/* ==========================================================================
   PORTAL DASHBOARD — MRGTEK
   Painel de Notas Fiscais (PHP + Chart.js + JS vanilla)
   Tema: claro / corporativo
   --------------------------------------------------------------------------
   Este arquivo é um substituto direto (drop-in) de style.css.
   Todos os seletores, classes e IDs existentes foram mantidos —
   apenas valores visuais (cor, espaçamento, tipografia, sombra,
   hierarquia e responsividade de desktop) foram refinados.
   Os breakpoints de <900px e <640px continuam sob responsabilidade
   de responsive.css (carregado depois deste arquivo).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1) DESIGN TOKENS
   Paleta oficial MRGTEK mantida exatamente como especificado.
   Tokens extras (rgb / espaçamento / raio / tipografia) são aditivos e
   servem apenas para consistência interna deste arquivo.
   -------------------------------------------------------------------------- */
:root {
    /* Paleta da marca MRGTEK (obrigatórios) */
    --brand-navy: #1C2A4E;
    --brand-navy-2: #16223F;
    --brand-blue: #3D6DAB;
    --brand-blue-lt: #5B8FC9;

    --primary: #3D6DAB;
    --primary-dark: #2F5688;
    --secondary: #5B8FC9; /* alias histórico de --brand-blue-lt, mantido por compatibilidade */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1C2A4E;
    --light: #F4F7FB;
    --border: #e3e9f2;
    --text: #334155;

    /* Variações RGB dos tokens acima — usadas apenas para transparências (box-shadow/backgrounds) */
    --primary-rgb: 61, 109, 171;
    --success-rgb: 16, 185, 129;
    --danger-rgb: 239, 68, 68;
    --warning-rgb: 245, 158, 11;
    --dark-rgb: 28, 42, 78;

    /* Tipografia */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;

    /* Elevação (sombras) — hierarquia sutil, sem exageros */
    --shadow-xs: 0 1px 2px rgba(28, 42, 78, 0.06);
    --shadow: 0 1px 3px rgba(28, 42, 78, 0.10), 0 1px 2px rgba(28, 42, 78, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(28, 42, 78, 0.12), 0 2px 4px -2px rgba(28, 42, 78, 0.08);
    --shadow-lg: 0 10px 20px -6px rgba(28, 42, 78, 0.18);
    --shadow-focus: 0 0 0 3px rgba(var(--primary-rgb), 0.18);

    /* Raios de borda — escala consistente */
    --radius-sm: 0.4rem;
    --radius: 0.5rem;
    --radius-md: 0.65rem;
    --radius-lg: 0.85rem;
    --radius-pill: 999px;

    /* Transições */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.15s var(--ease);
    --transition: 0.25s var(--ease);
}

/* --------------------------------------------------------------------------
   2) RESET / BASE
   -------------------------------------------------------------------------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--light);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4 { font-family: inherit; line-height: 1.25; }

button, input, select {
    font-family: inherit;
    color: inherit;
}

img { max-width: 100%; display: block; }

/* Seleção de texto alinhada à marca */
::selection { background: var(--primary); color: #fff; }

/* --------------------------------------------------------------------------
   3) ACESSIBILIDADE — foco visível
   Aplica um anel de foco consistente em todos os elementos interativos
   apenas quando a navegação é por teclado (:focus-visible).
   -------------------------------------------------------------------------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}

.nav-item:focus-visible {
    outline: 2px solid var(--brand-blue-lt);
    outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   4) SCROLLBARS — discretas, coerentes com o tema claro
   -------------------------------------------------------------------------- */
.content,
.table-wrapper,
.sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: rgba(28, 42, 78, 0.25) transparent;
}
.sidebar-nav {
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.content::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
    width: 8px; height: 8px;
}
.content::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(28, 42, 78, 0.20); border-radius: var(--radius-pill);
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.20); border-radius: var(--radius-pill);
}
.content::-webkit-scrollbar-track,
.table-wrapper::-webkit-scrollbar-track,
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------------
   5) LAYOUT GERAL
   -------------------------------------------------------------------------- */
.container-fluid { display: flex; height: 100vh; overflow: hidden; }

/* --------------------------------------------------------------------------
   6) SIDEBAR
   Fundo navy em gradiente sutil (mantido). Logo sobre cartão branco.
   -------------------------------------------------------------------------- */
