/* ==========================================================
   Purbokone Circulation — stylesheet
   Identity: press ink + newsprint; CMYK colour bar reserved
   for the "today's run" panel only.
   ========================================================== */
:root {
  --ink: #14233C;
  --ink-2: #22375A;
  --ink-3: #3A5073;
  --paper: #F3F5F6;
  --sheet: #FFFFFF;
  --plate: #E3E8EC;
  --rule: #CDD5DC;
  --muted: #5A697C;
  --action: #0A7EA8;
  --action-ink: #075E7E;
  --due: #B01E57;
  --paid: #1D7A4E;
  --warn: #B7791F;
  --c: #00A0DC; --m: #D6246E; --y: #F2C200; --k: #14233C;

  --font: "Anek Bangla", "Noto Sans Bengali", "Hind Siliguri", system-ui, sans-serif;
  --r-sm: 4px;
  --r: 8px;
  --side: 248px;
  --top: 56px;
  --shadow-pop: 0 12px 32px rgba(20, 35, 60, .18);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.55;
  color: var(--ink); background: var(--paper);
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--action-ink); }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Headline type: condensed, like a newspaper deck ---------- */
.hl { font-stretch: 75%; font-variation-settings: "wdth" 75; font-weight: 700; letter-spacing: -.005em; line-height: 1.1; }
h1.page-title { margin: 0; font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem); }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; font-weight: 650; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.due { color: var(--due); }
.paid { color: var(--paid); }

