/* ========================================
   estilos-backend.css - SISTEMA MODULAR
   ========================================*/

/* ========================================
   0. BASE RESPONSIVA E TÁTIL
   ======================================== */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 0;
}

.mobile-bottom-nav {
    display: none;
    position: fixed;
    z-index: 1000;
    right: 0;
    bottom: 0;
    left: 0;
}

.mobile-card-toggle {
    display: none;
}

img, svg, canvas, video {
    max-width: 100%;
}

button, input, select, textarea {
    font: inherit;
}


/* ========================================*/
/* 1. ESTILO BASE DA PÁGINA */
.body-padrao {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    color: #111827;
    background: #f3f4f6;
    margin: 0;
    padding: 20px;
    line-height: 1.5;
    min-height: 100vh;
}
/* ========================================*/
/* 2 Card padrao */

.card-padrao {
    background: #ffffff;
    border-radius: 20px;
    border: 1px solid #e5e7eb;
    padding: 24px;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto 20px auto;
}

/* RESPONSIVO */
@media (max-width: 768px) {
    .body-padrao {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(86px, calc(72px + env(safe-area-inset-bottom)));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .mobile-bottom-nav {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 2px;
        padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        border-top: 1px solid #d1d5db;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
    }

    .mobile-bottom-nav__item {
        min-width: 0;
        min-height: 52px;
        padding: 5px 3px;
        border-radius: 10px;
        color: #64748b;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        font-size: 11px;
        font-weight: 650;
        line-height: 1.15;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-bottom-nav__item.is-active {
        color: #1d4ed8;
        background: #eff6ff;
    }

    .mobile-bottom-nav__icon {
        min-height: 20px;
        display: grid;
        place-items: center;
        font-size: 18px;
        line-height: 1;
    }

    .mobile-nav-body-offset {
        padding-bottom: max(86px, calc(72px + env(safe-area-inset-bottom)));
    }

    .page-resumo #link-lucro,
    .page-resumo #link-transacoes,
    .page-resumo #link-dinheiro,
    .page-resumo #link-caixa,
    .page-resumo #link-ferramentas {
        display: none !important;
    }

    .card-padrao {
        padding: 18px;
        border-radius: 16px;
    }
}
/* ========================================*/
/* 3. TÍTULOS PADRÃO */

.titulo-padrao h1 { 
    font-size: 24px; 
    letter-spacing: -0.03em; 
    margin: 0 0 4px 0; 
    font-weight: 700; 
    color: #111827;
}

.titulo-padrao  h2 {
      font-size: 16px;
      letter-spacing: -0.02em;
      margin-top: 12px;
      margin-bottom: 4px;
    }

.titulo-padrao p.small { 
    font-size: 13px; 
    color: #6b7280; 
    margin: 0 0 16px 0; 
}


/* ========================================
   4. header-padrao - HEADER FLEX (ESQUERDA/DIREITA)
   ======================================== */
.header-padrao {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

/* ========================================
   tabs-padrao - ABAS (dentro do header Dirieta)
   ======================================== */
.tabs-padrao {
    display: flex;
    gap: 8px;
    margin: 0;
}

.tabs-padrao .tab-button {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.tabs-padrao .tab-button.tab-active {
    background: #2563eb;
    color: #f9fafb;
    border-color: #1d4ed8;
}

.tabs-padrao .tab-button:hover:not(.tab-active) {
    background: #eff6ff;
    transform: translateY(-1px);
}



/* ========================================
   toolbar-direita - BOTÕES AZUL/BRANCO
   ========================================
   REGRA AUTOMÁTICA:
   <a> = AZUL | <button> = BRANCO
   ======================================== */

.toolbar-direita {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* BASE PARA TODOS */
.toolbar-direita a,
.toolbar-direita button {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* LINKS AZUIS (<a>) */
.toolbar-direita a {
    border-color: #2563eb;
    background: #2563eb;
    color: #f9fafb;
}

.toolbar-direita a:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 216, 0.3);
}

/* BOTÕES BRANCOS (<button>) */
.toolbar-direita button {
    border-color: #6b7280;
    background: #ffffff;
    color: #374151;
}

.toolbar-direita button:hover {
    background: #f9fafb;
    transform: translateY(-1px);
}

/* RESPONSIVO */
@media (max-width: 480px) {
    .toolbar-direita { justify-content: flex-end; }
}
/* ========================================*/
/* 5. CARDS DE ESTATÍSTICAS (RESUMO) */
/* Wrapper dos cards: permite 2, 3, 4 ou mais colunas lado a lado */

.stats-padrao {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.stats-padrao .stat {
  flex: 1 1 220px;  /* mínimo 220px, depois expande até ocupar a linha */
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px;
  background: #f9fafb;
}


/* Label pequena */
.stats-padrao .stat-label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 4px;
}

/* Valor em destaque */
.stats-padrao .stat-value {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

/* Ajuste específico para o saldo em caixa */
.stats-padrao #saldo-caixa-principal {
    font-size: 16px;
    line-height: 1.4;
}

/* ========================================*/
/* 6. TABELA PADRÃO (RESUMOS, LISTAGENS) */
.tabela-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    margin-top: 12px;
}

.tabela-padrao {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 0;
    background: #ffffff;
}

.tabela-padrao th,
.tabela-padrao td {
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    text-align: left;
}

.tabela-padrao thead {
    background: #f3f4f6;
}

.tabela-padrao th.sortable {
    cursor: pointer;
}

.tabela-padrao tfoot td {
    font-weight: 600;
    background: #f9fafb;
}

/* TABELA DE TRANSAÇÕES (LAYOUT COMPACTO) */
.tabela-transacoes-wrapper .tabela-padrao th,
.tabela-transacoes-wrapper .tabela-padrao td {
    font-size: 11px;
    padding: 4px 6px;
    white-space: nowrap;
}

/* larguras mínimas por coluna (ajustar se quiseres) */
.tabela-transacoes-wrapper th.col-ordem        { width: 50px;  }
.tabela-transacoes-wrapper th.col-data-compra  { width: 90px;  }
.tabela-transacoes-wrapper th.col-data-venda   { width: 90px;  }
.tabela-transacoes-wrapper th.col-nome         { width: 140px; }
.tabela-transacoes-wrapper th.col-num-acoes    { width: 60px;  }
.tabela-transacoes-wrapper th.col-valor        { width: 80px;  }
.tabela-transacoes-wrapper th.col-custo        { width: 90px;  }
.tabela-transacoes-wrapper th.col-ganho        { width: 80px;  }
.tabela-transacoes-wrapper th.col-ganho-pct    { width: 60px;  }
.tabela-transacoes-wrapper th.col-taxa         { width: 60px;  }
.tabela-transacoes-wrapper th.col-moeda        { width: 80px;  }
.tabela-transacoes-wrapper th.col-acoes        { width: 50px;  }

/* inputs de filtro ocupam a largura da célula */
.tabela-transacoes-wrapper .filtro-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 11px;
    padding: 2px 4px;
}

/*  Remover setas dos inputs numéricos */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
input[type=number] {
    -moz-appearance: textfield;
}


.select-utilizador {
    padding: 4px 8px;
    margin-right: 8px;
    font-size: 14px;
}

/* Valores positivos/negativos (ex.: % Dia, saldos, etc.) */
.positivo {
    color: #059669;
    font-weight: 600;
}

.negativo {
    color: #dc2626;
    font-weight: 600;
}

/* ========================================
   7. AJUSTES PARA TABLET E TELEMÓVEL
   ======================================== */
@media (max-width: 768px) {
    .header-padrao {
        align-items: stretch;
    }

    .toolbar-direita,
    .tabs-padrao {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .toolbar-direita a,
    .toolbar-direita button,
    .tabs-padrao .tab-button,
    .select-utilizador,
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea,
    button {
        min-height: 44px;
    }

    .toolbar-direita a,
    .toolbar-direita button,
    .tabs-padrao .tab-button {
        justify-content: center;
        padding: 10px 14px;
    }

    .stats-padrao {
        gap: 12px;
    }

    .stats-padrao .stat {
        flex-basis: min(100%, 220px);
    }

    .tabela-padrao th,
    .tabela-padrao td {
        padding: 8px;
    }
}

@media (max-width: 480px) {
    .body-padrao {
        font-size: 14px;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(86px, calc(72px + env(safe-area-inset-bottom)));
        padding-left: max(8px, env(safe-area-inset-left));
    }

    .card-padrao {
        padding: 14px;
        border-radius: 14px;
    }

    .titulo-padrao h1 {
        font-size: 21px;
        line-height: 1.2;
    }

    .titulo-padrao p.small {
        font-size: 13px;
    }

    .header-padrao {
        gap: 10px;
    }

    .select-utilizador {
        width: 100%;
        margin-right: 0;
        padding: 9px 10px;
    }

    .toolbar-direita > a,
    .toolbar-direita > button {
        flex: 1 1 auto;
        font-size: 14px;
    }

    .tabs-padrao .tab-button {
        flex: 0 0 auto;
        font-size: 13px;
    }

    .stats-padrao .stat {
        flex: 1 1 100%;
    }

    .graficos-duplos .card-grafico {
        min-width: 0 !important;
    }

    .grafico-canvas-wrap {
        height: clamp(210px, 65vw, 260px) !important;
    }

    dialog {
        max-width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
    }
}

/* ========================================
   8. TABELAS FINANCEIRAS EM CARTÕES MÓVEIS
   ======================================== */
@media (max-width: 640px) {
    .mobile-card-collapsible:not(.is-expanded) .mobile-card-secondary {
        display: none;
    }

    .mobile-card-toggle {
        display: inline-flex;
        grid-column: 1 / -1;
        justify-self: start;
        align-items: center;
        justify-content: center;
        min-height: 38px;
        margin-top: 4px;
        padding: 7px 11px;
        border: 1px solid #bfdbfe;
        border-radius: 999px;
        background: #eff6ff;
        color: #1d4ed8;
        font-size: 12px;
        font-weight: 650;
        cursor: pointer;
    }

    table[data-mobile-cards] {
        display: block;
        width: 100%;
        background: transparent;
    }

    table[data-mobile-cards][hidden] {
        display: none !important;
    }

    table[data-mobile-cards] thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    table[data-mobile-cards] tbody,
    table[data-mobile-cards] tfoot {
        display: grid;
        gap: 12px;
        width: 100%;
    }

    table[data-mobile-cards] tbody tr {
        display: grid;
    }

    table[data-mobile-cards] tbody tr,
    table[data-mobile-cards] tfoot tr {
        display: grid;
        grid-template-columns: 1fr;
        overflow: hidden;
        border: 1px solid #dbe3ee;
        border-radius: 14px;
        background: #ffffff;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
    }

    table[data-mobile-cards] tfoot {
        margin-top: 12px;
    }

    table[data-mobile-cards] tfoot tr {
        border-color: #bfdbfe;
        background: #eff6ff;
    }

    table[data-mobile-cards] tbody td,
    table[data-mobile-cards] tfoot td {
        display: grid;
        grid-template-columns: minmax(105px, 0.85fr) minmax(0, 1.15fr);
        gap: 12px;
        align-items: center;
        min-height: 42px;
        padding: 9px 12px;
        border: 0;
        border-bottom: 1px solid #eef2f7;
        text-align: right;
        overflow-wrap: anywhere;
    }

    table[data-mobile-cards] tbody td:last-child,
    table[data-mobile-cards] tfoot td:last-child {
        border-bottom: 0;
    }

    table[data-mobile-cards] td::before {
        content: attr(data-label);
        color: #64748b;
        font-size: 11px;
        font-weight: 650;
        line-height: 1.25;
        text-align: left;
    }

    table[data-mobile-cards] td:first-child {
        background: #f8fafc;
        color: #0f172a;
        font-weight: 700;
    }

    table[data-mobile-cards] td[colspan] {
        display: block;
        text-align: center;
    }

    table[data-mobile-cards] td[colspan]::before {
        content: none;
    }

    table[data-mobile-cards] td button,
    table[data-mobile-cards] td a {
        min-height: 40px;
    }

    .tabela-editavel-scroll::before {
        content: "Desliza horizontalmente para editar todas as colunas.";
        display: block;
        position: sticky;
        left: 0;
        margin-bottom: 8px;
        color: #64748b;
        font-size: 11px;
    }
}

