/* ============================================================
   Financeiro Pessoal — Design System
   Token-based theming (light + dark). Colors are RGB channels
   so Tailwind's rgb(var(--x) / <alpha-value>) opacity works.
   ============================================================ */

:root {
    /* Neutrals — LIGHT */
    --canvas: 248 250 252;
    --surface: 255 255 255;
    --elevated: 241 245 249;
    --border: 226 232 240;
    --text-strong: 15 23 42;
    --text-body: 51 65 85;
    --text-muted: 100 116 139;

    /* Sidebar — LIGHT */
    --sidebar-bg: 255 255 255;
    --sidebar-hover: 241 245 249;
    --sidebar-active: 219 234 254;
    --sidebar-text: 100 116 139;
    --sidebar-text-active: 15 23 42;

    /* Accent (same in both themes) */
    --accent: 59 130 246;    /* blue-500 */
    --accent-2: 6 182 212;   /* cyan-500 */
    --positive: 5 150 105;
    --negative: 220 38 38;
    --warning: 217 119 6;

    /* Effects */
    --shadow-card: 0 2px 4px -1px rgba(15, 23, 42, .06), 0 10px 24px -8px rgba(15, 23, 42, .14);
    --shadow-pop: 0 24px 50px -16px rgba(15, 23, 42, .30), 0 6px 14px -8px rgba(15, 23, 42, .18);
    --ring: 0 0 0 3px rgba(59, 130, 246, .35);
    --glass-blur: 12px;
    --sheen: rgba(255, 255, 255, .7);
    color-scheme: light;
}

.dark {
    /* Neutrals — DARK */
    --canvas: 8 11 20;
    --surface: 17 24 39;
    --elevated: 30 41 59;
    --border: 42 54 76;
    --text-strong: 241 245 249;
    --text-body: 203 213 225;
    --text-muted: 148 163 184;

    /* Sidebar — DARK */
    --sidebar-bg: 10 14 24;
    --sidebar-hover: 30 41 59;
    --sidebar-active: 30 58 138;
    --sidebar-text: 148 163 184;
    --sidebar-text-active: 255 255 255;

    --shadow-card: 0 2px 6px -1px rgba(0, 0, 0, .5), 0 14px 32px -10px rgba(0, 0, 0, .62);
    --shadow-pop: 0 28px 60px -14px rgba(0, 0, 0, .78), 0 8px 18px -8px rgba(0, 0, 0, .6);
    --ring: 0 0 0 3px rgba(59, 130, 246, .5);
    --sheen: rgba(255, 255, 255, .06);
    color-scheme: dark;
}

* { border-color: rgb(var(--border)); }

html, body {
    background-color: rgb(var(--canvas));
    color: rgb(var(--text-body));
    transition: background-color .25s ease, color .25s ease;
}

/* ---------- Sidebar (distinct, with depth) ---------- */
#sidebar {
    background-image: linear-gradient(180deg, #ffffff 0%, #eef3fb 100%);
    box-shadow: 10px 0 34px -16px rgba(30, 64, 175, .22);
}
.dark #sidebar {
    background-image: linear-gradient(185deg, #0d1a30 0%, #0a1120 55%, #0b1b34 100%);
    box-shadow: 12px 0 44px -18px rgba(0, 0, 0, .75);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 150ms ease-in-out;
    position: relative;
}

/* active nav item — accent gradient + glow */
.sidebar-link.is-active {
    background-image: linear-gradient(135deg, rgb(var(--accent) / .22), rgb(var(--accent-2) / .18));
    color: rgb(var(--sidebar-text-active));
    box-shadow: inset 0 0 0 1px rgb(var(--accent) / .4), 0 10px 22px -12px rgb(var(--accent) / .7);
}
.sidebar-link.is-active::before {
    content: "";
    position: absolute;
    left: -3px; top: 20%; bottom: 20%;
    width: 3px; border-radius: 9999px;
    background: linear-gradient(180deg, rgb(var(--accent)), rgb(var(--accent-2)));
}

.sidebar-scroll { scrollbar-width: thin; scrollbar-color: rgb(var(--border)) transparent; }
.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background-color: rgb(var(--border)); border-radius: 9999px; }

/* ---------- Cards ---------- */
.card {
    background-color: rgb(var(--surface));
    border: 1px solid rgb(var(--border));
    border-radius: 1rem;
    box-shadow: var(--shadow-card), inset 0 1px 0 var(--sheen);
    padding: 1.5rem;
    transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-pop), inset 0 1px 0 var(--sheen); }

