/* Indika Motors — Spare Parts Manager
   Palette: workshop navy, Ape-yellow action colour, cool paper. */
:root {
  --ink: #13294B;
  --ink-2: #1D3A66;
  --ink-3: #2B4F82;
  --paper: #EEF2F7;
  --surface: #FFFFFF;
  --line: #DCE3EC;
  --line-2: #C9D3E0;
  --text: #16202E;
  --muted: #5B6B80;
  --faint: #8A98AB;
  --amber: #F2A900;
  --amber-2: #FFC933;
  --amber-ink: #2E2200;
  --green: #16865A;
  --green-bg: #E4F4EC;
  --red: #C23B2F;
  --red-bg: #FBE9E7;
  --blue-bg: #E7EEF8;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgba(19, 41, 75, .06), 0 8px 24px -12px rgba(19, 41, 75, .18);
  --font: 'Manrope', 'Noto Sans Sinhala', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --side-w: 256px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
html[lang="si"] body { line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.num, td.n, .metric-v, .money { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- boot / login ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr);
}
.login-art {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-art::before {
  content: '';
  position: absolute;
  inset: auto -120px -160px auto;
  width: 520px; height: 520px;
  border-radius: 50%;
  border: 56px solid rgba(242, 169, 0, .9);
  opacity: .9;
}
.login-art::after {
  content: '';
  position: absolute;
  inset: auto 60px 40px auto;
  width: 180px; height: 180px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .25);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: -.01em; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand small { display: block; font-weight: 500; opacity: .7; font-size: 12px; letter-spacing: 0; }
.login-art h1 {
  position: relative;
  z-index: 1;
  font-size: clamp(34px, 4.4vw, 58px);
  line-height: 1.05;
  letter-spacing: -.03em;
  font-weight: 800;
  margin: 0 0 16px;
  max-width: 11ch;
}
html[lang="si"] .login-art h1 { line-height: 1.25; letter-spacing: 0; max-width: 14ch; }
.login-art p { position: relative; z-index: 1; margin: 0; max-width: 36ch; color: rgba(255, 255, 255, .78); font-size: 17px; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.02em; }
.login-card .sub { color: var(--muted); margin: 0 0 28px; }
.login-top { display: flex; justify-content: flex-end; margin-bottom: 40px; }
.form-error {
  background: var(--red-bg); color: var(--red);
  border-radius: var(--r-sm); padding: 10px 12px; font-size: 14px; margin-bottom: 16px;
}

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 28px 24px 36px; min-height: 260px; }
  .login-art::before { width: 300px; height: 300px; border-width: 34px; inset: auto -90px -130px auto; }
  .login-art::after { display: none; }
  .login-art h1 { font-size: 34px; margin-top: 40px; }
  .login-top { margin-bottom: 20px; }
}

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh;
  background: var(--ink);
  color: #fff;
  display: flex; flex-direction: column;
  padding: 22px 16px;
}
.side .brand { padding: 4px 8px 26px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  text-decoration: none;
  color: rgba(255, 255, 255, .72);
  font-weight: 600;
  font-size: 15px;
  transition: background .15s, color .15s;
}
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a[aria-current="page"] { background: var(--amber); color: var(--amber-ink); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.side-foot .who { font-size: 13px; color: rgba(255, 255, 255, .6); padding: 0 8px; }

.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: 18px 32px;
  background: rgba(238, 242, 247, .88);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[lang="si"] .topbar h1 { letter-spacing: 0; font-size: 22px; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }
.mobile-brand { display: none; }
.content { padding: 8px 32px 48px; max-width: 1400px; width: 100%; }

.bottom-nav { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar h1 { font-size: 20px; }
  html[lang="si"] .topbar h1 { font-size: 18px; }
  .content { padding: 4px 14px calc(96px + var(--safe-b)); }
  .topbar .actions .hide-m { display: none; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--ink);
    padding: 6px 6px calc(6px + var(--safe-b));
    box-shadow: 0 -8px 24px -12px rgba(19, 41, 75, .5);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    text-decoration: none; color: rgba(255, 255, 255, .65);
    font-size: 11px; font-weight: 600; padding: 7px 2px 5px; border-radius: 12px;
    line-height: 1.2; text-align: center;
  }
  html[lang="si"] .bottom-nav a { font-size: 10.5px; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--amber-ink); background: var(--amber); }
}

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--amber); color: var(--amber-ink);
  font-weight: 700; font-size: 14.5px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .05s;
  text-decoration: none;
}
.btn:hover { background: var(--amber-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: var(--ink-2); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line-2); }
.btn-ghost:hover { background: #F6F8FB; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #A93227; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; color: var(--text); flex: none;
}
.icon-btn:hover { background: #F6F8FB; }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.plain { border-color: transparent; background: transparent; }
.icon-btn.plain:hover { background: var(--blue-bg); }

.lang-toggle {
  display: inline-flex; padding: 3px; border-radius: 999px;
  background: rgba(19, 41, 75, .08);
}
.lang-toggle button {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--muted);
}
.lang-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(19, 41, 75, .18); }
.side .lang-toggle { background: rgba(255, 255, 255, .1); align-self: flex-start; }
.side .lang-toggle button { color: rgba(255, 255, 255, .7); }
.side .lang-toggle button[aria-pressed="true"] { background: #fff; color: var(--ink); }
.side .btn-ghost { background: transparent; color: rgba(255, 255, 255, .8); border-color: rgba(255, 255, 255, .2); }
.side .btn-ghost:hover { background: rgba(255, 255, 255, .08); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12.5px; color: var(--faint); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 70px; resize: vertical; }
.input:focus { outline: none; border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(43, 79, 130, .18); }
.input.invalid { border-color: var(--red); }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .seg { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); pointer-events: none; }
.input-icon .input { padding-left: 38px; }

