/* =====================================================================
 *  Smart Income Tax Calculator — styles
 *  Colours are tokens on :root; dark mode redefines them.
 * ===================================================================== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e3e8ef;
  --text: #0f1b2d;
  --muted: #5b6b80;
  --accent: #0a6e4f;          /* Bangladesh green */
  --accent-soft: #e5f3ee;
  --accent-ink: #ffffff;
  --red: #c8102e;              /* Bangladesh red */
  --red-soft: #fdecee;
  --amber: #a86400;
  --amber-soft: #fff4e0;
  --blue: #1f5fbf;
  --blue-soft: #e8f0fc;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 4px 16px rgba(15, 27, 45, .05);
  --radius: 14px;
  --band-0: #cbd5e1;
  --band-1: #4ade80;
  --band-2: #22c55e;
  --band-3: #eab308;
  --band-4: #f97316;
  --band-5: #ef4444;
  --band-6: #b91c1c;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #0e1626;
    --line: #22304a;
    --text: #e7edf6;
    --muted: #93a3ba;
    --accent: #34c38f;
    --accent-soft: #11342a;
    --accent-ink: #062016;
    --red: #ff6b7f;
    --red-soft: #3a1520;
    --amber: #f5b54a;
    --amber-soft: #36270d;
    --blue: #79a8ff;
    --blue-soft: #15264a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --band-0: #3b4a63;
          color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-2: #0e1626;
  --line: #22304a;
  --text: #e7edf6;
  --muted: #93a3ba;
  --accent: #34c38f;
  --accent-soft: #11342a;
  --accent-ink: #062016;
  --red: #ff6b7f;
  --red-soft: #3a1520;
  --amber: #f5b54a;
  --amber-soft: #36270d;
  --blue: #79a8ff;
  --blue-soft: #15264a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --band-0: #3b4a63;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Hind Siliguri', 'Noto Sans Bengali', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.num, input[type=number], td.r, th.r { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: var(--accent); display: grid; place-items: center;
}
.brand-mark span { width: 15px; height: 15px; border-radius: 50%; background: var(--red); display: block; }
.brand h1 { font-size: 17px; margin: 0; line-height: 1.2; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.tab {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tools { display: flex; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 38px; padding: 8px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 40px; }
.view[hidden] { display: none !important; }
.grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0;
}
.card > h2, .card-head h2 { font-size: 16px; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card > h2 { margin-bottom: 12px; }
.step {
  width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700;
}
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

/* ---------- Form ---------- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label, .field .label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; min-height: 1em; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }
input[type=number], input[type=text], select {
  width: 100%; font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; min-width: 0;
}
input[type=number]:focus, input[type=text]:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money { position: relative; }
.money::before { content: '৳'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.money input { padding-left: 26px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); color: var(--muted); font: inherit; font-size: 13.5px; padding: 7px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
details.more { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--accent); }

/* ---------- Result: hero ---------- */
.hero { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1100px) { .hero { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; line-height: 1.25; margin-top: 2px; word-break: break-word; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stat.primary .k, .stat.primary .s { color: inherit; opacity: .85; }

.flow { list-style: none; padding: 0; margin: 0; }
.flow li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.flow li:last-child { border-bottom: 0; }
.flow li .lbl { color: var(--muted); }
.flow li .lbl small { display: block; font-size: 12px; }
.flow li.minus .val { color: var(--red); }
.flow li.total { font-weight: 700; font-size: 15.5px; border-top: 2px solid var(--line); border-bottom: 0; margin-top: 4px; padding-top: 10px; }
.flow li.total .lbl { color: var(--text); }
.val { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Callouts ---------- */
.note { border-radius: 12px; padding: 11px 13px; font-size: 13.5px; margin: 10px 0 0; border: 1px solid transparent; }
.note.good { background: var(--accent-soft); color: var(--text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.note.warn { background: var(--amber-soft); color: var(--text); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.note.info { background: var(--blue-soft); color: var(--text); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.note.bad { background: var(--red-soft); color: var(--text); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.note strong { font-weight: 700; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); vertical-align: middle; }
.badge.green { background: var(--accent-soft); color: var(--accent); }

/* ---------- Slab bar ---------- */
.bandbar { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); margin: 6px 0 10px; }
.bandbar span { display: block; height: 100%; min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line); border-bottom: 0; }
tr.inactive td { color: var(--muted); }
tr.active-band td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.rate-pill { display: inline-block; min-width: 46px; text-align: center; padding: 1px 8px; border-radius: 999px; font-weight: 700; font-size: 12.5px; color: #111; }

/* ---------- Guide ---------- */
.guide { max-width: 980px; margin: 0 auto; }
.guide-hero { background: var(--accent); color: var(--accent-ink); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.guide-hero h2 { margin: 0 0 4px; font-size: 21px; }
.guide-hero p { margin: 0; opacity: .9; }
.guide-hero .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.guide-hero .chip { background: rgba(255,255,255,.16); border-radius: 999px; padding: 3px 12px; font-size: 13px; }
.guide h3 { font-size: 16px; margin: 0 0 10px; }
.guide p, .guide li { font-size: 14.5px; }
.guide ul { padding-left: 20px; margin: 6px 0; }
.formula { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.slab-edit td { padding: 6px 8px; }
.slab-edit input { padding: 7px 9px; font-size: 14px; }
.slab-edit .w-rate { width: 90px; }

/* ---------- History ---------- */
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.history-item:last-child { border-bottom: 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  transition: opacity .25s, transform .25s; z-index: 50; pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { max-width: 1240px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: 12.5px; }
footer p { margin: 4px 0; }

/* ---------- Mobile ---------- */
@media (max-width: 700px) {
  .topbar-inner { gap: 8px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; padding: 6px 4px; font-size: 13px; }
  .brand p { display: none; }
  .stat .v { font-size: 19px; }
}

/* ---------- Report sheet (paper) ---------- */
.report-grid { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); }
@media (max-width: 980px) { .report-grid { grid-template-columns: minmax(0, 1fr); } }
.paper-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.paper {
  background: #fff; color: #111; min-width: 640px; padding: 32px 36px;
  font-family: Tahoma, Verdana, 'Hind Siliguri', sans-serif; font-size: 12.5px; line-height: 1.45;
}
.paper * { color: #111; }
.paper .ttl { text-align: center; font-weight: 700; margin-bottom: 18px; }
.paper .ttl div:first-child { font-size: 14px; }
.paper .meta { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.paper .meta table td { padding: 0 12px 0 0; border: 0; white-space: nowrap; }
.paper .meta table td:first-child { font-weight: 700; }
.paper .ay { font-weight: 700; text-decoration: underline; white-space: nowrap; }
.paper table, .paper table.coi { font-size: inherit; }
.paper table.coi { width: 100%; border-collapse: collapse; }
.paper table.coi td { padding: 3px 6px; border: 0; white-space: nowrap; background: none; }
.paper table.coi td.n { text-align: right; font-variant-numeric: tabular-nums; }
.paper table.coi td.lbl { white-space: normal; }
.paper .hd td { font-weight: 700; text-decoration: underline; text-align: right; }
.paper .b td { font-weight: 700; }
.paper .gap td { height: 10px; }
.paper .ul { border-bottom: 1px solid #111 !important; }
.paper .dul { border-bottom: 3px double #111 !important; }
.paper .ol { border-top: 1px solid #111 !important; }
.paper .box { border: 1px solid #111 !important; }
.paper .sect { font-weight: 700; text-decoration: underline; }
.paper .red, .paper .red * { color: #c00000; font-weight: 700; }
.paper .notes { margin-top: 18px; }
.paper .notes ol { margin: 2px 0 0; padding-left: 18px; }

/* ---------- Print ---------- */
@media print {
  .topbar, .no-print, footer .no-print, #toast { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .grid { grid-template-columns: 1fr; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  .inputs-col { display: none; }
  .view[hidden] { display: none !important; }
  .paper-wrap { box-shadow: none; border: 0; overflow: visible; }
  .paper { min-width: 0; padding: 0; font-size: 10.5px; line-height: 1.3; }
  .paper table.coi td { padding: 0 6px; }
  .paper .gap td { height: 3px; }
  .paper .ttl { margin-bottom: 10px; }
  .paper .meta { margin-bottom: 8px; }
  .paper .notes { margin-top: 10px; }
  #view-report:not([hidden]) ~ * , body:has(#view-report:not([hidden])) footer { display: none !important; }
  @page { size: A4; margin: 12mm; }
}
@media (max-width: 520px) { .hide-sm { display: none; } }
