/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg: #0f1117; --bg2: #161b27; --bg3: #1e2535; --bg4: #252d40;
  --border: #2a3347; --border2: #364060;
  --text: #e8ecf3; --text2: #9aa5be; --text3: #5c6880;
  --accent: #6366f1; --accent-h: #7c7ff5; --accent-dim: rgba(99,102,241,.15);
  --green: #10b981; --green-dim: rgba(16,185,129,.15);
  --red: #ef4444; --red-dim: rgba(239,68,68,.15);
  --yellow: #f59e0b; --yellow-dim: rgba(245,158,11,.15);
  --blue: #3b82f6; --blue-dim: rgba(59,130,246,.15);
  --purple: #8b5cf6; --purple-dim: rgba(139,92,246,.15);
  --radius: 12px; --radius-sm: 8px; --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --sidebar-w: 220px; --header-h: 56px;
  --font: 'Inter', system-ui, sans-serif;
  --transition: 0.18s ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; overflow-x: hidden; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; }
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; width: 100%; background: var(--bg); }
#main-app { display: flex; width: 100%; height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; height: 100vh; overflow-y: auto; z-index: 200; transition: transform var(--transition); }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 16px 16px; font-weight: 700; font-size: 1.05rem; color: var(--accent); border-bottom: 1px solid var(--border); }
.sidebar-logo svg { width: 22px; height: 22px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text2); font-size: .875rem; font-weight: 500; transition: all var(--transition); cursor: pointer; white-space: nowrap; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item-btn { width: 100%; text-align: left; }
.sidebar-bottom { padding: 12px 8px; border-top: 1px solid var(--border); }

/* ── Mobile Header ──────────────────────────────────────────────────────────── */
.mobile-header { display: none; align-items: center; justify-content: space-between; height: var(--header-h); padding: 0 16px; background: var(--bg2); border-bottom: 1px solid var(--border); position: fixed; top: 0; left: 0; right: 0; z-index: 150; }
.mobile-header span { font-weight: 600; font-size: .95rem; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 190; }

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; height: 100vh; }
.view { padding: 24px; max-width: 1280px; margin: 0 auto; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.view-title { font-size: 1.4rem; font-weight: 700; }
.view-subtitle { color: var(--text2); font-size: .875rem; margin-top: 2px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-sm { padding: 16px; }
.card-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin-bottom: 8px; }
.card-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.card-sub { font-size: .8rem; color: var(--text2); margin-top: 4px; }

/* ── Grids ──────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 16px; }

/* ── Stat Cards ─────────────────────────────────────────────────────────────── */
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: relative; overflow: hidden; transition: border-color var(--transition); }
.stat-card:hover { border-color: var(--border2); }
.stat-card .icon { width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.stat-card .icon svg { width: 18px; height: 18px; }
.stat-card .label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); }
.stat-card .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.stat-card .sub { font-size: .78rem; color: var(--text2); margin-top: 4px; }
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { background: var(--bg3); }