.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 3px; gap: 2px; flex: none;
}
.seg button {
  border: 0; background: transparent; cursor: pointer; border-radius: 6px;
  padding: 6px 12px; font-weight: 700; font-size: 13.5px; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 14px; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.span-2 { grid-column: span 2; }
@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.panel-h h2 { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -.01em; }
.panel-b { padding: 12px 20px 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0 16px; }
.toolbar .grow { flex: 1 1 240px; min-width: 0; }
.toolbar select.input { width: auto; min-width: 160px; }
@media (max-width: 600px) {
  .toolbar select.input { flex: 1; min-width: 0; }
}

/* ---------- dashboard ---------- */
.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.hero {
  grid-column: span 12;
  background: var(--ink);
  color: #fff;
  border-radius: 22px;
  padding: 28px 30px 26px;
  position: relative;
  overflow: hidden;
}
.hero-top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.hero .shop { font-size: 13px; font-weight: 700; color: var(--amber); margin: 0 0 6px; }
.hero h2 { margin: 0; font-size: 28px; letter-spacing: -.02em; font-weight: 800; }
html[lang="si"] .hero h2 { letter-spacing: 0; font-size: 24px; }
.hero-total { text-align: right; }
.hero-total .v { font-size: clamp(26px, 3.4vw, 40px); font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.hero-total .l { font-size: 13px; color: rgba(255, 255, 255, .65); }
.flow { margin-top: 26px; }
.flow-bar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: rgba(255, 255, 255, .1); }
.flow-bar > div { height: 100%; }
.flow-bar .c { background: #7FA2D6; }
.flow-bar .p { background: var(--amber); }
.flow-legend { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-top: 14px; }
.flow-legend .k { display: flex; gap: 10px; align-items: flex-start; }
.flow-legend .dot { width: 10px; height: 10px; border-radius: 3px; margin-top: 6px; flex: none; }
.flow-legend .kv { font-weight: 800; font-size: 18px; }
.flow-legend .kl { font-size: 12.5px; color: rgba(255, 255, 255, .65); }
.flow-note { font-size: 12.5px; color: rgba(255, 255, 255, .55); margin-top: 12px; }
.units { margin-top: 22px; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, .12); display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.units .ul { font-size: 13px; color: rgba(255, 255, 255, .7); }
.units .ub { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.units .ub div { height: 100%; background: #6FD3A2; border-radius: 999px; }
.units .uv { font-weight: 700; font-size: 14px; }
@media (max-width: 600px) {
  .hero { padding: 22px 18px; border-radius: 18px; }
  .hero-total { text-align: left; }
  .units { grid-template-columns: 1fr auto; }
  .units .ul { grid-column: span 2; }
}

.metrics { grid-column: span 12; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.metric { padding: 18px 20px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric:nth-child(3n) { border-right: 0; }
.metric:nth-last-child(-n+3) { border-bottom: 0; }
.metric-l { font-size: 13px; color: var(--muted); font-weight: 600; }
.metric-v { font-size: 22px; font-weight: 800; letter-spacing: -.01em; margin-top: 2px; }
@media (max-width: 760px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(3n) { border-right: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n+3) { border-bottom: 1px solid var(--line); }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .metric { padding: 14px; }
  .metric-v { font-size: 17px; }
}

.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
@media (max-width: 1100px) { .col-4, .col-5, .col-7, .col-8 { grid-column: span 6; } }
@media (max-width: 760px) { .col-4, .col-5, .col-6, .col-7, .col-8 { grid-column: span 12; } }

.month-stats { display: grid; grid-template-columns: 1fr; gap: 14px; }
.ms { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.ms:last-child { border-bottom: 0; padding-bottom: 0; }
.ms .l { color: var(--muted); font-weight: 600; font-size: 14px; }
.ms .v { font-weight: 800; font-size: 20px; }

.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .cn { font-weight: 700; }
.cat-row .cv { font-weight: 700; font-variant-numeric: tabular-nums; }
.cat-row .cb { grid-column: span 2; height: 6px; background: var(--blue-bg); border-radius: 999px; overflow: hidden; }
.cat-row .cb div { height: 100%; background: var(--ink-3); border-radius: 999px; }
.cat-row .cm { grid-column: span 2; font-size: 12.5px; color: var(--muted); }

.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .t { flex: 1; min-width: 0; }
.list-row .t b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .t span { font-size: 12.5px; color: var(--muted); }
.list-row .r { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--blue-bg); color: var(--ink-2); white-space: nowrap;
}
.pill.warn { background: #FFF3D1; color: #7A5400; }
.pill.bad { background: var(--red-bg); color: var(--red); }
.pill.good { background: var(--green-bg); color: var(--green); }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }

/* ---------- data tables ---------- */
.table-wrap { overflow: auto; border-radius: var(--r-lg); max-height: calc(100dvh - 230px); }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
table.grid th {
  position: sticky; top: 0; z-index: 2;
  background: #F4F7FB; color: var(--muted);
  font-size: 12.5px; font-weight: 700; text-align: left;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
html[lang="si"] table.grid th { white-space: normal; min-width: 96px; line-height: 1.35; vertical-align: bottom; }
table.grid td { padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
table.grid tbody tr:hover td { background: #F8FAFD; }
table.grid td.n, table.grid th.n { text-align: right; }
table.grid td.name { white-space: normal; min-width: 220px; font-weight: 600; }
table.grid .sticky { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
table.grid th.sticky { z-index: 3; background: #F4F7FB; }
table.grid tbody tr:hover td.sticky { background: #F8FAFD; }
table.grid tfoot td {
  position: sticky; bottom: 0; background: #F4F7FB; font-weight: 800;
  border-top: 1px solid var(--line-2); border-bottom: 0;
}
table.grid tfoot td.sticky { z-index: 3; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .icon-btn { width: 34px; height: 34px; }

/* mobile cards replace tables */
.cards { display: none; }
@media (max-width: 760px) {
  .desktop-only { display: none !important; }
  .cards { display: flex; flex-direction: column; gap: 10px; }
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 14px 12px; box-shadow: var(--shadow);
}
.card-top { display: flex; gap: 10px; align-items: flex-start; }
.card-top .t { flex: 1; min-width: 0; }
.card-top .t b { font-weight: 700; display: block; line-height: 1.35; }
.card-top .t .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card-kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.card-kv div { background: #F5F8FB; border-radius: 10px; padding: 7px 9px; min-width: 0; }
.card-kv .k { font-size: 11px; color: var(--muted); font-weight: 600; line-height: 1.3; }
.card-kv .v { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.3; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions .btn { flex: 1; }
.card details summary { cursor: pointer; font-size: 13px; color: var(--ink-3); font-weight: 700; margin-top: 10px; list-style: none; }
.card details summary::-webkit-details-marker { display: none; }
.kv-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin-top: 10px; font-size: 13.5px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat .l { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .stat-strip { grid-template-columns: 1fr 1fr; } .stat .v { font-size: 16px; } }

/* period picker */
.period { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 13.5px; cursor: pointer; white-space: nowrap; flex: none;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.period-inputs { display: flex; gap: 10px; flex-wrap: wrap; }
.period-inputs .field { flex: 1 1 150px; max-width: 220px; }
.period-label { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(13, 26, 48, .5);
  display: grid; place-items: center; padding: 20px;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: 100%; max-width: 620px; max-height: calc(100dvh - 40px);
  background: var(--surface); border-radius: 20px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
  animation: pop .18s ease-out;
}
.dialog.sm { max-width: 420px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.dialog-h { display: flex; align-items: center; gap: 12px; padding: 18px 20px 12px; }
.dialog-h h3 { margin: 0; font-size: 19px; font-weight: 800; flex: 1; letter-spacing: -.01em; }
.dialog-b { padding: 6px 20px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #FAFBFD; }
@media (max-width: 600px) {
  .overlay { place-items: end stretch; padding: 0; }
  .dialog { max-width: none; border-radius: 22px 22px 0 0; max-height: 92dvh; animation: sheet .22s ease-out; }
  .dialog-f { padding-bottom: calc(14px + var(--safe-b)); }
  .dialog-f .btn { flex: 1; }
  @keyframes sheet { from { transform: translateY(40px); opacity: .4; } }
}

.calc {
  background: #F5F8FB; border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px;
}
.calc h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 700; }
.calc dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; margin: 0; font-size: 14px; }
.calc dt { color: var(--muted); }
.calc dd { margin: 0; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

/* combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(19, 41, 75, .35);
  max-height: 260px; overflow-y: auto; padding: 4px;
}
.combo-opt { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.combo-opt:hover, .combo-opt.active { background: var(--blue-bg); }
.combo-opt b { font-weight: 600; font-size: 14px; }
.combo-opt small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.combo-opt.disabled { opacity: .5; }

/* toast */
#toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (max-width: 900px) { #toast-root { bottom: calc(88px + var(--safe-b)); } }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .4);
  display: flex; gap: 10px; align-items: center; animation: pop .18s ease-out; max-width: 90vw;
}
.toast.err { background: var(--red); }
.toast svg { width: 18px; height: 18px; flex: none; }

/* ---------- reports ---------- */
.rep-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .rep-layout { grid-template-columns: 1fr; } }
.rep-types { display: grid; gap: 8px; }
.rep-type {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--surface); cursor: pointer; width: 100%;
}
.rep-type svg { width: 22px; height: 22px; flex: none; color: var(--ink-3); margin-top: 1px; }
.rep-type b { display: block; font-weight: 800; font-size: 14.5px; }
.rep-type span { font-size: 12.5px; color: var(--muted); }
.rep-type[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: #F6F9FD; }
.rep-type[aria-pressed="true"] svg { color: var(--amber); }
.rep-side { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1100px) { .rep-side { position: static; } .rep-types { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .rep-types { grid-template-columns: 1fr 1fr; } .rep-type { padding: 10px; gap: 8px; } .rep-type span { display: none; } .rep-type b { font-size: 13.5px; } }
.rep-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rep-actions .btn { flex: 1; }
.rep-stage { background: #D9E0EA; border-radius: var(--r-lg); padding: 20px; min-height: 420px; }
@media (max-width: 600px) { .rep-stage { padding: 10px; } }
.rep-scale { margin: 0 auto 16px; transform-origin: top left; }
.rep-scale:last-child { margin-bottom: 0; }
.rep-page-wrap { box-shadow: 0 10px 30px -12px rgba(19, 41, 75, .45); }
.rep-placeholder { display: grid; place-items: center; min-height: 380px; text-align: center; color: var(--muted); padding: 24px; }
.rep-placeholder svg { width: 44px; height: 44px; color: var(--faint); margin-bottom: 10px; }

/* A4 page (794 × 1123 CSS px) */
.rp-page {
  width: 794px; height: 1123px;
  background: #fff; color: #17202C;
  padding: 44px 46px 30px;
  display: flex; flex-direction: column;
  font-family: 'Manrope', 'Noto Sans Sinhala', sans-serif;
  font-size: 11px; line-height: 1.45;
  /* Sinhala conjuncts (ZWJ) must be shaped as whole words: any non-zero
     letter-spacing makes html2canvas draw glyph-by-glyph and breaks them. */
  letter-spacing: 0;
  position: relative; overflow: hidden;
}
.rp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 14px; border-bottom: 3px solid #13294B; }
.rp-head .shop { font-weight: 800; font-size: 13px; color: #13294B; }
.rp-head .title { font-size: 22px; font-weight: 800; margin-top: 4px; color: #13294B; line-height: 1.2; }
.rp-head .meta { text-align: right; font-size: 10.5px; color: #5B6B80; }
.rp-head .meta b { color: #17202C; display: block; font-size: 12px; }
.rp-head .mark { width: 6px; align-self: stretch; background: #F2A900; border-radius: 3px; flex: none; }
.rp-head .left { display: flex; gap: 12px; }
.rp-cont { display: flex; justify-content: space-between; font-size: 10.5px; color: #5B6B80; padding-bottom: 8px; border-bottom: 1px solid #DCE3EC; }
.rp-cont b { color: #13294B; }
.rp-body { flex: 1; overflow: hidden; padding-top: 16px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.rp-body > * { flex-shrink: 0; }
.rp-foot { display: flex; justify-content: space-between; font-size: 9.5px; color: #8A98AB; padding-top: 8px; border-top: 1px solid #DCE3EC; }
.rp-kpis { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #DCE3EC; border-radius: 8px; overflow: hidden; }
.rp-kpis.four { grid-template-columns: repeat(4, 1fr); }
.rp-kpi { padding: 9px 11px; border-right: 1px solid #DCE3EC; border-bottom: 1px solid #DCE3EC; }
.rp-kpi .l { font-size: 9.5px; color: #5B6B80; line-height: 1.3; }
.rp-kpi .v { font-size: 14px; font-weight: 800; color: #13294B; font-variant-numeric: tabular-nums; }
.rp-kpi.hl { background: #FFF6DB; }
.rp-h { font-size: 12.5px; font-weight: 800; color: #13294B; margin: 2px 0 0; }
.rp-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.rp-table th { background: #13294B; color: #fff; font-weight: 700; text-align: left; padding: 6px 6px; font-size: 9.5px; line-height: 1.3; vertical-align: bottom; }
.rp-table td { padding: 5px 6px; border-bottom: 1px solid #E6EBF2; vertical-align: top; }
.rp-table tr:nth-child(even) td { background: #F7F9FC; }
.rp-table .n { text-align: right; font-variant-numeric: tabular-nums; }
.rp-table td.n { white-space: nowrap; }
.rp-table td { overflow-wrap: break-word; }
.rp-table tr.total td { background: #FFF6DB; font-weight: 800; border-top: 2px solid #13294B; border-bottom: 0; }
.rp-note { font-size: 10px; color: #5B6B80; }
.rp-empty { padding: 30px; text-align: center; color: #8A98AB; border: 1px dashed #C9D3E0; border-radius: 8px; }

#print-root { display: none; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  #print-root .rp-page { page-break-after: always; break-after: page; }
  #print-root .rp-page:last-child { page-break-after: auto; break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* settings */
.settings { display: grid; gap: 16px; max-width: 760px; }
.set-row { display: grid; grid-template-columns: 1fr 240px; gap: 16px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row b { display: block; font-weight: 700; }
.set-row p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
@media (max-width: 600px) { .set-row { grid-template-columns: 1fr; gap: 10px; } }

/* topbar extras for phones */
.m-only { display: none; align-items: center; gap: 6px; }
@media (max-width: 900px) {
  .m-only { display: flex; }
  .m-only .lang-toggle button { padding: 5px 9px; font-size: 12px; }
}
@media (max-width: 600px) {
  .btn.collapse { width: 42px; padding: 0; }
  .btn.collapse .lbl { display: none; }
}
.panel.empty { padding: 44px 20px; }
a.cat-row:hover .cn { color: var(--ink-3); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

@media (max-width: 600px) {
  .toolbar .grow { flex-basis: 100%; }
}
