/* Ledgerly design system — self-contained, no external fonts or CDNs. */

:root {
  /* palette (light) */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e6e8ec;
  --border-strong: #d3d7de;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;
  --debit: #dc2626;
  --debit-soft: #fdecec;
  --credit: #059669;
  --credit-soft: #e6f6f0;
  --warn: #b45309;
  --warn-soft: #fdf3e6;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 2px 8px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 236px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --surface: #161a20;
    --surface-2: #1b2028;
    --border: #262c36;
    --border-strong: #333b47;
    --text: #e8eaed;
    --text-muted: #9aa2ad;
    --text-faint: #6b7482;
    --accent: #7c74ff;
    --accent-hover: #948dff;
    --accent-soft: #20213a;
    --debit: #f87171;
    --debit-soft: #2a1a1c;
    --credit: #34d399;
    --credit-soft: #16241f;
    --warn: #fbbf24;
    --warn-soft: #2a2214;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 2px 8px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 22px;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b7bff);
  display: grid; place-items: center; color: #fff; font-weight: 800;
  box-shadow: var(--shadow-sm); flex-shrink: 0;
}
.brand .name { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px; gap: 16px;
}
.topbar h1 { font-size: 21px; }
.topbar .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.content { padding: 4px 32px 40px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .04s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--debit); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--debit-soft); border-color: var(--debit); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.icon-btn {
  width: 32px; height: 32px; padding: 0; justify-content: center;
  border-radius: var(--radius-sm);
}

/* ---------- cards & stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; }

.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stat { padding: 18px 20px; }
.stat .label {
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}
.stat .value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.stat .value.debit { color: var(--debit); }
.stat .value.credit { color: var(--credit); }
.stat .meta { color: var(--text-faint); font-size: 12px; margin-top: 4px; }
.stat .accent-bar { height: 3px; border-radius: 3px; margin-bottom: 14px; width: 34px; background: var(--accent); }

.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 920px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; padding: 11px 16px; color: var(--text-muted);
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { opacity: .5; font-size: 10px; }
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
.amount { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.amount.debit { color: var(--debit); }
.amount.credit { color: var(--credit); }
.merchant-cell { font-weight: 600; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: .35; transition: opacity .12s; }
tr:hover .row-actions { opacity: 1; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.debit { background: var(--debit-soft); color: var(--debit); border-color: transparent; }
.badge.credit { background: var(--credit-soft); color: var(--credit); border-color: transparent; }
.badge.cat { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- filters ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 180px; }
.search {
  position: relative; display: flex; align-items: center;
}
.search svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--text-faint); }
.search input { padding-left: 34px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px; width: 100%; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }
label.field { display: block; }
label.field > span {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 6px;
}

/* ---------- pagination / footer ---------- */
.table-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-top: 1px solid var(--border); color: var(--text-muted);
  font-size: 13px; flex-wrap: wrap; gap: 10px;
}
.pager { display: flex; gap: 6px; align-items: center; }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty .big { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
  backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center;
  z-index: 50; padding: 20px; opacity: 0; transition: opacity .15s;
}
.modal-overlay.open { display: flex; opacity: 1; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  transform: translateY(8px) scale(.99); transition: transform .15s;
}
.modal-overlay.open .modal { transform: none; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 22px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 12px 16px; min-width: 240px; font-weight: 550;
  animation: slidein .2s ease; display: flex; align-items: center; gap: 10px;
}
.toast.ok { border-left-color: var(--credit); }
.toast.err { border-left-color: var(--debit); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding: 8px 0 4px; }
.login-head { text-align: center; padding: 8px 0 22px; }
.login-head p { color: var(--text-muted); margin: 6px 0 0; }
.form-error { color: var(--debit); background: var(--debit-soft); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-top: 14px; }

.section-title { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 12px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }

/* mini bar for distributions */
.bar-track { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- reports ---------- */
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  padding: 7px 15px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text-muted); border: none;
  border-left: 1px solid var(--border); transition: background .12s, color .12s;
}
.segmented button:first-child { border-left: none; }
.segmented button:hover { background: var(--surface-2); color: var(--text); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: 8px; }
.chart .col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; cursor: default; }
.chart .col.clickable { cursor: pointer; }
.chart .bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; }
.chart .bar {
  width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px;
  transition: opacity .12s, background .12s; position: relative;
}
.chart .col:hover .bar { background: var(--accent-hover); }
.chart .bar.empty { background: var(--border-strong); }
.chart .col .xlabel { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chart .bar .tip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  margin-bottom: 6px; background: var(--text); color: var(--surface); font-size: 11px;
  font-weight: 600; padding: 3px 7px; border-radius: 6px; white-space: nowrap; opacity: 0;
  pointer-events: none; transition: opacity .1s; z-index: 5;
}
.chart .col:hover .tip { opacity: 1; }

.catrow { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.catrow:last-child { margin-bottom: 0; }
.catrow .cname { width: 96px; font-size: 13px; flex-shrink: 0; }
.catrow .ctrack { flex: 1; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.catrow .cfill { height: 100%; background: var(--accent); border-radius: 5px; }
.catrow .camt { width: 96px; text-align: right; font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.show { transform: none; }
  .content, .topbar { padding-left: 18px; padding-right: 18px; }
  .form-grid { grid-template-columns: 1fr; }
}