/* ---------- Boot + registration mark ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.reg-mark {
  width: 44px; height: 44px; border-radius: 50%; border: 2.5px solid var(--ink); position: relative; display: inline-block;
  animation: spin 1.4s linear infinite;
}
.reg-mark::before, .reg-mark::after { content: ""; position: absolute; background: var(--ink); }
.reg-mark::before { left: 50%; top: -8px; bottom: -8px; width: 2.5px; transform: translateX(-50%); }
.reg-mark::after { top: 50%; left: -8px; right: -8px; height: 2.5px; transform: translateY(-50%); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Colour bar (signature) ---------- */
.colorbar { display: flex; height: 6px; }
.colorbar i { flex: 1; }
.colorbar i:nth-child(1) { background: var(--c); }
.colorbar i:nth-child(2) { background: var(--m); }
.colorbar i:nth-child(3) { background: var(--y); }
.colorbar i:nth-child(4) { background: var(--k); }
.colorbar i:nth-child(5) { background: color-mix(in srgb, var(--c) 50%, white); }
.colorbar i:nth-child(6) { background: color-mix(in srgb, var(--m) 50%, white); }
.colorbar i:nth-child(7) { background: color-mix(in srgb, var(--y) 50%, white); }
.colorbar i:nth-child(8) { background: color-mix(in srgb, var(--k) 50%, white); }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--side) 1fr; }
.side {
  background: var(--ink); color: #DCE4EE; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 1.15rem; line-height: 1.1; }
.brand small { display: block; font-size: .78rem; color: #9FB0C6; }
.nav { padding: .25rem .6rem 1rem; flex: 1; }
.nav-group { margin: 1rem .5rem .3rem; font-size: .8rem; color: #8FA2BB; }
.nav a {
  display: flex; align-items: center; gap: .75rem; padding: .55rem .7rem; border-radius: var(--r-sm);
  color: #DCE4EE; text-decoration: none; font-size: .98rem;
}
.nav a i { width: 1.2rem; text-align: center; color: #8FA2BB; }
.nav a:hover { background: var(--ink-2); }
.nav a[aria-current="page"] { background: #fff; color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"] i { color: var(--action); }
.side-foot { padding: .9rem 1.1rem; border-top: 1px solid var(--ink-2); font-size: .85rem; color: #9FB0C6; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--top); display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
  background: var(--sheet); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 1.5rem; max-width: 1320px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-head p { margin: .25rem 0 0; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 40px; padding: .45rem .95rem;
  border: 1px solid var(--rule); background: var(--sheet); color: var(--ink); border-radius: var(--r-sm);
  cursor: pointer; text-decoration: none; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--action); border-color: var(--action); color: #fff; }
.btn.primary:hover { background: var(--action-ink); }
.btn.danger { color: var(--due); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: .2rem .6rem; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 40px; padding: 0; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-sm); overflow: hidden; background: var(--sheet); }
.seg button { border: 0; background: transparent; padding: .4rem .8rem; cursor: pointer; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .92rem; font-weight: 550; }
.field > small { color: var(--muted); font-size: .82rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: .5rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--sheet);
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: 2px solid var(--action); outline-offset: 0; border-color: var(--action); }
.field.has-error .input { border-color: var(--due); }
.field .err { color: var(--due); font-size: .85rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; margin-top: .5rem; padding-top: .9rem; border-top: 1px solid var(--plate); font-weight: 650; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--action); }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar .input { width: auto; min-width: 180px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 2.2rem; width: 100%; }

/* ---------- Panels & tables ---------- */
.panel { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r); }
.panel-pad { padding: 1.1rem 1.25rem; }
.panel-head { display: flex; align-items: center; gap: .75rem; padding: .9rem 1.25rem; border-bottom: 1px solid var(--plate); }
.panel-head h2 { margin: 0; flex: 1; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th {
  text-align: left; font-weight: 600; font-size: .85rem; color: var(--muted); padding: .6rem .9rem;
  border-bottom: 1px solid var(--rule); background: #F8FAFB; position: sticky; top: 0; white-space: nowrap;
}
table.data td { padding: .6rem .9rem; border-bottom: 1px solid var(--plate); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data .r { text-align: right; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: #F4F8FA; }
table.data tfoot td { font-weight: 650; border-top: 2px solid var(--ink); border-bottom: 0; }
tr.inactive td { color: var(--muted); }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .78rem; border: 1px solid currentColor; white-space: nowrap; }
.pill.agent { color: var(--action-ink); }
.pill.depot { color: var(--ink-3); }
.pill.bookpost, .pill.other { color: var(--warn); }
.pill.off { color: var(--muted); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty i { font-size: 1.6rem; display: block; margin-bottom: .5rem; }

/* ---------- Dashboard ---------- */
.dash { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1.25rem; }
.run { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; grid-column: 1 / -1; }
.run-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1.5rem; padding: 1.4rem 1.5rem 1.5rem; }
.run-date { font-size: .95rem; color: var(--muted); }
.run-big { font-size: clamp(3.2rem, 2rem + 4.5vw, 5.4rem); margin: .1rem 0 .1rem; }
.run-big small { font-size: 1.1rem; font-weight: 500; color: var(--muted); margin-left: .4rem; font-stretch: 100%; font-variation-settings: "wdth" 100; }
.run-meta { display: flex; flex-wrap: wrap; gap: .35rem 1.2rem; color: var(--muted); font-size: .92rem; }
.run-split { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--plate); }
.run-split div { padding: .85rem 1.1rem; border-right: 1px solid var(--plate); }
.run-split div:last-child { border-right: 0; }
.run-split b { display: block; font-size: 1.45rem; }
.run-split span { font-size: .85rem; color: var(--muted); }
.chart { width: 100%; height: 190px; display: block; }
.chart .bar-i { fill: var(--ink); }
.chart .bar-r { fill: var(--m); }
.chart .axis { stroke: var(--rule); }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin-top: .4rem; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: .35rem; vertical-align: middle; }
.figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.figures > div { padding: 1rem 1.25rem; border-bottom: 1px solid var(--plate); }
.figures > div:nth-child(odd) { border-right: 1px solid var(--plate); }
.figures b { display: block; font-size: clamp(1.1rem, .9rem + 1vw, 1.5rem); overflow-wrap: anywhere; }
.figures span { color: var(--muted); font-size: .88rem; }
.dues-list { list-style: none; margin: 0; padding: 0; }
.dues-list li { display: flex; gap: .75rem; align-items: baseline; padding: .6rem 1.25rem; border-bottom: 1px solid var(--plate); }
.dues-list li:last-child { border-bottom: 0; }
.dues-list a { flex: 1; min-width: 0; text-decoration: none; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dues-list a:hover { text-decoration: underline; }
.notice { display: flex; gap: .75rem; align-items: flex-start; padding: .8rem 1rem; border-left: 4px solid var(--warn); background: #FFF8E6; border-radius: var(--r-sm); margin-bottom: 1rem; }

/* ---------- Statement ---------- */
.stmt-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--plate); }
.stmt-head div { padding: .9rem 1.25rem; border-right: 1px solid var(--plate); }
.stmt-head div:last-child { border-right: 0; }
.stmt-head b { display: block; font-size: 1.3rem; }
.stmt-head span { font-size: .85rem; color: var(--muted); }
.print-only { display: none; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 35, 60, .45); z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal {
  background: var(--sheet); border-radius: var(--r); width: min(760px, 100%); max-height: calc(100vh - 2rem);
  display: flex; flex-direction: column; box-shadow: var(--shadow-pop);
}
.modal.narrow { width: min(460px, 100%); }
.modal-head { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--plate); }
.modal-head h2 { margin: 0; flex: 1; font-size: 1.25rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: .9rem 1.25rem; border-top: 1px solid var(--plate); }
.secret { font-size: 1.4rem; letter-spacing: .05em; padding: .6rem .9rem; background: var(--paper); border: 1px dashed var(--ink-3); border-radius: var(--r-sm); text-align: center; user-select: all; font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: var(--r-sm); box-shadow: var(--shadow-pop); max-width: 360px; animation: pop .18s ease-out; }
.toast.error { background: var(--due); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 480px); }
.login-art { background: var(--ink); color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: 3rem; position: relative; overflow: hidden; }
.login-art .colorbar { position: absolute; top: 0; left: 0; right: 0; }
.login-art h1 { font-size: clamp(2.4rem, 1.5rem + 3vw, 4rem); margin: 0 0 .5rem; }
.login-art p { color: #B8C6D8; max-width: 38ch; margin: 0; }
.login-art .reg { position: absolute; right: -60px; top: 12%; width: 320px; height: 320px; border-radius: 50%; border: 2px solid var(--ink-3); }
.login-art .reg::before, .login-art .reg::after { content: ""; position: absolute; background: var(--ink-3); }
.login-art .reg::before { left: 50%; top: -40px; bottom: -40px; width: 2px; }
.login-art .reg::after { top: 50%; left: -40px; right: -40px; height: 2px; }
.login-form { background: var(--sheet); display: flex; flex-direction: column; justify-content: center; padding: 3rem 2.5rem; gap: 1rem; }
.login-form h2 { font-size: 1.6rem; margin: 0; }
.login-form .btn { width: 100%; min-height: 46px; }
.login-lang { align-self: flex-end; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .dash { grid-template-columns: 1fr; }
  .run-body { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(290px, 85vw); z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .shell.nav-open .side { transform: none; box-shadow: var(--shadow-pop); }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(20, 35, 60, .4); z-index: 30; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 .75rem; }
  .content { padding: 1rem .85rem calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: var(--sheet); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .5rem 0 .45rem; font-size: .75rem; color: var(--muted); text-decoration: none; border: 0; background: none; }
  .bottom-nav i { font-size: 1.15rem; }
  .bottom-nav [aria-current="page"] { color: var(--action-ink); font-weight: 600; }
  .form-grid { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-art { min-height: 200px; padding: 2rem 1.5rem; }
  .login-art .reg { width: 200px; height: 200px; right: -40px; top: 20px; }
  .login-form { padding: 2rem 1.5rem; }
  .run-split { grid-template-columns: repeat(2, 1fr); }
  .run-split div:nth-child(2) { border-right: 0; }
  .run-split div:nth-child(-n+2) { border-bottom: 1px solid var(--plate); }
  .stmt-head { grid-template-columns: repeat(2, 1fr); }
  .stmt-head div:nth-child(2) { border-right: 0; }
  .stmt-head div:nth-child(-n+2) { border-bottom: 1px solid var(--plate); }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 92vh; border-radius: var(--r) var(--r) 0 0; }
  .toolbar .input, .search { max-width: none; width: 100%; }
  #toasts { left: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* Tables become stacked rows */
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; padding: .7rem .9rem; border-bottom: 1px solid var(--plate); }
  table.data.stack td { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; border: 0; }
  table.data.stack td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
  table.data.stack td.lead { font-weight: 600; font-size: 1.02rem; }
  table.data.stack td.lead::before { content: none; }
  table.data.stack td.r { text-align: right; }
  table.data.stack td:empty { display: none; }
  table.data.stack tfoot tr { border-top: 2px solid var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .side, .topbar, .bottom-nav, .toolbar, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .panel { border: 0; }
  .print-only { display: block; }
  table.data th { position: static; background: none; }
  table.data td, table.data th { padding: .25rem .4rem; }
  tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
