/* ===== Design Tokens ===== */
:root {
  --primary: #1a56db;
  --primary-light: #3b82f6;
  --primary-bg: #eff6ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text2: #64748b;
  --text3: #94a3b8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* ===== Login Page ===== */
.login-page { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a5f, #1a56db); }
.login-container { text-align: center; }
.login-card { background: white; border-radius: 16px; padding: 3rem 2.5rem; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.15); }
.login-header { margin-bottom: 2rem; }
.login-logo { font-size: 2.5rem; margin-bottom: .5rem; }
.login-header h1 { font-size: 1.4rem; font-weight: 700; }
.login-header p { color: var(--text2); font-size: .85rem; margin-top: .25rem; }
.login-footer { color: rgba(255,255,255,.6); margin-top: 1.5rem; font-size: .8rem; }

/* ===== Form ===== */
.field { margin-bottom: 1rem; text-align: left; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .4rem; color: var(--text2); }
.field input, .field select, .field textarea { width: 100%; padding: .6rem .8rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; font-family: var(--font); transition: border .2s; }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1); }
.error-msg { background: var(--danger-bg); color: var(--danger); padding: .6rem; border-radius: 8px; margin-bottom: 1rem; font-size: .85rem; }
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem; border: none; border-radius: 8px; font-size: .85rem; font-weight: 600; font-family: var(--font); cursor: pointer; transition: all .15s; }
.btn:hover { opacity: .85; }
.btn-primary { background: var(--primary); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; padding: .75rem; font-size: 1rem; }
.btn-ghost { background: none; border: none; color: var(--text2); }

/* ===== Top Nav ===== */
.top-nav { background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 100%); color: white; padding: .6rem 1.5rem; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 12px rgba(26,86,219,.25); flex-wrap: wrap; }
.nav-left { display: flex; align-items: center; gap: .6rem; }
.nav-title { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.nav-badge { background: rgba(255,255,255,.2); padding: .15rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 600; }
.nav-tabs { display: flex; gap: .25rem; margin-left: 1rem; }
.nav-tab { padding: .4rem .8rem; border-radius: 6px; color: rgba(255,255,255,.7); font-size: .85rem; font-weight: 500; cursor: pointer; border: none; background: none; }
.nav-tab:hover { color: white; background: rgba(255,255,255,.1); }
.nav-tab.active { color: white; background: rgba(255,255,255,.2); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.nav-select { background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: .3rem .5rem; font-size: .8rem; }
.nav-select option { color: var(--text); }
.user-name { font-size: .85rem; opacity: .9; }
.btn-logout { background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.2); font-size: .8rem; padding: .3rem .6rem; }

/* ===== Summary Cards ===== */
.summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 1rem 1.5rem; }
.summary-card { background: white; border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); display: flex; align-items: center; gap: .8rem; }
.card-icon { font-size: 1.8rem; }
.card-label { display: block; font-size: .75rem; color: var(--text2); font-weight: 500; }
.card-value { display: block; font-size: 1.3rem; font-weight: 700; margin-top: .15rem; }
.mini-bar-wrap { width: 100%; height: 4px; background: #e5e7eb; border-radius: 2px; margin-top: .5rem; }
.mini-bar { height: 100%; border-radius: 2px; background: var(--primary); transition: width .3s; }

/* ===== Panels ===== */
.panel { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 1.5rem 1rem; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.2rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: .5rem; }
.panel-header h2 { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.table-controls { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ===== Select / Inputs ===== */
.ctrl-select { padding: .35rem .6rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .8rem; font-family: var(--font); background: white; }

/* ===== Budget Table ===== */
.table-scroll { overflow-x: auto; }
.budget-table { width: 100%; border-collapse: collapse; }
.budget-table th { background: #f8fafc; padding: .6rem .8rem; text-align: left; font-size: .75rem; color: var(--text2); font-weight: 600; text-transform: uppercase; border-bottom: 2px solid var(--border); white-space: nowrap; }
.budget-table td { padding: .5rem .8rem; border-bottom: 1px solid #f1f5f9; font-size: .85rem; }
.col-num, .num-cell { text-align: right !important; font-variant-numeric: tabular-nums; }
.tree-row { cursor: default; }
.tree-row:hover { background: #f8fafc; }
.lv-1 td:first-child { padding-left: .8rem; font-weight: 700; font-size: .9rem; }
.lv-2 td:first-child { padding-left: 2rem; font-weight: 600; }
.lv-3 td:first-child { padding-left: 3.5rem; }
.toggle { display: inline-block; width: 1.2rem; cursor: pointer; color: var(--text3); user-select: none; }
.negative { color: var(--danger); font-weight: 600; }
.positive { color: var(--success); }

/* Rate bar */
.rate-cell { display: flex; align-items: center; gap: .5rem; min-width: 120px; }
.rate-text { font-size: .8rem; font-weight: 600; min-width: 36px; text-align: right; }
.rate-bar-bg { flex: 1; height: 6px; background: #e5e7eb; border-radius: 3px; }
.rate-bar { height: 100%; border-radius: 3px; transition: width .3s; }
.rate-bar.green { background: var(--success); }
.rate-bar.yellow { background: var(--warning); }
.rate-bar.red { background: var(--danger); }

/* ===== Charts ===== */
.charts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; padding: 1rem; }
.chart-card { background: #f8fafc; border-radius: 8px; padding: 1rem; }
.chart-card h3 { font-size: .85rem; color: var(--text2); margin-bottom: .5rem; }
.chart-wrap { position: relative; height: 220px; }

/* ===== Tabs Content ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Expense Form ===== */
.expense-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1.2rem; }
.expense-form-col { display: flex; flex-direction: column; gap: .8rem; }
.balance-hint { background: var(--primary-bg); color: var(--primary); padding: .5rem .8rem; border-radius: 8px; display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; }
.balance-hint.over { background: var(--danger-bg); color: var(--danger); }

/* ===== History Table ===== */
.history-table { width: 100%; border-collapse: collapse; }
.history-table th { background: #f8fafc; padding: .5rem .8rem; text-align: left; font-size: .75rem; color: var(--text2); font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; }
.history-table td { padding: .5rem .8rem; border-bottom: 1px solid #f1f5f9; font-size: .85rem; }
.history-table tr:hover { background: #f8fafc; }

/* ===== Upload Area ===== */
.upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; margin: 1rem; cursor: pointer; transition: border .2s; }
.upload-area:hover { border-color: var(--primary); background: var(--primary-bg); }
.upload-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ===== Admin Table ===== */
.admin-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; padding: 1rem; align-items: end; }

/* ===== Toast ===== */
.toast { position: fixed; top: 1rem; right: 1rem; padding: .7rem 1.2rem; border-radius: 8px; font-size: .85rem; font-weight: 500; z-index: 9999; transform: translateX(120%); transition: transform .3s; }
.toast.show { transform: translateX(0); }
.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.toast.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fca5a5; }
.toast.warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fcd34d; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 3rem; color: var(--text3); }
.empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: white; border-radius: 12px; padding: 1.5rem; width: 420px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .expense-panel { grid-template-columns: 1fr; }
  .admin-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .summary-strip { grid-template-columns: 1fr; }
  .nav-tabs { display: none; }
  .admin-form { grid-template-columns: 1fr; }
}
