/* 4Finance Lab - styles */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --text: #0f1b2d;
  --muted: #5b6b80;
  --accent: #0e7c86;
  --accent-2: #0a5f67;
  --accent-soft: #e2f3f4;
  --navy: #0f2742;
  --side-bg: #0f2742;
  --side-text: #c9d6e6;
  --side-active: #ffffff;
  --side-hover: rgba(255,255,255,0.07);
  --good: #15803d; --good-bg: #ecfdf3; --good-bd: #a7e3bd;
  --warn: #b45309; --warn-bg: #fff8eb; --warn-bd: #f7d38f;
  --bad:  #b91c1c; --bad-bg:  #fef2f2; --bad-bd:  #f6b4b4;
  --c1: #0e7c86; --c2: #e0662f; --c3: #3b6fd8; --c4: #8a4fc7; --c5: #c23b5a; --c6: #6b7f2a;
  --grid: rgba(15,27,45,0.08);
  --shadow: 0 1px 2px rgba(15,27,45,.06), 0 6px 20px rgba(15,27,45,.06);
  --radius: 14px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1320;
  --surface: #121c2c;
  --surface-2: #162236;
  --surface-3: #1c2a40;
  --border: #26354d;
  --text: #e6edf6;
  --muted: #94a5bb;
  --accent: #2bb3bd;
  --accent-2: #5fd0d8;
  --accent-soft: #11343b;
  --side-bg: #08101b;
  --side-text: #a9b8cb;
  --good: #4ade80; --good-bg: #0f2a1c; --good-bd: #1f5c3a;
  --warn: #fbbf24; --warn-bg: #2d220b; --warn-bd: #6b4d12;
  --bad:  #f87171; --bad-bg:  #2f1214; --bad-bd:  #6f2328;
  --c1: #2bb3bd; --c2: #f08a54; --c3: #6f9bf0; --c4: #b48ae6; --c5: #ec6f8b; --c6: #a7bf55;
  --grid: rgba(230,237,246,0.09);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--side-bg) 270px, transparent 270px); }
