/*
  FinTrack — visual identity: "The Ledger"
  A financial journal feel: warm paper background, deep forest green
  as the primary ink, aged-brass as the single accent. Serif numerals
  for anything that's a monetary amount (the way a printed statement
  sets its figures apart), sans-serif for interface chrome.
  Avoids: uniform rounded-card-with-shadow kit, all-caps labels,
  gradient washes, arrow-suffixed buttons.
*/

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --paper: #F6F4EE;
    --paper-raised: #FFFFFF;
    --ink: #1C1E1B;
    --ink-soft: #52564F;
    --line: #DED9CB;
    --forest: #1B3B32;
    --forest-deep: #12271F;
    --brass: #A9803D;
    --brass-soft: #E8D9B8;
    --good: #2E6B4F;
    --warn: #B07B24;
    --bad: #A23B2E;
    --radius-sm: 4px;
    --radius-md: 8px;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Source Serif 4', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.figure, .money, .stat-value, .table td.amount, .amount-cell {
    font-family: var(--font-serif);
    font-variant-numeric: tabular-nums;
}

/* ---------- App shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--forest-deep);
    color: #E7E5DC;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 1.5rem 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-mark {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    color: var(--brass-soft);
}

.brand-name {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

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

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: #C9C6BA;
    font-size: 0.92rem;
    margin-bottom: 0.15rem;
    border-left: 2px solid transparent;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-link.active {
    background: rgba(169,128,61,0.16);
    color: #F3E7CC;
    border-left-color: var(--brass);
}

.nav-icon { width: 1.1rem; text-align: center; opacity: 0.9; }

.sidebar-footer {
    padding: 0.6rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.logout-link { color: #D8A79A; }

.sidebar-overlay {
    display: none;
}

/* ---------- Main area ---------- */
.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.75rem;
    background: var(--paper-raised);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    font-size: 1rem;
}

.page-title {
    font-family: var(--font-serif);
    font-size: 1.35rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
}

.topbar-right { display: flex; align-items: center; gap: 1.25rem; }
.topbar-date { color: var(--ink-soft); font-size: 0.85rem; }

.topbar-user { display: flex; align-items: center; gap: 0.55rem; }
.user-avatar {
    width: 2rem; height: 2rem; border-radius: 50%;
    background: var(--forest); color: #F3E7CC;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-serif); font-weight: 600;
}
.user-name { font-size: 0.9rem; font-weight: 500; }

.content { padding: 1.75rem; max-width: 1280px; }

/* ---------- Cards / panels ---------- */
.panel {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.25rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.panel-title {
    font-family: var(--font-serif);
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
}

.panel-subtitle { color: var(--ink-soft); font-size: 0.85rem; margin-top: 0.15rem; }

/* Summary / stat cards — differentiated by a left ink bar per meaning, not identical shadows */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-left: 3px solid var(--forest);
    border-radius: var(--radius-sm);
    padding: 1rem 1.15rem;
}

.stat-card.accent-income { border-left-color: var(--good); }
.stat-card.accent-expense { border-left-color: var(--bad); }
.stat-card.accent-balance { border-left-color: var(--forest); }
.stat-card.accent-savings { border-left-color: var(--brass); }
.stat-card.accent-budget { border-left-color: var(--warn); }

.stat-label {
    font-size: 0.78rem;
    color: var(--ink-soft);
    margin-bottom: 0.35rem;
}

.stat-value {
    font-size: 1.55rem;
    font-weight: 600;
}

.stat-note { font-size: 0.78rem; color: var(--ink-soft); margin-top: 0.25rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 0.78rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table td.amount { text-align: right; font-weight: 600; }
.table .amount.positive { color: var(--good); }
.table .amount.negative { color: var(--bad); }
.table-actions { display: flex; gap: 0.4rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    border: 1px solid transparent;
    line-height: 1;
}
.btn-primary { background: var(--forest); color: #F3EFE3; }
.btn-primary:hover { background: var(--forest-deep); }
.btn-outline { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--ink-soft); }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
.btn-brass { background: var(--brass); color: #2B2100; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.form-field input,
.form-field select,
.form-field textarea {
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--paper-raised);
    color: var(--ink);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    border-color: var(--forest);
}
.field-error { color: var(--bad); font-size: 0.78rem; min-height: 1em; }
.form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 0.5rem; }

/* ---------- Filters bar ---------- */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: end;
    margin-bottom: 1.1rem;
}
.filters-bar .form-field { margin-bottom: 0; min-width: 150px; }

/* ---------- Progress bars ---------- */
.progress-track {
    height: 8px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill { height: 100%; background: var(--forest); }
.progress-fill.warn { background: var(--warn); }
.progress-fill.bad { background: var(--bad); }
.progress-fill.brass { background: var(--brass); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}
.badge-safe { background: #E1EEE6; color: var(--good); }
.badge-warning { background: #F3E7CC; color: var(--warn); }
.badge-near { background: #F6DDBF; color: #8A4B14; }
.badge-exceeded { background: #F3DAD5; color: var(--bad); }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(18,39,31,0.45);
    display: none; align-items: center; justify-content: center;
    z-index: 100; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--paper-raised);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem;
}
.modal-title { font-family: var(--font-serif); font-size: 1.15rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.3rem; color: var(--ink-soft); }

/* ---------- Flash messages ---------- */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    border-left: 3px solid transparent;
}
.flash-success { background: #E1EEE6; color: var(--good); border-left-color: var(--good); }
.flash-error { background: #F3DAD5; color: var(--bad); border-left-color: var(--bad); }

/* ---------- Empty states ---------- */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--ink-soft);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.7; }
.empty-state h3 { font-family: var(--font-serif); color: var(--ink); margin: 0 0 0.35rem; }

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--forest-deep);
    padding: 1.5rem;
}
.auth-card {
    background: var(--paper-raised);
    border-radius: var(--radius-md);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 420px;
}
.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-brand .brand-mark { color: var(--forest); font-size: 2rem; }
.auth-brand .brand-name { color: var(--ink); font-size: 1.3rem; }
.auth-title { font-family: var(--font-serif); font-size: 1.2rem; margin: 0 0 0.3rem; }
.auth-subtitle { color: var(--ink-soft); font-size: 0.88rem; margin-bottom: 1.5rem; }
.auth-footer { text-align: center; margin-top: 1.25rem; font-size: 0.88rem; color: var(--ink-soft); }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.small { height: 180px; }

/* ---------- Grid layouts ---------- */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }

/* ---------- Category swatches ---------- */
.cat-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block; margin-right: 0.4rem; }

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .filters-bar, .table-actions, .btn, .no-print { display: none !important; }
    .main-area { width: 100%; }
    .content { padding: 0; max-width: none; }
    body { background: #fff; }
}