/* Frosted glass surface (for hero/summary cards) */
.glass {
    background-color: rgb(var(--surface) / .72);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid rgb(var(--border) / .8);
}

/* Accent glow accent for hero elements */
.glow-accent { box-shadow: 0 0 0 1px rgb(var(--accent) / .25), 0 12px 40px -12px rgb(var(--accent) / .45); }

.brand-badge { background-image: linear-gradient(135deg, rgb(var(--accent)), rgb(var(--accent-2))); }
.text-gradient {
    background-image: linear-gradient(90deg, rgb(var(--accent)), rgb(var(--accent-2)));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Buttons ---------- */
.btn-primary {
    background-image: linear-gradient(135deg, rgb(var(--accent)), rgb(var(--accent-2)));
    color: #ffffff;
    border-radius: 0.625rem;
    padding: 0.55rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 150ms ease-in-out;
    border: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    box-shadow: 0 6px 16px -8px rgb(var(--accent) / .8);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary:focus { outline: none; box-shadow: var(--ring); }

.btn-danger {
    background-color: rgb(var(--negative));
    color: #ffffff; border-radius: 0.625rem;
    padding: 0.55rem 1rem; font-weight: 600; font-size: 0.875rem;
    transition: all 150ms ease-in-out; border: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger:focus { outline: none; box-shadow: 0 0 0 3px rgba(220, 38, 38, .4); }

.btn-secondary {
    background-color: rgb(var(--elevated));
    color: rgb(var(--text-body));
    border-radius: 0.625rem; padding: 0.55rem 1rem;
    font-weight: 500; font-size: 0.875rem;
    transition: all 150ms ease-in-out;
    border: 1px solid rgb(var(--border)); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-secondary:hover { border-color: rgb(var(--accent) / .5); color: rgb(var(--text-strong)); }
.btn-secondary:focus { outline: none; box-shadow: var(--ring); }

/* ---------- Form elements ---------- */
.input-field {
    border: 1px solid rgb(var(--border));
    border-radius: 0.625rem;
    padding: 0.55rem 0.8rem; width: 100%;
    font-size: 0.875rem; line-height: 1.25rem;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    background-color: rgb(var(--surface));
    color: rgb(var(--text-strong));
}
.input-field::placeholder { color: rgb(var(--text-muted)); }
.input-field:focus { outline: none; border-color: rgb(var(--accent)); box-shadow: var(--ring); }

.label { display: block; font-size: 0.875rem; font-weight: 500; color: rgb(var(--text-body)); margin-bottom: 0.25rem; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background-color: rgba(2, 6, 23, .6);
    backdrop-filter: blur(4px); z-index: 50;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background-color: rgb(var(--surface));
    color: rgb(var(--text-body));
    border: 1px solid rgb(var(--border));
    border-radius: 1rem; box-shadow: var(--shadow-pop);
    max-width: 28rem; width: 100%; margin: 0 1rem; max-height: 90vh; overflow-y: auto;
    animation: modalSlideIn 200ms ease-out;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-10px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Alerts ---------- */
.alert-success {
    background-color: rgb(var(--accent) / .12);
    border: 1px solid rgb(var(--accent) / .4);
    color: rgb(var(--positive));
    padding: 0.75rem 1rem; border-radius: 0.625rem; font-size: 0.875rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.dark .alert-success { color: rgb(52 211 153); }
.alert-error {
    background-color: rgb(var(--negative) / .12);
    border: 1px solid rgb(var(--negative) / .4);
    color: rgb(var(--negative));
    padding: 0.75rem 1rem; border-radius: 0.625rem; font-size: 0.875rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.dark .alert-error { color: rgb(248 113 113); }

/* ---------- Table ---------- */
.table-container {
    width: 100%; overflow-x: auto; border-radius: 1rem;
    border: 1px solid rgb(var(--border)); background-color: rgb(var(--surface));
}
.table-container table { width: 100%; border-collapse: collapse; }
.table-header {
    background-color: rgb(var(--elevated));
    font-size: 0.75rem; font-weight: 600; color: rgb(var(--text-muted));
    text-transform: uppercase; letter-spacing: .05em;
}
.table-header th { padding: 0.75rem 1.25rem; text-align: left; border-bottom: 1px solid rgb(var(--border)); }
.table-row { transition: background-color 150ms ease; }
.table-row:hover { background-color: rgb(var(--elevated) / .6); }
.table-row td { padding: 0.75rem 1.25rem; border-bottom: 1px solid rgb(var(--border)); font-size: 0.875rem; color: rgb(var(--text-body)); }

/* ---------- Badges ---------- */
.badge-green, .badge-red, .badge-purple, .badge-blue {
    display: inline-flex; align-items: center;
    padding: 0.15rem 0.65rem; border-radius: 9999px;
    font-size: 0.75rem; font-weight: 600;
}
.badge-green  { background-color: rgb(var(--accent) / .16);  color: rgb(var(--positive)); }
.dark .badge-green { color: rgb(52 211 153); }
.badge-red    { background-color: rgb(var(--negative) / .14); color: rgb(var(--negative)); }
.dark .badge-red { color: rgb(248 113 113); }
.badge-purple { background-color: rgb(139 92 246 / .16); color: rgb(124 58 237); }
.dark .badge-purple { color: rgb(196 181 253); }
.badge-blue   { background-color: rgb(59 130 246 / .16); color: rgb(37 99 235); }
.dark .badge-blue { color: rgb(147 197 253); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 0.625rem;
    border: 1px solid rgb(var(--border)); background-color: rgb(var(--surface));
    color: rgb(var(--text-muted)); cursor: pointer; transition: all .15s ease;
}
.theme-toggle:hover { color: rgb(var(--accent)); border-color: rgb(var(--accent) / .5); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
.dark .theme-toggle .icon-sun { display: block; }
.dark .theme-toggle .icon-moon { display: none; }

/* ---------- Hero header (gradient banner) ---------- */
.hero {
    position: relative;
    overflow: hidden;
    border-radius: 1.25rem;
    padding: 1.5rem 1.75rem;
    background-image: linear-gradient(120deg, #0b2a5b 0%, #1d4ed8 48%, #06b6d4 100%);
    box-shadow: 0 18px 48px -20px rgba(29, 78, 216, .7);
}
.hero::before {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(circle at 85% 12%, rgba(255,255,255,.16), transparent 42%);
    pointer-events: none;
}
.hero > * { position: relative; }
.hero-title { color: #fff; font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.hero-sub { color: rgba(255,255,255,.78); font-size: .85rem; margin-top: .15rem; }

.filter-pill {
    display: inline-flex; align-items: center; gap: .4rem;
    background-color: rgba(255,255,255,.14);
    border: 1px solid rgba(255,255,255,.22);
    color: #eaf2ff; border-radius: .625rem;
    padding: .4rem .75rem; font-size: .78rem; font-weight: 500;
    backdrop-filter: blur(6px);
}
.hero-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    background: #fff; color: #1d4ed8; font-weight: 700; font-size: .82rem;
    border: none; border-radius: .625rem; padding: .5rem .9rem; cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.hero-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px -8px rgba(0,0,0,.4); }
.hero-btn-ghost {
    display: inline-flex; align-items: center; gap: .4rem;
    background: rgba(255,255,255,.15); color: #fff; font-weight: 600; font-size: .82rem;
    border: 1px solid rgba(255,255,255,.28); border-radius: .625rem; padding: .5rem .9rem; cursor: pointer;
}
.hero-btn-ghost:hover { background: rgba(255,255,255,.24); }

/* ---------- Premium stat cards (always dark blue, both themes) ---------- */
.stat-card {
    --sc: 96 165 250;                     /* accent hue per metric */
    position: relative; overflow: hidden; isolation: isolate;
    background-image: linear-gradient(150deg, #0a2657 0%, #143a86 58%, #1e50b0 100%);
    border: 1px solid rgba(148,197,255,.22);
    border-radius: 1rem; padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow-pop), inset 0 1px 0 rgba(255,255,255,.14);
    transition: transform .2s ease, box-shadow .2s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 32px 62px -18px rgba(6,16,44,.92), inset 0 1px 0 rgba(255,255,255,.18); }
.stat-card::before {                       /* colored halo, top-right */
    content: ""; position: absolute; z-index: -1; top: -38%; right: -14%;
    width: 160px; height: 160px; border-radius: 50%;
    background: radial-gradient(circle, rgb(var(--sc) / .5), transparent 68%);
    pointer-events: none;
}
.stat-card::after {                        /* top sheen for volume */
    content: ""; position: absolute; z-index: -1; left: 0; right: 0; top: 0; height: 46%;
    background: linear-gradient(180deg, rgba(255,255,255,.12), transparent);
    pointer-events: none;
}
.stat-chip {
    width: 40px; height: 40px; border-radius: .75rem;
    background: rgb(var(--sc) / .18); border: 1px solid rgb(var(--sc) / .38);
    display: inline-flex; align-items: center; justify-content: center; color: rgb(var(--sc));
    margin-bottom: .75rem; box-shadow: 0 8px 18px -8px rgb(var(--sc) / .7);
}
.stat-label { color: #a9c6f5; font-size: .68rem; letter-spacing: .06em; font-weight: 600; text-transform: uppercase; }
.stat-value { color: #fff; font-size: 1.55rem; font-weight: 700; line-height: 1.1; margin-top: .2rem; }
.stat-sub { color: #9fb6dd; font-size: .72rem; margin-top: .4rem; }
.stat-sub.pos, .stat-value.pos { color: #6ee7b7; }
.stat-sub.neg, .stat-value.neg { color: #fca5a5; }
.stat-card.sc-emerald { --sc: 52 211 153; }
.stat-card.sc-rose    { --sc: 251 113 133; }
.stat-card.sc-blue    { --sc: 96 165 250; }
.stat-card.sc-amber   { --sc: 251 191 36; }
.stat-card.sc-violet  { --sc: 167 139 250; }

/* Panel = chart/content card (raised, with depth) */
.panel {
    position: relative;
    background-color: rgb(var(--surface));
    border: 1px solid rgb(var(--border));
    border-radius: 1rem; padding: 1.25rem;
    box-shadow: var(--shadow-card), inset 0 1px 0 var(--sheen);
    transition: box-shadow .2s ease, transform .2s ease;
}
.panel:hover { box-shadow: var(--shadow-pop), inset 0 1px 0 var(--sheen); }
.panel.overflow-hidden { padding: 0; }

/* Soft metric card — lighter variation with colored accent + depth */
.metric {
    --mc: 59 130 246;
    position: relative; overflow: hidden;
    background: rgb(var(--surface));
    border: 1px solid rgb(var(--border));
    border-radius: 1rem; padding: 1.1rem 1.25rem 1.1rem 1.4rem;
    box-shadow: var(--shadow-card), inset 0 1px 0 var(--sheen);
    transition: transform .2s ease, box-shadow .2s ease;
}
.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-pop), inset 0 1px 0 var(--sheen); }
.metric::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: linear-gradient(180deg, rgb(var(--mc)), rgb(var(--mc) / .35));
}
.metric::after {
    content: ""; position: absolute; top: -40%; right: -12%;
    width: 130px; height: 130px; border-radius: 50%;
    background: radial-gradient(circle, rgb(var(--mc) / .12), transparent 70%);
    pointer-events: none;
}
.metric-label { color: rgb(var(--text-muted)); font-size: .75rem; font-weight: 500; }
.metric-value { color: rgb(var(--mc)); font-size: 1.4rem; font-weight: 700; margin-top: .35rem; }
.metric.mc-emerald { --mc: 16 185 129; }
.metric.mc-rose    { --mc: 239 68 68; }
.metric.mc-blue    { --mc: 59 130 246; }
.metric.mc-amber   { --mc: 217 119 6; }
.metric.mc-violet  { --mc: 139 92 246; }
.panel-title { color: rgb(var(--text-strong)); font-size: 1rem; font-weight: 600; }
.panel-sub { color: rgb(var(--text-muted)); font-size: .8rem; margin-top: .1rem; }

/* ---------- Responsivo ---------- */
canvas { max-width: 100%; }
.page-content { overflow-x: hidden; }
.table-container, .overflow-x-auto { -webkit-overflow-scrolling: touch; }

@media (max-width: 640px) {
    .hero { padding: 1.15rem 1.15rem; border-radius: 1rem; }
    .hero-title { font-size: 1.2rem; }
    .hero-sub { font-size: .8rem; }
    .hero-btn, .hero-btn-ghost { padding: .5rem .75rem; font-size: .78rem; }
    .card, .panel { padding: 1.05rem; }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.4rem; }
    .metric-value { font-size: 1.25rem; }
    .table-header th, .table-row td { padding: .55rem .7rem; }
    .modal-content { margin: 0 .75rem; }
}

/* ---------- Misc ---------- */
.page-content { animation: fadeIn 220ms ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.focus-ring:focus { outline: none; box-shadow: var(--ring); }