.sidebar {
  background: var(--side-bg); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; text-decoration: none; color: #fff; cursor: pointer; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand b { display: block; font-size: 1.15rem; letter-spacing: .2px; }
.brand small { color: var(--side-text); font-size: .75rem; }
.nav-cat { font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1.2px; color: #ffffff; margin: 16px 10px 6px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.22); }
.nav-item[data-go="home"] + .nav-cat { border-top: 0; padding-top: 4px; }
.lab-badge { display: inline-flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.lab-badge .emef { display: inline-flex; align-items: center; border: 1.5px solid var(--accent); border-radius: 7px; overflow: hidden; font-weight: 800; color: var(--accent); }
.lab-badge .emef b { padding: 2px 6px; border-left: 1.5px solid var(--accent); line-height: 1.3; }
.lab-badge .emef b:first-child { border-left: 0; }
.lab-badge .emef span { padding: 2px 7px; background: var(--accent); color: #fff; font-weight: 700; line-height: 1.3; }
.lab-badge .who { font-weight: 600; color: var(--text); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--side-text); text-align: left;
  padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: .9rem;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav-item.active { background: rgba(43,179,189,.18); color: var(--side-active); box-shadow: inset 3px 0 0 #2bb3bd; }
.side-foot { margin-top: auto; padding: 16px 10px 4px; font-size: .75rem; color: #7f93ad; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .crumb { font-weight: 600; font-size: .95rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumb span { color: var(--muted); font-weight: 500; }
.icon-btn.menu-btn { display: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; min-width: 36px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.content { padding: 26px 28px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ---------- Home ---------- */
.hero {
  background: linear-gradient(135deg, #0f2742 0%, #0e5961 60%, #0e7c86 100%);
  color: #fff; border-radius: 18px; padding: 34px 34px 30px; position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 6px; font-size: 2rem; letter-spacing: -.3px; }
.hero p { margin: 0; color: #cfe6ea; max-width: 640px; }
.hero svg.deco { position: absolute; right: -10px; bottom: -10px; width: 360px; opacity: .22; }
.hero .chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.hero .chips span { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); padding: 4px 10px; border-radius: 999px; font-size: .78rem; }
.home-cat { margin: 30px 0 12px; font-size: .78rem; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); font-weight: 700; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 8px;
  transition: transform .15s, box-shadow .15s, border-color .15s; box-shadow: var(--shadow);
}
.tool-card:hover, .tool-card:focus-visible { transform: translateY(-2px); border-color: var(--accent); outline: none; }
.tool-card .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.tool-card .ic svg { width: 22px; height: 22px; }
.tool-card h3 { margin: 4px 0 0; font-size: 1rem; }
.tool-card p { margin: 0; color: var(--muted); font-size: .85rem; }
.tool-card .new { align-self: flex-start; font-size: .68rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; }

/* ---------- Tool view ---------- */
.tool-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.tool-head .ic { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.tool-head .ic svg { width: 26px; height: 26px; }
.tool-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.2px; }
.tool-head p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; max-width: 720px; }
.tool-head .grow { flex: 1; min-width: 240px; }
.tool-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .85rem;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); color: #fff; }
.btn svg { width: 16px; height: 16px; }

.tool-body { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-h h2, .panel-h h3 { margin: 0; font-size: .95rem; }
.panel-b { padding: 16px 18px; }
.inputs { position: sticky; top: 76px; }
.inputs .panel-b { display: grid; gap: 12px; }
.field label { display: flex; justify-content: space-between; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field label em { font-style: normal; font-weight: 500; opacity: .8; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; font-size: .93rem;
}
.field textarea { font-family: var(--mono); font-size: .85rem; min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input:disabled { background: var(--accent-soft); color: var(--accent); font-weight: 700; border-style: dashed; }
.field .hint { font-size: .74rem; color: var(--muted); margin-top: 3px; }
.field.hidden { display: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface-3); padding: 4px; border-radius: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.reset-link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .78rem; text-decoration: underline; padding: 0; }
.file-row { display: flex; gap: 8px; flex-wrap: wrap; }
.co-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; }
.co-row select { width: auto; }
.colpick { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow: auto; padding: 6px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
.field .colpick label.chk { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 9px; border-radius: 7px; background: var(--surface-3); color: var(--text); font-weight: 500; cursor: pointer; }
.field .colpick input[type=checkbox] { width: auto; padding: 0; margin: 0; box-shadow: none; accent-color: var(--accent); }
.file-btn { cursor: pointer; }
.file-status { font-size: .78rem; color: var(--muted); margin-top: 6px; }

.results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }
.results > * { min-width: 0; }
.msg { padding: 12px 14px; border-radius: 10px; font-size: .88rem; border: 1px solid var(--warn-bd); background: var(--warn-bg); color: var(--warn); }
.msg.err { border-color: var(--bad-bd); background: var(--bad-bg); color: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--accent); }
.kpi .k { font-size: .76rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.kpi .v { font-size: 1.45rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; word-break: break-word; }
.kpi .s { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.kpi.good { border-top-color: var(--good); background: var(--good-bg); } .kpi.good .v { color: var(--good); }
.kpi.warn { border-top-color: var(--warn); background: var(--warn-bg); } .kpi.warn .v { color: var(--warn); }
.kpi.bad  { border-top-color: var(--bad);  background: var(--bad-bg);  } .kpi.bad  .v { color: var(--bad); }
.kpi.big .v { font-size: 2rem; }

.chart-wrap { position: relative; height: 340px; }
.chart-wrap.tall { height: 400px; }
.chart-note { font-size: .76rem; color: var(--muted); margin-top: 8px; }
.mini-btns { display: flex; gap: 6px; }
.mini { border: 1px solid var(--border); background: var(--surface-2); border-radius: 7px; padding: 4px 8px; font-size: .74rem; font-weight: 600; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.mini:hover { border-color: var(--accent); color: var(--accent); }
.mini svg { width: 13px; height: 13px; }

.tbl-scroll { overflow: auto; max-height: 460px; }
table.data { width: 100%; border-collapse: collapse; font-size: .86rem; font-variant-numeric: tabular-nums; }
table.data th { position: sticky; top: 0; background: var(--surface-3); text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 9px 12px; white-space: nowrap; }
table.data td { padding: 8px 12px; border-top: 1px solid var(--border); }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:hover td { background: var(--surface-2); }
table.data tr.hl td { font-weight: 700; background: var(--accent-soft); }

details.steps { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
details.steps > summary { cursor: pointer; padding: 14px 18px; font-weight: 700; font-size: .95rem; list-style: none; display: flex; align-items: center; gap: 8px; }
details.steps > summary::-webkit-details-marker { display: none; }
details.steps > summary::before { content: "+"; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
details.steps[open] > summary::before { content: "\2212"; }
.steps-body { padding: 0 18px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.step { min-width: 0; }
.step { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; }
.step h4 { margin: 0 0 4px; font-size: .88rem; }
.formula { font-family: "Cambria Math", "Latin Modern Math", "STIX Two Math", Georgia, serif; font-size: 1.05rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px; overflow-x: auto; line-height: 1.7; }
.formula + .formula { margin-top: 6px; }
.sub-calc { font-family: var(--mono); font-size: .82rem; color: var(--muted); margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.note { font-size: .82rem; color: var(--muted); }
.ref { font-size: .78rem; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 10px; }

.zonebar { position: relative; height: 16px; border-radius: 8px; overflow: hidden; display: flex; margin: 0 0 10px; }
.zonebar div { height: 100%; }
.zonebar-wrap .mk { position: absolute; top: 0; transform: translateX(-50%); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.zonebar-wrap { position: relative; padding-top: 24px; }
.zonebar-pin { position: absolute; top: 18px; width: 4px; height: 28px; box-shadow: 0 0 0 2px var(--surface); background: var(--text); border-radius: 2px; transform: translateX(-50%); }
.zonebar-lbl { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .88rem; transition: .25s; z-index: 100; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.print-only { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .tool-body { grid-template-columns: 1fr; }
  .inputs { position: static; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; background: none; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  body.nav-open .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .icon-btn.menu-btn { display: inline-flex; }
  .content { padding: 18px 16px 50px; }
  .topbar { padding: 10px 16px; }
  .lab-badge .who { display: none; }
  .hero { padding: 24px 20px; }
  .hero h1 { font-size: 1.5rem; }
  .btn .lbl { display: none; }
}
@media (min-width: 861px) { .scrim { display: none !important; } }

/* ---------- Print ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --shadow: none; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .scrim, .tool-actions, .mini-btns, .reset-link, .toast, #home { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; max-width: none; }
  .tool-body { grid-template-columns: 1fr; gap: 12px; }
  .inputs { position: static; }
  .panel, .kpi, details.steps { box-shadow: none; }
  .panel, .kpi, .step { break-inside: avoid; }
  .tbl-scroll { max-height: none; overflow: visible; }
  details.steps > .steps-body { display: grid !important; }
  .print-only { display: block; }
  .chart-wrap canvas { display: none !important; }
  .chart-wrap { height: auto !important; }
  .chart-wrap img.print-img { display: block !important; width: 100%; }
  .field input, .field select, .field textarea { border: 1px solid #ccc; background: #fff; }
  .seg button:not(.on) { display: none; }
  .print-head { display: flex !important; justify-content: space-between; border-bottom: 2px solid #0e7c86; padding-bottom: 6px; margin-bottom: 12px; font-size: 11px; color: #555; }
  @page { margin: 14mm; }
}
.chart-wrap img.print-img { display: none; }
.print-head { display: none; }
