:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5d6570;
  --border: #e2ddd3;
  --accent: #b4461d;
  --accent-soft: #fbeee7;
  --old: #9aa3ad;
  --new: #c2551f;
  --up: #1d7a46;
  --up-soft: #e6f4ec;
  --down: #b42318;
  --notice-bg: #fff6d9;
  --notice-border: #e6c34a;
  --whatsapp: #1f8f4e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e8e6e3;
    --muted: #a0a7b0;
    --border: #33373d;
    --accent: #f08a57;
    --accent-soft: #3a261c;
    --old: #6c7580;
    --new: #e2753f;
    --up: #4cc584;
    --up-soft: #173325;
    --down: #ff7a6e;
    --notice-bg: #332d14;
    --notice-border: #8a7424;
    --whatsapp: #2aa862;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Gujarati", "Shruti", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.55;
  font-size: 16px;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

.hero {
  background: linear-gradient(135deg, #8f3514, #c2551f 60%, #d98a2b);
  color: #fff;
  padding: 36px 0 32px;
}
.hero h1 { margin: 4px 0 8px; font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.3; }
.eyebrow { margin: 0; opacity: .85; font-size: .9rem; letter-spacing: .04em; text-transform: uppercase; }
.tagline { margin: 0; max-width: 60ch; opacity: .95; }

.notice {
  margin: 20px 0;
  padding: 12px 16px;
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  border-radius: var(--radius);
  font-size: .95rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 1.15rem; }

#calc-form { position: sticky; top: 16px; }
@media (max-width: 860px) { #calc-form { position: static; } }

.field { margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field.nested { margin-top: 12px; }
label, legend { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
legend { padding: 0; }

input[type="number"], select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .chip:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
}
.chip input { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip.small { font-size: .82rem; padding: 5px 10px; font-weight: 500; }
.chip.small:hover { border-color: var(--accent); }

.examples { margin-bottom: 16px; }
.examples .muted { display: block; margin-bottom: 6px; font-size: .88rem; }

.custom-fitment { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.custom-fitment label { margin: 0; font-weight: 400; white-space: nowrap; }
.custom-fitment input { max-width: 130px; }

.advanced { border-top: 1px solid var(--border); padding-top: 12px; }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-2 label { font-size: .85rem; font-weight: 500; }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } }

.hint, .muted { color: var(--muted); font-size: .85rem; }
.hint { margin: 6px 0 0; }
.error { color: var(--down); font-size: .85rem; margin: 6px 0 0; }

.results.empty .card:not(.highlight) { opacity: .4; pointer-events: none; }

.highlight { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 600px) { .stats { grid-template-columns: 1fr; } }
.stat {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: .88rem; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .82rem; color: var(--muted); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .93rem; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
tr.total td { font-weight: 700; }
tr.selected td { background: var(--accent-soft); font-weight: 700; }
td.up { color: var(--up); }
td.down { color: var(--down); }

.chart-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; margin-bottom: 14px; }
.chart-label { font-weight: 600; font-size: .9rem; }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar {
  height: 24px;
  border-radius: 6px;
  min-width: 2px;
  display: flex;
  align-items: center;
  transition: width .3s ease;
  position: relative;
}
.bar span { font-size: .8rem; font-weight: 600; padding-left: 8px; white-space: nowrap; color: #fff; }
.bar.old { background: var(--old); }
.bar.new { background: var(--new); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: .85rem; color: var(--muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch.old { background: var(--old); }
.swatch.new { background: var(--new); }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--accent); }
.btn:hover { filter: brightness(1.05); }

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, filter .12s ease;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.icon-btn.whatsapp { background: var(--whatsapp); border-color: var(--whatsapp); }
.icon-btn.copy { background: transparent; color: var(--accent); }
.icon-btn .i-done { display: none; }
.icon-btn.copied { background: var(--up); border-color: var(--up); color: #fff; }
.icon-btn.copied .i-copy { display: none; }
.icon-btn.copied .i-done { display: block; }

.icon-btn.busy { position: relative; cursor: progress; }
.icon-btn.busy svg { visibility: hidden; }
.icon-btn.busy::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Floating action buttons (right edge, vertical middle) ---------- */
:root { --fab-size: 52px; --fab-gap: 16px; --fab-gutter: calc(var(--fab-size) + var(--fab-gap) * 2); }
.fab {
  position: fixed;
  right: var(--fab-gap);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 50;
}
.fab .icon-btn {
  width: var(--fab-size);
  height: var(--fab-size);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.fab .icon-btn.copy { background: var(--surface); }
.fab .icon-btn.copy.copied { background: var(--up); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }
.icon-btn.busy:disabled { opacity: 1; cursor: progress; }
.fab-status {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  width: max-content;
  max-width: min(260px, calc(100vw - var(--fab-gutter) - 16px));
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: .88rem;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}
.fab-status.show { opacity: 1; visibility: visible; }
.fab-status a { color: #6fdc9d; font-weight: 700; }

/* Keep page content clear of the floating buttons. */
@media (max-width: 1300px) {
  .wrap { padding-right: var(--fab-gutter); }
}
@media (max-width: 600px) {
  :root { --fab-size: 42px; --fab-gap: 8px; }
  .fab { gap: 10px; }
  .fab .icon-btn svg { width: 20px; height: 20px; }
}

/* ---------- PDF report (rendered off-screen, fixed light colours) ---------- */
.pdf-report {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 794px;
  padding: 8px 4px;
  background: #fff;
  color: #1f2328;
  font-family: "Noto Sans Gujarati", "Shruti", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}
.pdf-report h1 { font-size: 21px; margin: 0; color: #8f3514; line-height: 1.3; }
.pdf-report h2 { font-size: 15px; margin: 0 0 8px; color: #8f3514; padding-bottom: 4px; border-bottom: 1px solid #f0d9cc; }
.pdf-report h3 { font-size: 13.5px; margin: 14px 0 6px; }
.rp-section { margin-top: 18px; }
.rp-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: linear-gradient(135deg, #8f3514, #c2551f 60%, #d98a2b);
  color: #fff;
}
.rp-head h1 { color: #fff; }
.rp-eyebrow { margin: 0; font-size: 12px; opacity: .9; }
.rp-meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; white-space: nowrap; }
.rp-note { margin-top: 10px; padding: 6px 10px; background: #fff6d9; border: 1px solid #e6c34a; border-radius: 6px; font-size: 12px; }
.rp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.rp-kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid #e2ddd3; }
.rp-kv span { color: #5d6570; }
.rp-kv strong { text-align: right; }
.rp-period { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid #e2ddd3; }
.rp-period span { color: #5d6570; }
.rp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.rp-stat { background: #fbeee7; border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; }
.rp-stat span { color: #5d6570; font-size: 12px; }
.rp-stat strong { font-size: 20px; color: #b4461d; }
.rp-stat small { color: #5d6570; font-size: 11px; }
.rp-stat.accent { background: #b4461d; }
.rp-stat.accent span, .rp-stat.accent small { color: rgba(255, 255, 255, .88); }
.rp-stat.accent strong { color: #fff; }
.rp-stat.green { background: #e6f4ec; }
.rp-stat.green strong { color: #1d7a46; }
.rp-chart .chart-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.rp-chart .chart-label { font-weight: 600; font-size: 12.5px; }
.rp-chart .bars { display: flex; flex-direction: column; gap: 3px; }
.rp-chart .bar { height: 20px; border-radius: 5px; display: flex; align-items: center; transition: none; }
.rp-chart .bar span { color: #fff; font-size: 11px; font-weight: 600; padding-left: 6px; white-space: nowrap; }
.rp-chart .bar.old, .rp-legend .old { background: #9aa3ad; }
.rp-chart .bar.new, .rp-legend .new { background: #c2551f; }
.rp-legend { display: flex; gap: 16px; font-size: 11.5px; color: #5d6570; }
.rp-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.rp-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 6px; }
.rp-table th, .rp-table td { padding: 5px 8px; border-bottom: 1px solid #e2ddd3; text-align: right; white-space: nowrap; }
.rp-table th:first-child, .rp-table td:first-child { text-align: left; }
.rp-table th { color: #5d6570; font-weight: 600; background: #f6f4ef; }
.rp-table tr.total td, .rp-table tfoot td { font-weight: 700; }
.rp-table tfoot td { background: #fbeee7; }
.rp-table tr.selected td { background: #fbeee7; font-weight: 700; }
.rp-table .up { color: #1d7a46; }
.rp-table .down { color: #b42318; }
.rp-table .month-name { font-weight: 600; }
.rp-table .month-note { display: inline; color: #5d6570; font-size: 11px; margin-left: 6px; }
.rp-disclaimer { margin-top: 16px; padding: 8px 10px; background: #fff6d9; border: 1px solid #e6c34a; border-radius: 6px; font-size: 11.5px; }

.info ul { padding-left: 20px; margin: 0 0 12px; }
.info li { margin-bottom: 6px; }

.footer { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }
.footer p { margin: 6px 0; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 8px; }
.footer-nav a { color: var(--accent); font-weight: 600; text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; }

.info h3 { font-size: 1rem; margin: 16px 0 8px; }
.faq h2 { margin-bottom: 8px; }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 1.3rem; font-weight: 600; color: var(--accent); flex-shrink: 0; }
.faq-item[open] summary::after { content: "−"; }
.faq-item summary h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.faq-item p { margin: 0 0 14px; color: var(--text); }
#faq { scroll-margin-top: 16px; }

/* ---------- Header navigation ---------- */
.hero-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.hero-nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: .92rem;
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 999px;
}
.hero-nav a:hover { background: rgba(255, 255, 255, .15); }
html { scroll-behavior: smooth; }
#results, #arrears { scroll-margin-top: 16px; }

/* ---------- Arrears calculator ---------- */
.arrears { border-color: var(--accent); }
.arrears h3 { font-size: 1rem; margin: 24px 0 10px; }
.section-title { font-size: 1.3rem !important; }

.arrears-inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 16px;
  margin-top: 16px;
}
@media (max-width: 860px) { .arrears-inputs { grid-template-columns: minmax(0, 1fr); } }

input[type="date"] {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 0;
}
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.small-btn { padding: 8px 12px; font-size: .85rem; white-space: nowrap; }

.arrears-error {
  background: var(--accent-soft);
  border: 1px solid var(--down);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .95rem;
}

.arrears-hero {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 8px 0 16px;
}
@media (max-width: 600px) { .arrears-hero { grid-template-columns: minmax(0, 1fr); } }
.stat.big { padding: 18px; }
.stat.big .stat-value { font-size: 2rem; }
.stat.big.accent { background: var(--accent); }
.stat.big.accent .stat-label, .stat.big.accent .stat-sub { color: rgba(255, 255, 255, .85); }
.stat.big.accent .stat-value { color: #fff; }
.stat.big.green { background: var(--up-soft); }
.stat.big.green .stat-value { color: var(--up); }

.arrears-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 24px;
  margin: 0;
}
@media (max-width: 600px) { .arrears-summary { grid-template-columns: minmax(0, 1fr); } }
.arrears-summary div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.arrears-summary dt { color: var(--muted); font-size: .9rem; }
.arrears-summary dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.arrears-summary .period { grid-column: 1 / -1; flex-direction: column; gap: 2px; }
.arrears-summary .period dd { text-align: left; font-weight: 600; }
@media (max-width: 600px) {
  .breakdown th, .breakdown td { white-space: normal; padding: 8px 6px; }
  .breakdown td:not(:first-child) { white-space: nowrap; }
}

.arrears-table .month-name { display: block; font-weight: 600; }
.month-note { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }
.arrears-table tr.skipped td { color: var(--muted); }
.arrears-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

@media (max-width: 600px) {
  .arrears-table thead { display: none; }
  .arrears-table, .arrears-table tbody, .arrears-table tfoot, .arrears-table tr, .arrears-table td { display: block; width: 100%; }
  .arrears-table tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; }
  .arrears-table tfoot tr { background: var(--accent-soft); }
  .arrears-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 5px 0;
    white-space: normal;
    text-align: right;
  }
  .arrears-table td::before { content: attr(data-label); color: var(--muted); font-weight: 400; text-align: left; font-size: .85rem; }
  .arrears-table td:first-child { border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 4px; }
  .arrears-table td:first-child::before { display: none; }
  .arrears-table td:first-child { flex-direction: column; text-align: left; gap: 0; }
  .arrears-table tfoot td { border-top: 0; }
}

.formula {
  margin-top: 24px;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: 12px;
  font-size: .93rem;
}
.formula h3 { margin-top: 0 !important; }
.formula ul { padding-left: 20px; margin: 8px 0 0; }
.formula li { margin-bottom: 6px; }
.disclaimer { margin-bottom: 0; }

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --shadow: none; }
  .hero { background: none; color: #000; padding: 0 0 8px; }
  #calc-form, .fab, .advanced, .hero-nav, #arrears-today { display: none !important; }
  .wrap { padding-right: 0; }
  .arrears { break-before: page; }
  .stat.big.accent { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .layout { grid-template-columns: 1fr; }
  .card { break-inside: avoid; border-color: #ccc; }
  .bar, .swatch, .stat, tr.selected td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