.sidebar {
    width: 220px;
    background: linear-gradient(180deg, var(--brand-navy), var(--brand-navy-2));
    color: white;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.35rem 1rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    text-align: center;
}

.brand-logo-wrap {
    background: #FFFFFF;
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin: 0 auto 0.75rem;
    max-width: 150px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.20);
}

.brand-logo { width: 100%; height: auto; display: block; }

.sidebar-header h1 {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--brand-blue-lt);
}

.sidebar-nav { flex: 1; padding: 1.25rem 0.6rem; overflow-y: auto; }

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.72rem 0.85rem;
    margin-bottom: 0.15rem;
    color: rgba(255, 255, 255, 0.68);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

/* Ícones inline nos itens de navegação */
.nav-item svg {
    width: 18px;
    height: 18px;
    margin-right: 0.6rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.07);
    color: white;
    border-left-color: rgba(255, 255, 255, 0.35);
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border-left-color: var(--brand-blue-lt);
    font-weight: 600;
}

.sidebar-footer {
    padding: 1.1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
    text-align: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 0.03em;
}

/* --------------------------------------------------------------------------
   7) MAIN / HEADER
   -------------------------------------------------------------------------- */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 1.35rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    z-index: 2;
}

.header-title h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: var(--dark);
    letter-spacing: -0.01em;
}

.header-title p {
    color: #64748b;
    font-size: 0.84rem;
}

.header-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   8) CONTROLES DE FORMULÁRIO (filtros, importação)
   -------------------------------------------------------------------------- */
.input-date,
.input-select {
    padding: 0.58rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: white;
    color: var(--text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    cursor: pointer;
}

.input-date:hover,
.input-select:hover {
    border-color: var(--brand-blue-lt);
}

.input-date:focus,
.input-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}

/* --------------------------------------------------------------------------
   9) BOTÕES
   -------------------------------------------------------------------------- */
.btn-primary {
    padding: 0.6rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    box-shadow: var(--shadow);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}
.btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-ghost {
    padding: 0.55rem 1.05rem;
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--light);
    border-color: var(--primary);
    color: var(--primary);
}
.btn-ghost:active:not(:disabled) { transform: translateY(1px); }
.btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }

/* --------------------------------------------------------------------------
   10) VIEWS (troca de seção via JS) + animação de entrada
   -------------------------------------------------------------------------- */
.content { flex: 1; overflow-y: auto; padding: 2rem; }

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.35s var(--ease); }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   11) KPIs
   Cartões com ícone em badge quadrado (SVG inline) + valor numérico
   que precisa caber sem estourar o card, mesmo em valores longos
   (ex.: "R$ 83.639.725,66").
   -------------------------------------------------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform var(--transition), box-shadow var(--transition);
    min-width: 0; /* garante que o conteúdo possa encolher/quebrar corretamente */
}
.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

/* Badge quadrado do ícone (~52px, cantos arredondados) */
.kpi-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    font-weight: 800;
    font-size: 0.9rem;
    color: white;
    flex-shrink: 0;
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

/* Ícone SVG inline dentro do badge */
.kpi-icon svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    color: #fff;
}

