/* Ledgerly — modern fintech UI. Light/dark via [data-theme]. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f2;
  --text: #1a2233;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-contrast: #ffffff;
  --income: #16a34a;
  --income-soft: #dcfce7;
  --expense: #dc2626;
  --expense-soft: #fee2e2;
  --transfer: #2563eb;
  --transfer-soft: #dbeafe;
  --liability: #d97706;
  --liability-soft: #fef3c7;
  --receivable: #0d9488;
  --receivable-soft: #ccfbf1;
  --warning: #d97706;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #131a2e;
  --surface-2: #0f1527;
  --border: #232c45;
  --text: #e6eaf3;
  --text-muted: #8d99b5;
  --primary: #818cf8;
  --primary-soft: #1d2342;
  --primary-contrast: #0b1020;
  --income: #4ade80;
  --income-soft: #11301d;
  --expense: #f87171;
  --expense-soft: #3a1414;
  --transfer: #60a5fa;
  --transfer-soft: #122544;
  --liability: #fbbf24;
  --liability-soft: #38280a;
  --receivable: #2dd4bf;
  --receivable-soft: #0c2e2a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; padding: 18px 14px; gap: 18px;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 22px 26px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; padding: 4px 10px; }
.brand-mark { color: var(--primary); font-size: 1.5rem; line-height: 1; }
.brand-center { justify-content: center; margin-bottom: 18px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: 10px; color: var(--text-muted); font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { width: 18px; text-align: center; opacity: .9; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  color: var(--primary-contrast); display: grid; place-items: center; font-weight: 700;
}
.user-name { font-weight: 600; font-size: .92rem; }
.user-sub { color: var(--text-muted); font-size: .78rem; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 26px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 1.15rem; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
#sidebarToggle { display: none; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.card + .card { margin-top: 18px; }
.card h3 { margin: 0 0 12px; font-size: .95rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; }
.stat-sub { color: var(--text-muted); font-size: .85rem; margin-top: 4px; }
.pos { color: var(--income); }
.neg { color: var(--expense); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-income { background: var(--income-soft); color: var(--income); }
.badge-expense { background: var(--expense-soft); color: var(--expense); }
.badge-transfer { background: var(--transfer-soft); color: var(--transfer); }
.badge-liability { background: var(--liability-soft); color: var(--liability); }
.badge-receivable { background: var(--receivable-soft); color: var(--receivable); }
.badge-warning { background: var(--liability-soft); color: var(--warning); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: .9rem; cursor: pointer; background: none; color: var(--text);
  transition: filter .12s ease, background .12s ease;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
[data-theme="dark"] .btn-primary { color: #0b1020; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-ghost { border-color: var(--border); background: var(--surface); }
.btn-sm { padding: 6px 11px; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px 11px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; font-weight: 500; }
.field small { color: var(--text-muted); font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .9rem; }
.checkbox input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.inline-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline-form .field { min-width: 130px; flex: 1; }

/* Progress bars */
.progress { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress-bar.warn { background: var(--warning); }
.progress-bar.over { background: var(--expense); }

/* Flash */
.flash { margin: 14px 26px 0; padding: 11px 16px; border-radius: 10px; font-weight: 500; font-size: .9rem; }
.auth-card .flash { margin: 0 0 14px; }
.flash-success { background: var(--income-soft); color: var(--income); }
.flash-error { background: var(--expense-soft); color: var(--expense); }

/* Auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); padding: 34px 32px;
}
.auth-title { margin: 0 0 18px; text-align: center; }
.auth-alt { text-align: center; color: var(--text-muted); margin-top: 16px; }

/* Empty states */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2.6rem; margin-bottom: 10px; }
.empty-state h2 { color: var(--text); }
.empty-state .btn { margin-top: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 28, .55); z-index: 60;
  display: grid; place-items: center; padding: 18px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  padding: 24px; width: 100%; max-width: 440px; border: 1px solid var(--border);
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Timeline (PayLater schedule) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex; align-items: center; gap: 14px; padding: 11px 4px;
  border-bottom: 1px dashed var(--border);
}
.timeline li:last-child { border-bottom: none; }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.timeline .dot.paid { background: var(--income); }
.timeline .dot.partial { background: var(--warning); }
.timeline .dot.overdue { background: var(--expense); }
.timeline .when { width: 110px; color: var(--text-muted); font-size: .85rem; }
.timeline .what { flex: 1; }
.timeline .amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Bulk action bar */
.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--primary-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 14px; margin-bottom: 14px;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar select, .bulk-bar input { width: auto; padding: 6px 10px; }
.row-actions { white-space: nowrap; }
.row-actions .btn { padding: 4px 8px; }

/* Misc */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .field { min-width: 130px; }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.mt { margin-top: 16px; }
.chart-box { position: relative; height: 260px; }
.pagination { display: flex; gap: 6px; margin-top: 14px; justify-content: center; }
.notes-block { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.balances-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px; font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; }
.chip .cur { color: var(--text-muted); font-weight: 500; margin-right: 6px; }
code.token-box { display: block; background: var(--surface-2); border: 1px dashed var(--primary); border-radius: 10px; padding: 12px; word-break: break-all; margin: 8px 0; }

/* Responsive */
@media (max-width: 920px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%);
    transition: transform .2s ease; width: 260px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  #sidebarToggle { display: inline-flex; }
  .content { padding: 16px 14px 70px; }
  .topbar { padding: 12px 14px; }
  .btn-quick-add { padding: 9px 12px; }
}
