/* =========================================================
   FinFlow — Design System
   Analytical dark/light theme via CSS custom properties
   ========================================================= */

/* DARK THEME (default) */
:root,
[data-theme="dark"] {
    --bg-primary:    #0d0f17;
    --bg-secondary:  #111420;
    --bg-card:       #161926;
    --bg-hover:      #1d2130;
    --bg-input:      #1a1d2e;

    --border:        rgba(255,255,255,.08);
    --border-hover:  rgba(255,255,255,.16);

    --text-primary:  #f0f2f8;
    --text-secondary:#a8afc4;
    --text-muted:    #5e6580;

    --green:         #10b981;
    --green-subtle:  rgba(16,185,129,.12);
    --red:           #ef4444;
    --red-subtle:    rgba(239,68,68,.12);
    --indigo:        #6366f1;
    --indigo-subtle: rgba(99,102,241,.12);
    --yellow:        #f59e0b;
    --yellow-subtle: rgba(245,158,11,.12);

    --shadow-sm:     0 1px 3px rgba(0,0,0,.4);
    --shadow-md:     0 4px 16px rgba(0,0,0,.5);
    --shadow-lg:     0 12px 40px rgba(0,0,0,.6);

    --sidebar-width: 240px;
    --topbar-height: 60px;
    --radius:        12px;
    --radius-sm:     8px;
}

/* LIGHT THEME */
[data-theme="light"] {
    --bg-primary:    #f4f6fc;
    --bg-secondary:  #eaecf5;
    --bg-card:       #ffffff;
    --bg-hover:      #f0f2fa;
    --bg-input:      #f8f9fe;

    --border:        rgba(0,0,0,.08);
    --border-hover:  rgba(0,0,0,.16);

    --text-primary:  #111827;
    --text-secondary:#374151;
    --text-muted:    #9ca3af;

    --green:         #059669;
    --green-subtle:  rgba(5,150,105,.1);
    --red:           #dc2626;
    --red-subtle:    rgba(220,38,38,.1);
    --indigo:        #4f46e5;
    --indigo-subtle: rgba(79,70,229,.1);
    --yellow:        #d97706;
    --yellow-subtle: rgba(217,119,6,.1);

    --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
    --shadow-md:     0 4px 16px rgba(0,0,0,.12);
    --shadow-lg:     0 12px 40px rgba(0,0,0,.16);
}

/* =========================================================
   RESET & BASE
   ========================================================= */

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background 0.2s, color 0.2s;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* =========================================================
   TYPOGRAPHY
   ========================================================= */

.mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    letter-spacing: -0.5px;
}

.text-sm   { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg   { font-size: 16px; }
.text-xl   { font-size: 20px; }
.text-2xl  { font-size: 24px; }
.text-3xl  { font-size: 30px; }

.font-medium  { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold    { font-weight: 700; }

.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-green     { color: var(--green); }
.text-red       { color: var(--red); }
.text-indigo    { color: var(--indigo); }
.text-yellow    { color: var(--yellow); }

/* =========================================================
   LAYOUT
   ========================================================= */

.app-root {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    height: var(--topbar-height);
}

.logo-mark {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #6366f1, #10b981);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
    letter-spacing: -1px;
    flex-shrink: 0;
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 16px 10px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    text-decoration: none;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--indigo-subtle);
    color: var(--indigo);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.75;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s;
}

.user-pill:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--indigo-subtle);
    border: 2px solid var(--border);
    object-fit: cover;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* TOPBAR */
.topbar {
    grid-area: topbar;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    z-index: 90;
}

.topbar-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.topbar-left > div {
    display: flex;
    flex-direction: column;
}

.page-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.page-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* MAIN CONTENT */
.main-content {
    grid-area: main;
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 28px;
    overflow-y: auto;
    min-width: 0;
}

/* =========================================================
   CARDS
   ========================================================= */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* =========================================================
   KPI METRICS
   ========================================================= */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.kpi-card.green::before { background: var(--green); }
.kpi-card.red::before   { background: var(--red); }
.kpi-card.indigo::before { background: var(--indigo); }
.kpi-card.yellow::before { background: var(--yellow); }

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.kpi-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 26px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: 8px;
}

.kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    padding: 2px 7px;
    border-radius: 20px;
}

.kpi-delta.up   { color: var(--green); background: var(--green-subtle); }
.kpi-delta.down { color: var(--red);   background: var(--red-subtle); }
.kpi-delta.neutral { color: var(--text-muted); background: var(--bg-hover); }

/* =========================================================
   TABLE
   ========================================================= */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead tr {
    border-bottom: 1px solid var(--border);
}

thead th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 10px 14px;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-hover);
}

