/* ==========================================================
   RS NEGÓCIOS — Design System
   Paleta: Indigo + Cyan neon, glassmorphism, glow
   Fontes: Sora (display) + Inter (corpo) + JetBrains Mono (dados)
   ========================================================== */

:root {
    /* Cores principais */
    --primary:        #6366f1;
    --primary-dark:   #4f46e5;
    --primary-light:  #818cf8;
    --primary-glow:   rgba(99, 102, 241, 0.45);

    --accent:         #06b6d4;
    --accent-dark:    #0891b2;
    --accent-glow:    rgba(6, 182, 212, 0.45);

    /* Gradientes */
    --grad-primary:   linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
    --grad-soft:      linear-gradient(135deg, rgba(99,102,241,0.10) 0%, rgba(6,182,212,0.10) 100%);
    --grad-radial:    radial-gradient(circle at top right, rgba(99,102,241,0.18), transparent 60%);

    /* Superfícies — DARK por padrão (negócio é DARK first) */
    --bg:             #0a0a14;
    --bg-card:        #14141f;
    --bg-elevated:    #1c1c2e;
    --bg-input:       #0f0f1a;
    --bg-overlay:     rgba(20, 20, 31, 0.7);
    --text:           #e2e8f0;
    --text-strong:    #f8fafc;
    --text-muted:     #94a3b8;
    --text-soft:      #64748b;
    --border:         rgba(99, 102, 241, 0.18);
    --border-strong:  rgba(99, 102, 241, 0.35);

    --shadow-sm:      0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-md:      0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-lg:      0 25px 60px rgba(0, 0, 0, 0.6);
    --shadow-glow:    0 0 50px var(--primary-glow);

    /* Semânticas */
    --success:        #10b981;
    --success-soft:   rgba(16, 185, 129, 0.12);
    --danger:         #ef4444;
    --danger-soft:    rgba(239, 68, 68, 0.12);
    --warning:        #f59e0b;
    --warning-soft:   rgba(245, 158, 11, 0.12);
    --info:           #3b82f6;
    --info-soft:      rgba(59, 130, 246, 0.12);

    /* Raios */
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-pill: 999px;

    /* Tipografia */
    --font-display: 'Sora', system-ui, sans-serif;
    --font-body:    'Inter', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', 'Menlo', monospace;
}

/* Modo CLARO (alternativo) */
[data-theme="light"] {
    --bg:             #f6f7fb;
    --bg-card:        #ffffff;
    --bg-elevated:    #f3f4f6;
    --bg-input:       #f9fafb;
    --bg-overlay:     rgba(255, 255, 255, 0.7);
    --text:           #0f172a;
    --text-strong:    #020617;
    --text-muted:     #475569;
    --text-soft:      #94a3b8;
    --border:         rgba(15, 23, 42, 0.08);
    --border-strong:  rgba(15, 23, 42, 0.15);
    --shadow-sm:      0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-md:      0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg:      0 20px 50px rgba(15, 23, 42, 0.12);
    --shadow-glow:    0 4px 18px rgba(99, 102, 241, 0.25);
    --grad-radial:    radial-gradient(circle at top right, rgba(99,102,241,0.08), transparent 60%);
    --grad-soft:      linear-gradient(135deg, rgba(99,102,241,0.06) 0%, rgba(6,182,212,0.06) 100%);
}

/* Backdrop do modal — adapta cor por tema */
[data-theme="light"] .modal-backdrop { background: rgba(15, 23, 42, 0.35); }

/* ----------------- Reset ----------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--grad-radial);
    pointer-events: none;
    z-index: 0;
}

h1, h2, h3, h4, h5 { font-family: var(--font-display); font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 0.95rem; }

a { color: var(--primary-light); text-decoration: none; }
a:hover { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: transparent; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ----------------- Layout shell ----------------- */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    padding: 0 4px;
}

