/* ========================================================================
   Ledger — professional finance UI
   Calm neutral canvas, white cards with hairline borders, confident indigo
   accent, tabular figures, dense but breathable. All class names preserved.
   ======================================================================== */
:root {
  color-scheme: light;

  /* neutrals */
  --bg: #f6f7f9;
  --bg-2: #eef1f5;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --ink: #0f172a;         /* slate-900 */
  --ink-2: #334155;       /* slate-700 */
  --muted: #64748b;       /* slate-500 */
  --faint: #94a3b8;       /* slate-400 */
  --line: #e6e9ef;
  --line-strong: #d6dbe4;

  /* brand + semantic */
  --accent: #4f46e5;      /* indigo-600 */
  --accent-600: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #eef0fe;
  --accent-soft-brd: #dfe2fc;

  --pos: #0f9d58;
  --pos-soft: #e7f6ee;
  --neg: #e5484d;
  --neg-soft: #fdECEC;
  --warn: #b7791f;
  --warn-soft: #fdf3e3;

  --shadow-xs: 0 1px 2px rgba(15,23,42,.06);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 6px 20px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.04);

  --r: 12px;
  --r-sm: 9px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* ---------- header ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar { display: flex; align-items: center; gap: 12px; padding: 13px 0; flex-wrap: wrap; }
.bar h1 {
  font-size: 17px; margin: 0; margin-right: auto; font-weight: 700;
  letter-spacing: -0.02em; color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.bar h1::before {
  content: "₹"; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-600));
  color: #fff; font-size: 15px; font-weight: 800;
  box-shadow: var(--shadow-sm);
}

/* ---------- nav tabs ---------- */
nav.tabs {
  position: sticky; top: 55px; z-index: 19;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
nav.tabs .wrap { display: flex; align-items: stretch; gap: 0; }
nav.tabs .tabs-scroll { flex: 1 1 auto; min-width: 0; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; }
nav.tabs .tabs-scroll::-webkit-scrollbar { display: none; }
/* ‹ › scroll buttons — shown only when the tabs overflow (desktop with a mouse). */
nav.tabs .tab-scroll-btn {
  flex: 0 0 auto; display: none; align-items: center; justify-content: center;
  width: 30px; padding: 0; margin: 0; border: 0; border-bottom: 0;
  background: none; cursor: pointer; color: var(--muted);
  font-size: 22px; line-height: 1; font-family: inherit;
}
nav.tabs .tab-scroll-btn:hover:not(:disabled) { color: var(--accent); }
nav.tabs .tab-scroll-btn:disabled { opacity: .25; cursor: default; }
nav.tabs.scrollable .tab-scroll-btn { display: flex; }
nav.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 12px 14px; margin-bottom: -1px;
  color: var(--muted); cursor: pointer; white-space: nowrap;
  font-size: 13.5px; font-weight: 500; font-family: inherit;
  transition: color .12s ease, border-color .12s ease;
}
nav.tabs button:hover { color: var(--ink); }
nav.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 26px 0 80px; }
h2 { font-size: 15px; margin: 0 0 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }

/* ---------- panels ---------- */
.panel, .tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 20px 22px; margin-bottom: 18px; }