tbody td {
    padding: 12px 14px;
    color: var(--text-secondary);
    vertical-align: middle;
}

tbody td.primary {
    color: var(--text-primary);
    font-weight: 500;
}

.amount-positive {
    font-family: 'JetBrains Mono', monospace;
    color: var(--green);
    font-weight: 500;
}

.amount-negative {
    font-family: 'JetBrains Mono', monospace;
    color: var(--red);
    font-weight: 500;
}

/* =========================================================
   BADGES
   ========================================================= */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-green  { background: var(--green-subtle);  color: var(--green); }
.badge-red    { background: var(--red-subtle);    color: var(--red); }
.badge-indigo { background: var(--indigo-subtle); color: var(--indigo); }
.badge-yellow { background: var(--yellow-subtle); color: var(--yellow); }
.badge-muted  { background: var(--bg-hover);      color: var(--text-muted); }

/* =========================================================
   BUTTONS
   ========================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.12s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--indigo);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--red-subtle);
    color: var(--red);
    border: 1px solid rgba(239,68,68,.2);
}

.btn-danger:hover {
    background: var(--red);
    color: #fff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

/* =========================================================
   FORM ELEMENTS
   ========================================================= */

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13.5px;
    transition: border-color 0.12s, box-shadow 0.12s;
    outline: none;
    appearance: none;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px var(--indigo-subtle);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* =========================================================
   MODAL
   ========================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    transform: translateY(12px);
    transition: transform 0.2s;
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* =========================================================
   PROGRESS BAR
   ========================================================= */

.progress-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* =========================================================
   CSV DROP ZONE
   ========================================================= */

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 36px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--indigo);
    background: var(--indigo-subtle);
}

.drop-zone-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.drop-zone-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.drop-zone-sub {
    font-size: 12px;
    color: var(--text-muted);
}

/* =========================================================
   GRID UTILITIES
   ========================================================= */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.flex    { display: flex; }
.flex-1  { flex: 1; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 12px; }
.gap-4   { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }

/* =========================================================
   SCROLLBAR
   ========================================================= */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =========================================================
   HAMBURGER + SIDEBAR MOBILE
   ========================================================= */

.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 10px;
    transition: background 0.12s;
}

.hamburger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: auto;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.12s;
}

.sidebar-close:hover { color: var(--text-primary); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.open { display: block; }

/* Chart containers */
.chart-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 900px) {
    :root { --topbar-height: 56px; }

    .app-root {
        grid-template-columns: 1fr;
        grid-template-areas: "topbar" "main";
    }

    /* Sidebar vira drawer */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .hamburger      { display: flex; }
    .sidebar-close  { display: flex; }

    .topbar {
        left: 0;
        padding: 0 16px;
    }

    .topbar-left {
        flex-direction: row;
        align-items: center;
        gap: 0;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .grid-3   { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
    .kpi-grid         { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3  { grid-template-columns: 1fr; }

    .kpi-value { font-size: 20px; }

    .card { padding: 16px; }
    .card-header { flex-wrap: wrap; gap: 10px; }

    /* Oculta colunas menos importantes na tabela em mobile */
    table th:nth-child(3),
    table td:nth-child(3),
    table th:nth-child(5),
    table td:nth-child(5) { display: none; }
}

@media (max-width: 420px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .main-content { padding: 12px; }
}

/* =========================================================
   YEAR / MONTH TABS (Dashboard navigation)
   ========================================================= */

.year-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.year-tab {
    padding: 6px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: all 0.15s;
    cursor: pointer;
}

.year-tab:hover {
    border-color: var(--indigo);
    color: var(--indigo);
}

.year-tab.active {
    background: var(--indigo);
    border-color: var(--indigo);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,.3);
}

/* Annual summary strip */
.year-summary {
    display: flex;
    align-items: center;
    gap: 32px;
    flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    margin-bottom: 16px;
}

.year-summary-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
}

.year-summary-item { display: flex; flex-direction: column; gap: 2px; }

.year-summary-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 500;
}

.year-summary-val.green { color: var(--green); }
.year-summary-val.red   { color: var(--red); }

.year-summary-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Month tabs */
.month-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.month-tab {
    padding: 4px 11px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    transition: all 0.12s;
    cursor: pointer;
}

.month-tab:hover:not(.disabled) {
    border-color: var(--indigo);
    color: var(--indigo);
}

.month-tab.active {
    background: var(--indigo-subtle);
    border-color: var(--indigo);
    color: var(--indigo);
    font-weight: 600;
}

.month-tab.disabled {
    opacity: 0.28;
    pointer-events: none;
    cursor: default;
}

@media (max-width: 640px) {
    .year-summary { gap: 16px; padding: 10px 14px; }
    .year-summary-label { display: none; }
}
