:root {
  --brand: #0f5257;
  --brand-2: #14787f;
  --brand-ink: #ffffff;
  --accent: #f2a541;
  --bg: #f4f6f6;
  --card: #ffffff;
  --ink: #142023;
  --muted: #5d6b6e;
  --line: #dfe5e6;
  --green: #1d8a4e;
  --green-bg: #e3f4ea;
  --red: #c0392b;
  --red-bg: #fbe9e7;
  --amber: #a86400;
  --amber-bg: #fdf1dc;
  --blue: #1f5fa8;
  --blue-bg: #e5eefa;
  --grey-bg: #eceff0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #3fb3b9; --brand-2: #5cc7cc; --brand-ink: #062628;
    --bg: #0f1516; --card: #182122; --ink: #e6eeee; --muted: #93a3a5; --line: #2a3537;
    --green-bg: #12301f; --red-bg: #3a1714; --amber-bg: #3a2a0f; --blue-bg: #13263b; --grey-bg: #222c2d;
    --green: #5fd08f; --red: #ff8a7a; --amber: #f2b45c; --blue: #7db3f0;
  }
}
:root[data-theme="dark"] {
  --brand: #3fb3b9; --brand-2: #5cc7cc; --brand-ink: #062628;
  --bg: #0f1516; --card: #182122; --ink: #e6eeee; --muted: #93a3a5; --line: #2a3537;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.15rem; margin: .2rem 0 .6rem; }
h3 { font-size: 1rem; margin: .2rem 0 .7rem; }
h1 small, h2 small { font-weight: 400; font-size: .8em; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.big { font-size: 1.25rem; font-weight: 600; }
.center { text-align: center; }
.r { text-align: right; }
.danger { color: var(--red); }
.boot, .loading { padding: 3rem 1rem; text-align: center; color: var(--muted); display: flex; gap: .6rem; justify-content: center; align-items: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── controls ── */
button, .button {
  appearance: none; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; padding: .62rem 1rem; border-radius: 10px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.06); }
button:disabled { opacity: .55; cursor: default; }
button.ghost, .button.ghost { background: transparent; color: var(--brand); }
button.small, .button.small { padding: .35rem .7rem; min-height: 32px; font-size: .85rem; }
button.success { background: var(--green); border-color: var(--green); color: #fff; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.ghost.danger { background: transparent; color: var(--red); border-color: var(--red); }
button.link { background: none; border: 0; color: var(--brand); padding: 0 .2rem; min-height: 0; font-weight: 500; }
button.link.danger { color: var(--red); }
button.block { width: 100%; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .58rem .7rem; min-height: 42px; width: 100%; max-width: 100%;
}
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.field.wide { grid-column: 1 / -1; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.hint { color: var(--muted); font-size: .8rem; }
.check { display: flex; align-items: center; gap: .5rem; margin: .5rem 0 .8rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

/* ── layout ── */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: .02em; }
.brand.big { font-size: 1.6rem; justify-content: center; margin: 1rem 0; }
.tabs { display: flex; gap: .2rem; flex: 1; overflow-x: auto; }
.tabs a, .bottombar a { text-decoration: none; color: var(--muted); padding: .5rem .75rem; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.tabs a.on { color: var(--brand); background: var(--grey-bg); }
.me { position: relative; margin-left: auto; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.me > button { border: 0; padding: 0; min-height: 0; }
.menu { position: absolute; right: 0; top: 2.6rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 220px; padding: .4rem; display: flex; flex-direction: column; }
.menu > * { padding: .5rem .6rem; text-align: left; justify-content: flex-start; }
.menu-head { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
.menu-head small { color: var(--muted); }
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.bottombar { display: none; }
@media (max-width: 760px) {
  .tabs { display: none; }
  .bottombar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); padding: .3rem .3rem calc(.3rem + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottombar a { flex: 1; text-align: center; font-size: .82rem; padding: .55rem .2rem; }
  .bottombar a.on { color: var(--brand); font-weight: 700; }
}
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin: .3rem 0 1rem; }
.page-head select, .actions select, .row select { width: auto; }
.actions, .row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: .6rem; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.cols.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .cols, .cols.three { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.warn { background: var(--amber-bg); border-color: transparent; }
.center-card { max-width: 520px; margin: 3rem auto; text-align: center; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; align-items: center; }
.toolbar > select, .toolbar > input { width: auto; flex: 0 1 220px; }
.toolbar > input[type=search] { flex: 1 1 200px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); flex-wrap: wrap; }
.seg button { background: transparent; color: var(--muted); border: 0; border-radius: 0; min-height: 38px; font-weight: 500; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.seg.wide { margin-bottom: 1rem; }
.selbar { display: flex; gap: .5rem; align-items: center; background: var(--blue-bg); border-radius: 10px; padding: .5rem .8rem; margin-bottom: .8rem; flex-wrap: wrap; }
.selbar.inline { margin: 0; }
.selbar select { width: auto; }
.empty { padding: 1.6rem; text-align: center; color: var(--muted); }
.error-box { background: var(--red-bg); color: var(--red); padding: .7rem .9rem; border-radius: 10px; margin-bottom: .8rem; }
.notice { background: var(--blue-bg); color: var(--blue); padding: .6rem .8rem; border-radius: 10px; }
.section { margin-top: 1.2rem; font-size: 1rem; color: var(--muted); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal .card { width: 100%; max-width: 420px; }

/* ── pills / chips ── */
.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.grey { background: var(--grey-bg); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { padding: .25rem .55rem; border-radius: 8px; background: var(--grey-bg); font-size: .85rem; font-weight: 600; cursor: default; }
.chip.paid { background: var(--green-bg); color: var(--green); }
.chip.sel { cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--muted); }
.chip.sel.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.month-block { margin-bottom: 1rem; }

/* ── tables ── */
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
.page > .table-wrap { margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:hover { background: var(--grey-bg); cursor: pointer; }
table.list.edit tbody tr:hover { cursor: default; }
table.list.edit input, table.list.edit select { min-height: 36px; padding: .35rem .5rem; min-width: 80px; }
table.list th.r, table.list td.r { text-align: right; }
td.chk, th.chk { width: 34px; }
tr.bad td, tr.hl td { background: var(--amber-bg); }
tr.overdue td:first-child { box-shadow: inset 3px 0 var(--red); }
tr.detail td { background: var(--grey-bg); font-size: .9rem; }
.clickable { cursor: pointer; }

/* ── stats & charts ── */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; display: flex; flex-direction: column; }
.stat small { color: var(--muted); font-size: .8rem; }
.stat b { font-size: 1.35rem; }
.stat.good b { color: var(--green); }
.stat.warn b { color: var(--amber); }
.stat.big { border: 0; padding: 0; margin-bottom: .6rem; }
.stat.big b { font-size: 2rem; color: var(--brand); }
.chart { width: 100%; height: 160px; display: block; }
.chart-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }
.hbars { display: flex; flex-direction: column; gap: .45rem; }
.hbar { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: .5rem; align-items: center; font-size: .88rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--grey-bg); border-radius: 6px; height: 12px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.hbar-val { font-weight: 600; min-width: 2.5rem; text-align: right; }
.agents-strip { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.agent-chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--card); border: 1px solid var(--line); padding: .35rem .7rem; border-radius: 999px; font-size: .9rem; }
.agent-chip b { background: var(--grey-bg); border-radius: 999px; padding: 0 .45rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.agent-chip.on .dot, .duty.on .dot { background: var(--green); }

/* ── key/value, timeline, proof ── */
.kv { display: grid; gap: .45rem; margin: 0 0 .8rem; }
.kv > div { display: grid; grid-template-columns: 120px 1fr; gap: .5rem; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 .8rem 1rem; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline time { display: block; color: var(--muted); font-size: .82rem; }
.proof-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.proof-grid figure { margin: 0; }
.proof-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.proof-grid img.signature { object-fit: contain; }
.proof-grid figcaption { font-size: .78rem; color: var(--muted); }

/* ── agent ── */
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: .7rem; }
.job { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; display: flex; flex-direction: column; gap: .4rem; cursor: pointer; box-shadow: var(--shadow); }
.job.slim { flex-direction: row; gap: .6rem; padding: .6rem .85rem; }
.job-top { display: flex; gap: .5rem; align-items: center; }
.job-top .pill { margin-left: auto; }
.job-addr { font-size: 1.02rem; }
.job-detail .big { font-size: 1.4rem; }
.cod-box { background: var(--amber-bg); color: var(--amber); padding: .7rem 1rem; border-radius: 10px; font-size: 1.15rem; margin: .7rem 0; }
.action-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); display: flex; gap: .5rem; flex-wrap: wrap; background: var(--bg); padding: .5rem 0; z-index: 5; }
.action-bar button { flex: 1 1 140px; min-height: 50px; font-size: 1rem; }
.duty { background: var(--card); color: var(--muted); border-color: var(--line); }
.duty.on { color: var(--green); border-color: var(--green); }
.sig { position: relative; }
.sig canvas { width: 100%; height: 170px; border: 1px dashed var(--muted); border-radius: 10px; background: #fff; touch-action: none; display: block; }
.sig button { position: absolute; right: .5rem; top: .4rem; }
.thumbs { display: flex; gap: .5rem; flex-wrap: wrap; }
.thumb { width: 92px; height: 92px; border-radius: 10px; overflow: hidden; position: relative; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 3px; right: 3px; min-height: 0; width: 24px; height: 24px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); border: 0; }
.thumb.add { display: flex; align-items: center; justify-content: center; text-align: center; font-size: .8rem; color: var(--brand); border: 2px dashed var(--brand); cursor: pointer; background: var(--card); }

/* ── auth & tracking ── */
.auth { max-width: 420px; margin: 0 auto; padding: 1.5rem 1rem; }
.auth-card h2 { margin-bottom: 1rem; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.track { max-width: 640px; margin: 0 auto; padding: 0 1rem 3rem; min-height: 100vh; }
.track.rtl { font-family: 'Noto Sans Thaana', Inter, sans-serif; }
.track-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; }
.track-hero { padding: 1.5rem 0 1rem; }
.track-hero h1 { font-size: 1.8rem; margin-bottom: 1rem; }
.track-form { display: flex; gap: .5rem; }
.track-form input { font-size: 1.1rem; min-height: 50px; text-transform: uppercase; }
.track-form button { min-height: 50px; padding: 0 1.4rem; }
.track-code { font-family: ui-monospace, monospace; color: var(--muted); }
.track-status { font-size: 1.5rem; margin: .3rem 0 1rem; }
.track-status.s-delivered { color: var(--green); }
.track-status.s-failed { color: var(--red); }
.steps { list-style: none; display: flex; padding: 0; margin: 0 0 1.2rem; gap: .3rem; }
.steps li { flex: 1; display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
.steps li .dot { width: 100%; height: 6px; border-radius: 3px; background: var(--line); }
.steps li.done { color: var(--ink); font-weight: 600; }
.steps li.done .dot { background: var(--green); }
.track-foot { text-align: center; color: var(--muted); margin-top: 2rem; }

/* ── statement ── */
.stmt-head { display: flex; justify-content: space-between; margin-bottom: 1rem; }
table.sheet { width: 100%; border-collapse: collapse; font-size: .92rem; margin-bottom: 1rem; }
table.sheet th, table.sheet td { border-bottom: 1px solid var(--line); padding: .3rem .5rem; text-align: center; }
table.sheet th { font-weight: 700; }
table.sheet td.hl { background: #fff59d; color: #333; }
table.sheet th.r, table.sheet td.r { text-align: right; }
table.totals { margin-left: auto; border-collapse: collapse; min-width: 300px; margin-bottom: 1rem; }
table.totals td { padding: .35rem .6rem; }
table.totals tr.neg td:nth-child(2) { color: #fff; background: var(--red); }
table.totals tr.pos td:nth-child(2) { color: var(--green); }

/* ── labels ── */
.labels-page { padding: 1rem; }
.labels-bar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.labels-bar select { width: auto; }
.labels { display: flex; flex-wrap: wrap; gap: 6mm; }
.label { width: 100mm; height: 150mm; background: #fff; color: #000; border: 1px solid #000; padding: 4mm; display: flex; flex-direction: column; gap: 2.5mm; font-family: Inter, Arial, sans-serif; overflow: hidden; page-break-inside: avoid; break-inside: avoid; }
.labels.a4 .label { width: 92mm; height: 135mm; }
.l-top { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 2mm; }
.l-brand { font-weight: 800; font-size: 7mm; letter-spacing: .05em; }
.l-no { font-weight: 800; font-size: 11mm; line-height: 1; text-align: right; }
.l-no small { display: block; font-size: 3mm; font-weight: 500; }
.l-zone { background: #000; color: #fff; font-weight: 700; font-size: 5mm; padding: 1.2mm 2.5mm; text-transform: uppercase; }
.l-to small { font-size: 3mm; font-weight: 700; }
.l-to b { display: block; font-size: 6mm; line-height: 1.15; }
.l-phone { font-size: 5mm; font-weight: 600; }
.l-addr { font-size: 4.2mm; line-height: 1.25; max-height: 22mm; overflow: hidden; }
.l-boat { font-size: 3.6mm; border: 1px solid #000; padding: 1mm 2mm; }
.l-cod { border: 1.2mm solid #000; text-align: center; font-weight: 800; font-size: 6.5mm; padding: 1.5mm; }
.l-paid { border: .5mm solid #000; text-align: center; font-weight: 700; font-size: 5mm; padding: 1mm; }
.l-notes { font-size: 3.6mm; font-style: italic; max-height: 10mm; overflow: hidden; }
.l-bottom { margin-top: auto; display: flex; gap: 3mm; align-items: center; border-top: 1px dashed #000; padding-top: 2mm; }
.l-bottom img { width: 30mm; height: 30mm; image-rendering: pixelated; }
.l-bottom > div { display: flex; flex-direction: column; font-size: 3mm; }
.l-code { font-family: ui-monospace, monospace; font-weight: 800; font-size: 5.2mm; }

/* ── toasts ── */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: .4rem; width: min(92vw, 420px); }
.toast { background: #142023; color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); transition: opacity .4s; }
.toast.err { background: var(--red); }
.toast.warn { background: #8a5a00; }
.toast.out { opacity: 0; }

/* ── print ── */
@media print {
  body { background: #fff; color: #000; }
  .no-print, .topbar, .bottombar, .labels-bar, #toasts, .page-head .actions, .toolbar { display: none !important; }
  .page, .labels-page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; background: #fff; }
  .labels { gap: 0; }
  .labels.thermal .label { border: 0; page-break-after: always; break-after: page; }
  .labels.a4 { gap: 4mm; }
  table.sheet td.hl { background: #ff0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.totals tr.neg td:nth-child(2) { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.rtl .timeline { border-left: 0; border-right: 2px solid var(--line); }
.rtl .timeline li { padding: 0 1rem .8rem 0; }
.rtl .timeline li::before { left: auto; right: -6px; }
.rtl .kv dd, .rtl .timeline time { text-align: right; }