/* ---------- forms ---------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: 13.5px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: #c2c9d6; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 64px; font-family: var(--mono); font-size: 13px; }
.field { flex: 1; min-width: 140px; }

/* ---------- buttons ---------- */
.btn {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: var(--r-sm); padding: 9px 16px; cursor: pointer; font-weight: 600;
  font-size: 13.5px; font-family: inherit; line-height: 1.2;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  box-shadow: var(--shadow-xs); transition: background .12s ease, box-shadow .12s ease, transform .04s ease;
}
.btn:hover { background: var(--accent-600); border-color: var(--accent-600); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-strong); box-shadow: none;
}
.btn.ghost:hover { background: var(--bg-2); border-color: #c2c9d6; color: var(--ink); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; font-weight: 600; }
.btn.danger { background: var(--surface); color: var(--neg); border: 1px solid #f0c0c1; box-shadow: none; }
.btn.danger:hover { background: var(--neg-soft); border-color: var(--neg); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
thead th { border-bottom: 1px solid var(--line-strong); }
th {
  color: var(--faint); font-weight: 600; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .06em;
}
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* ---------- small tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { padding: 16px 18px; }
.tile .k { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.tile .v { font-size: 23px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; border: 1px solid var(--accent-soft-brd);
}
.muted { color: var(--muted); }

/* ---------- auth ---------- */
.center {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #eef0fe 0%, var(--bg) 55%);
}
.card {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-md);
  padding: 32px; width: 360px;
}
.card h2 { text-align: center; font-size: 18px; margin-bottom: 6px; }
.card .btn { margin-top: 6px; justify-content: center; }
.card input { margin-bottom: 4px; }
/* "Developed by" credit badge on the login screen (bottom-right corner). */
.dev-badge {
  position: fixed; right: 20px; bottom: 18px; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 12px;
  background: rgba(255,255,255,0.85); border: 1px solid var(--line);
  box-shadow: var(--shadow-sm); backdrop-filter: blur(4px);
}
.dev-badge-label { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: var(--muted); }
.dev-badge-logo { height: 38px; width: auto; display: block; }
@media (max-width: 480px) { .dev-badge { right: 12px; bottom: 12px; padding: 6px 10px; gap: 7px; } .dev-badge-label { letter-spacing: 1.5px; } .dev-badge-logo { height: 30px; } }
/* Live-update banner: shown when another user's change arrives while you're mid-interaction. */
.live-banner {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 12px;
  box-shadow: var(--shadow-md); font-size: 14px; max-width: calc(100vw - 32px);
}
.live-banner .btn { padding: 5px 12px; }
.err { color: var(--neg); font-size: 13px; margin-top: 8px; }
.ok { color: var(--pos); font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 50;
  box-shadow: var(--shadow-md); font-size: 13.5px; font-weight: 500;
  animation: toastin .18s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- dashboard hero / KPI cards ---------- */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(212px, 1fr)); gap: 14px; margin-bottom: 18px; }
.hcard {
  padding: 18px 20px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.hcard::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); }
.hcard.green::before { background: var(--pos); }
.hcard.red::before { background: var(--neg); }
.hcard.blue::before { background: var(--accent); }
.hcard.amber::before { background: var(--warn); }
.hcard .lbl { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.hcard .val { font-size: 27px; font-weight: 800; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; color: var(--ink); }
.hcard .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hcard.green .val { color: var(--pos); }
.hcard.red .val { color: var(--neg); }

/* ---------- position bar ---------- */
.posbar { display: flex; height: 32px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); background: var(--bg-2); }
.posbar > div { display: flex; align-items: center; padding: 0 12px; font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap; }
.posbar .seg-lena { background: var(--pos); } .posbar .seg-dena { background: var(--neg); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .wrap { padding: 0 16px; }
  /* Keep wide tables inside their card on phones: the card scrolls sideways
     instead of the whole table spilling off the right edge of the screen. */
  .panel { overflow-x: auto; }
  th, td { padding: 8px 10px; }
}

.scrollframe { max-height: 440px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.scrollframe table th { position: sticky; top: 0; background: var(--surface); z-index: 1; box-shadow: inset 0 -1px 0 var(--line-strong); }

.mono { font-family: var(--mono); }
.right { margin-left: auto; }
details.help { margin-top: 10px; font-size: 13px; color: var(--muted); }
details.help summary { cursor: pointer; }
.testbox {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 14px; font-size: 13px; margin-top: 12px;
}
.testbox table td { border: 0; padding: 4px 8px 4px 0; }

/* ---------- number provenance: clickable numbers + drill-down drawer ---------- */
.traceable { cursor: pointer; border-bottom: 1px dashed currentColor; border-radius: 1px; transition: background .1s ease; }
.traceable:hover { background: var(--accent-soft); }
.hcard .val .traceable, .hcard .val.traceable { border-bottom-width: 2px; }

.drawer-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; justify-content: flex-end;
  background: rgba(15, 23, 42, 0.38); animation: traceFade .14s ease;
}
.drawer {
  width: 440px; max-width: 94vw; height: 100%; background: var(--surface);
  box-shadow: -10px 0 40px rgba(15, 23, 42, 0.22); display: flex; flex-direction: column;
  animation: traceSlide .18s cubic-bezier(.2,.7,.3,1);
}
@keyframes traceFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes traceSlide { from { transform: translateX(28px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.drawer-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.drawer-formula { padding: 12px 20px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); white-space: pre-wrap; line-height: 1.5; }
.drawer-body { padding: 6px 12px 20px; overflow: auto; flex: 1; }
.trace-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 10px; border-bottom: 1px solid var(--line); }
.trace-row:last-child { border-bottom: 0; }
.trace-row .trace-label { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; }
.trace-row.clickable { cursor: pointer; border-radius: 9px; }
.trace-row.clickable:hover { background: var(--accent-soft); }
.trace-row.clickable .trace-label::after { content: " ›"; color: var(--faint); }


/* --- business analytics --- */
.span-2 { grid-column: 1 / -1; }
.chartbox { position: relative; height: 300px; }
.chartbox.hero { height: 320px; }
@media (max-width: 760px) { .chartbox, .chartbox.hero { height: 220px; } }