/* Cores por tipo de KPI (mantidas) */
.i-nf    { background: var(--brand-navy); }
.i-money { background: var(--brand-blue); }
.i-avg   { background: var(--brand-blue-lt); }
.i-ok    { background: #059669; }
.i-div   { background: #d97706; }
.i-pay   { background: var(--danger); }

.kpi-content { flex: 1; min-width: 0; }

.kpi-label {
    color: #64748b;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.2rem;
}

.kpi-value {
    /* Escala fluida: reduz automaticamente para valores longos sem estourar o card */
    font-size: clamp(1.05rem, 0.85rem + 0.6vw, 1.35rem);
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

/* --------------------------------------------------------------------------
   12) GRÁFICOS
   -------------------------------------------------------------------------- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.25rem;
}

.chart-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    min-width: 0;
}

.chart-container h3 {
    margin-bottom: 1rem;
    color: var(--dark);
    font-size: 0.98rem;
    font-weight: 600;
}

.chart-container canvas { max-height: 300px; }

/* --------------------------------------------------------------------------
   13) TABELA
   -------------------------------------------------------------------------- */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.table-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.1rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.table-head h3 { color: var(--dark); font-size: 1.05rem; font-weight: 700; }

.table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
    background: var(--light);
    padding: 0.8rem 0.9rem;
    text-align: left;
    font-weight: 700;
    color: var(--dark);
    border-bottom: 2px solid var(--border);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
thead th:first-child { border-top-left-radius: var(--radius-sm); }
thead th:last-child  { border-top-right-radius: var(--radius-sm); }

tbody td {
    padding: 0.68rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.83rem;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--light); }
tbody tr:last-child td { border-bottom: none; }

/* Badges de status (tags) — cores derivadas dos tokens semânticos */
.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.5;
    white-space: nowrap;
}
.tag-ok     { background: rgba(var(--success-rgb), 0.14); color: #065f46; }
.tag-warn   { background: rgba(var(--warning-rgb), 0.16); color: #92400e; }
.tag-danger { background: rgba(var(--danger-rgb), 0.14);  color: #991b1b; }

/* --------------------------------------------------------------------------
   14) PAGINAÇÃO
   Botões são gerados via JS com a classe .btn-ghost — apenas o
   contêiner e o comportamento em grupo são ajustados aqui.
   -------------------------------------------------------------------------- */
.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}
.pagination .btn-ghost { padding: 0.5rem 1rem; font-size: 0.82rem; }

/* --------------------------------------------------------------------------
   15) CONFIGURAÇÃO (Importar / Exportar)
   -------------------------------------------------------------------------- */
.config-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    max-width: 720px;
}
.config-container h3 {
    margin-bottom: 0.6rem;
    color: var(--dark);
    font-size: 1.1rem;
    font-weight: 700;
}
.config-container .btn-primary { margin-top: 1.25rem; }

/* --------------------------------------------------------------------------
   16) UTILITÁRIOS
   -------------------------------------------------------------------------- */
.separator { color: #64748b; font-size: 0.85rem; }
.text-muted { color: #64748b; font-size: 0.85rem; line-height: 1.6; }

/* --------------------------------------------------------------------------
   17) IMPORTAÇÃO DE PLANILHA
   -------------------------------------------------------------------------- */
.import-box {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 1.25rem;
}

.input-file {
    padding: 0.6rem 0.85rem;
    border: 1.5px dashed var(--brand-blue-lt);
    border-radius: var(--radius);
    background: #f7faff;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    flex: 1;
    min-width: 240px;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
.input-file:hover { border-color: var(--brand-blue); background: #eef4fc; }

.import-status {
    margin-top: 1.1rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    display: none;
}
.import-status.info { display: block; background: #eef4fc; color: var(--brand-navy); border: 1px solid #cfe0f5; }
.import-status.ok   { display: block; background: rgba(var(--success-rgb), 0.12); color: #065f46; border: 1px solid rgba(var(--success-rgb), 0.35); }
.import-status.err  { display: block; background: rgba(var(--danger-rgb), 0.10);  color: #991b1b; border: 1px solid rgba(var(--danger-rgb), 0.30); }

.import-help {
    margin-top: 1.4rem;
    font-size: 0.82rem;
    color: #64748b;
}
.import-help summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--brand-blue);
    transition: color var(--transition-fast);
}
.import-help summary:hover { color: var(--primary-dark); }
.import-help code {
    display: block;
    margin-top: 0.6rem;
    padding: 0.85rem;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    line-height: 1.6;
    word-break: break-word;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.78rem;
    color: var(--text);
}

/* --------------------------------------------------------------------------
   18) RODAPE DO MENU — usuario logado + sair  (integracao login)
   -------------------------------------------------------------------------- */
.sidebar-footer { text-align: left; padding: 1rem 0.9rem 1.1rem; }
.side-user { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.side-user-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(150deg, var(--brand-navy), var(--brand-blue));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.18);
}
.side-user-name {
    font-size: 0.8rem; font-weight: 600; color: rgba(255,255,255,0.88);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-logout {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.55rem 0.6rem; border-radius: var(--radius);
    color: rgba(255,255,255,0.62); text-decoration: none;
    font-size: 0.85rem; font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.side-logout:hover { background: rgba(239,68,68,0.16); color: #fecaca; }
.side-logout svg { width: 17px; height: 17px; }
.nav-ico { display: inline-flex; align-items: center; }