/* Color Variants */
.icon-green { background: var(--green-dim); color: var(--green); }
.icon-red { background: var(--red-dim); color: var(--red); }
.icon-blue { background: var(--blue-dim); color: var(--blue); }
.icon-yellow { background: var(--yellow-dim); color: var(--yellow); }
.icon-accent { background: var(--accent-dim); color: var(--accent); }
.icon-purple { background: var(--purple-dim); color: var(--purple); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue { color: var(--blue); }
.text-accent { color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500; transition: all var(--transition); cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--bg3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg4); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success { background: var(--green-dim); color: var(--green); border-color: transparent; }
.btn-success:hover { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.icon-btn { width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--text2); transition: all var(--transition); }
.icon-btn:hover { background: var(--bg3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .8rem; font-weight: 500; color: var(--text2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
input[type="text"], input[type="number"], input[type="date"], input[type="password"],
input[type="email"], select, textarea {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 9px 12px; font-size: .875rem; width: 100%;
  transition: border-color var(--transition); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select option { background: var(--bg3); }
textarea { resize: vertical; min-height: 80px; }
.input-icon { position: relative; }
.input-icon input { padding-left: 36px; }
.input-icon svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text3); }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg3); }
th { text-align: left; padding: 10px 14px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); white-space: nowrap; }
td { padding: 11px 14px; font-size: .875rem; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--bg3); }
.tr-selected td { background: var(--accent-dim) !important; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-gray { background: var(--bg4); color: var(--text2); }

/* ── Progress Bar ───────────────────────────────────────────────────────────── */
.progress-wrap { background: var(--bg4); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 99px; transition: width 0.4s ease; }
.progress-ok { background: var(--green); }
.progress-warn { background: var(--yellow); }
.progress-critical { background: var(--red); }

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 40px 36px; width: 100%; max-width: 380px; text-align: center; }
.login-logo { width: 56px; height: 56px; background: var(--accent-dim); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; }
.login-logo svg { width: 28px; height: 28px; color: var(--accent); }
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { color: var(--text2); font-size: .875rem; margin-bottom: 28px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.login-hint { font-size: .8rem; color: var(--text2); text-align: center; min-height: 20px; }
.login-hint.error { color: var(--red); }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--bg3); border: 1px solid var(--border); font-size: .875rem; min-width: 260px; max-width: 400px; box-shadow: var(--shadow); animation: slideIn .2s ease; }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast.success { border-color: var(--green); }
.toast.success svg { color: var(--green); }
.toast.error { border-color: var(--red); }
.toast.error svg { color: var(--red); }
.toast.info svg { color: var(--blue); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 500; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadeIn .15s ease; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); animation: scaleIn .18s ease; }
.modal-lg { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* ── Specific Components ────────────────────────────────────────────────────── */
.tx-amount-pos { color: var(--green); font-weight: 600; }
.tx-amount-neg { color: var(--red); font-weight: 600; }
.tx-amount-transfer { color: var(--blue); font-weight: 600; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.merchant-tag { display: inline-flex; align-items: center; gap: 4px; background: var(--bg4); padding: 2px 8px; border-radius: 99px; font-size: .75rem; color: var(--text2); }
.insight-item { display: flex; gap: 12px; padding: 12px; background: var(--bg3); border-radius: var(--radius-sm); border-left: 3px solid var(--border2); }
.insight-item.warning { border-left-color: var(--yellow); }
.insight-item.critical { border-left-color: var(--red); }
.insight-item.info { border-left-color: var(--blue); }
.insight-item svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 48px 24px; color: var(--text2); text-align: center; }
.empty-state svg { width: 40px; height: 40px; opacity: .4; }
.empty-state p { font-size: .875rem; max-width: 260px; }
.section-title { font-size: .9rem; font-weight: 600; margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--bg3); border: 1px solid var(--border); border-radius: 99px; padding: 3px 10px; font-size: .75rem; color: var(--text2); }

/* ── Budget Progress ────────────────────────────────────────────────────────── */
.budget-row { display: flex; flex-direction: column; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-row-top { display: flex; justify-content: space-between; align-items: center; }
.budget-row-amounts { display: flex; gap: 8px; font-size: .78rem; color: var(--text2); }

/* ── Forecast ───────────────────────────────────────────────────────────────── */
.forecast-breakdown { display: flex; flex-direction: column; gap: 6px; }
.forecast-line { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: var(--radius-sm); font-size: .875rem; }
.forecast-line.positive { background: var(--green-dim); }
.forecast-line.negative { background: var(--red-dim); }
.forecast-line.result { background: var(--accent-dim); font-weight: 600; }
.forecast-line.balance { background: var(--bg3); }
.data-note { font-size: .75rem; color: var(--text3); font-style: italic; margin-top: 6px; }

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ── Loading Spinner ────────────────────────────────────────────────────────── */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.loading-wrap { display: flex; justify-content: center; align-items: center; padding: 64px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; background: var(--bg3); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.tab { flex: 1; text-align: center; padding: 7px 12px; border-radius: 6px; font-size: .8rem; font-weight: 500; color: var(--text2); cursor: pointer; transition: all var(--transition); }
.tab.active { background: var(--bg2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }

/* ── Filters Bar ────────────────────────────────────────────────────────────── */
.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters-bar input, .filters-bar select { width: auto; flex: 1; min-width: 140px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .main-content { padding-top: var(--header-h); height: 100vh; }
  .view { padding: 16px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .modal { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; align-self: flex-end; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .card-value { font-size: 1.4rem; }
}