.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    background: var(--grad-primary);
    display: grid;
    place-items: center;
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    box-shadow: var(--shadow-glow);
}

.brand-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-strong);
    line-height: 1.1;
}
.brand-text small { display: block; font-weight: 400; font-size: 0.7rem; color: var(--text-muted); letter-spacing: 0.05em; text-transform: uppercase; }

.nav-section { margin-top: 18px; }
.nav-label {
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--text-soft);
    padding: 0 8px 6px;
    font-weight: 600;
}
.nav-sublabel {
    text-transform: none;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    padding: 0 12px 4px 16px;
    font-weight: 500;
    border-left: 2px solid var(--border);
    margin-left: 8px;
}
.nav-sublabel + .nav-link,
.nav-sublabel ~ .nav-link {
    /* nav-links que seguem um sublabel ganham um leve indent */
}
/* Pra ter o indent só nos links que pertencem ao sub-grupo (até o próximo nav-label "raiz"),
   usamos uma classe de marcação no PHP. Variante simples: indent visual via gap */

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
}
.nav-link:hover { background: var(--bg-elevated); color: var(--text); }
.nav-link.active {
    background: var(--grad-soft);
    color: var(--primary-light);
    box-shadow: inset 0 0 0 1px var(--border-strong);
}
.nav-link .icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ----------------- Main ----------------- */
.main {
    padding: 22px 28px 60px;
    min-width: 0;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    gap: 16px;
}
.header-title h1 { font-size: 1.6rem; }
.header-title .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* ----------------- Cards ----------------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: 1rem; }

/* KPI cards */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
}
.kpi::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: var(--grad-primary);
    opacity: 0.7;
}
.kpi .label {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); font-weight: 600; margin-bottom: 4px;
}
.kpi .value {
    font-family: var(--font-display); font-weight: 700;
    font-size: 1.6rem; color: var(--text-strong); letter-spacing: -0.02em;
}
.kpi .value.mono { font-family: var(--font-body); font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 0.78rem; margin-top: 4px; font-weight: 500; }
.kpi .delta.positivo { color: var(--success); }
.kpi .delta.negativo { color: var(--danger); }
.kpi .delta.neutro   { color: var(--text-muted); }

/* ----------------- Botões ----------------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px;
    border-radius: var(--r-sm);
    font-weight: 600;
    font-size: 0.88rem;
    transition: all 0.15s;
    border: 1px solid transparent;
    background: var(--bg-elevated);
    color: var(--text);
}
.btn:hover { background: var(--bg-elevated); transform: translateY(-1px); }
.btn-primary {
    background: var(--grad-primary);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}
.btn-primary:hover { box-shadow: 0 6px 24px rgba(99,102,241,0.5); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-elevated); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ----------------- Inputs ----------------- */
.field { margin-bottom: 14px; }
.field label {
    display: block; font-size: 0.78rem; font-weight: 600;
    color: var(--text-muted); margin-bottom: 6px;
    text-transform: uppercase; letter-spacing: 0.06em;
}
.input, .select, .textarea {
    width: 100%; padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text); font-size: 0.95rem;
    transition: all 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.18);
}
.textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ----------------- Tabelas ----------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--border); }
table.tbl {
    width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
table.tbl thead th {
    background: var(--bg-elevated);
    text-align: left;
    padding: 11px 12px;
    font-weight: 600; font-size: 0.78rem;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.tbl td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}
table.tbl tbody tr:hover { background: var(--bg-elevated); }
table.tbl td.num, table.tbl th.num { text-align: right; font-family: var(--font-body); font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
table.tbl td.pos { color: var(--success); }
table.tbl td.neg { color: var(--danger); }
table.tbl tr.tr-grupo td {
    background: var(--bg-elevated);
    font-weight: 700; color: var(--text-strong);
    font-family: var(--font-display);
    text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.05em;
}
table.tbl tr.tr-sub td { padding-left: 24px; color: var(--text-muted); }
table.tbl tr.tr-total td {
    border-top: 2px solid var(--primary);
    font-weight: 700; color: var(--text-strong);
    background: var(--grad-soft);
}

/* Tabela DRE/Caixa com muitas colunas */
.tbl-dense th, .tbl-dense td { padding: 7px 8px; font-size: 0.82rem; }
.tbl-dense th:first-child, .tbl-dense td:first-child { text-align: left; position: sticky; left: 0; background: var(--bg-card); z-index: 2; min-width: 220px; }
.tbl-dense thead th:first-child { background: var(--bg-elevated); }
.tbl-dense tr.tr-grupo td:first-child { background: var(--bg-elevated); }

/* ----------------- Badges ----------------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--r-pill);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-validado  { background: var(--success-soft); color: var(--success); }
.badge-testando  { background: var(--warning-soft); color: var(--warning); }
.badge-pausado   { background: var(--info-soft);    color: var(--info); }
.badge-encerrado { background: var(--danger-soft);  color: var(--danger); }
.badge-neutro    { background: var(--bg-elevated);  color: var(--text-muted); }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 8px; border-radius: var(--r-pill);
    background: var(--bg-elevated); border: 1px solid var(--border);
    font-size: 0.74rem; color: var(--text-muted);
}

/* ----------------- Resultado pos/neg ----------------- */
.positivo, .pos { color: var(--success); }
.negativo, .neg { color: var(--danger); }
.neutro { color: var(--text-muted); }

/* ----------------- Modal ----------------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(10,10,20,0.7);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close {
    width: 32px; height: 32px; border-radius: var(--r-sm);
    display: grid; place-items: center;
    color: var(--text-muted); background: var(--bg-elevated);
}
.modal-close:hover { color: var(--text); }

/* ----------------- Tabs ----------------- */
.tabs {
    display: flex; gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}
.tab {
    padding: 10px 16px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-light); border-color: var(--primary); }

/* ----------------- Flash messages ----------------- */
.flash {
    padding: 12px 16px;
    border-radius: var(--r-sm);
    margin-bottom: 14px;
    font-size: 0.9rem;
    border: 1px solid;
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: rgba(16,185,129,0.3); }
.flash-error   { background: var(--danger-soft); color: var(--danger); border-color: rgba(239,68,68,0.3); }
.flash-info    { background: var(--info-soft); color: var(--info); border-color: rgba(59,130,246,0.3); }
.flash-warn    { background: var(--warning-soft); color: var(--warning); border-color: rgba(245,158,11,0.3); }

/* ----------------- Forms helpers ----------------- */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ----------------- Login ----------------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    position: relative; z-index: 1;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    padding: 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}
.login-card .brand { justify-content: center; margin-bottom: 24px; }

/* ----------------- Mobile / responsive ----------------- */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 260px; max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.25s;
        z-index: 50;
    }
    .sidebar.open { transform: translateX(0); }
    .main { padding: 16px; }
    .menu-toggle { display: inline-flex !important; }
    .header-title h1 { font-size: 1.25rem; }
    .field-row, .field-row-3 { grid-template-columns: 1fr; }
}

.menu-toggle {
    display: none;
    width: 38px; height: 38px;
    border-radius: var(--r-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    align-items: center; justify-content: center;
    color: var(--text);
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
}
.sidebar-backdrop.open { display: block; }

/* ----------------- Charts ----------------- */
.chart-wrap { position: relative; height: 280px; width: 100%; }

/* ----------------- Filter bar ----------------- */
.filter-bar {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    margin-bottom: 16px;
}
.filter-bar .field { margin: 0; }
.filter-bar label { margin-bottom: 2px; }

/* ----------------- Utilidades ----------------- */
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: 8px; }
.gap-md { gap: 14px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.w-100 { width: 100%; }
.hidden { display: none !important; }
.mono { font-family: var(--font-body); font-variant-numeric: tabular-nums; }