/* JMS Trip Sheet - one small stylesheet for driver, admin and print pages */
:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --line: #d1d5db;
  --primary: #1d4ed8; --primary-text: #fff; --danger: #b91c1c; --ok: #15803d; --warn: #b45309;
  --warn-bg: #fef3c7; --ok-bg: #dcfce7; --input: #fff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111827; --card: #1f2937; --text: #f9fafb; --muted: #9ca3af; --line: #374151;
    --primary: #3b82f6; --warn-bg: #451a03; --ok-bg: #052e16; --warn: #fbbf24; --ok: #4ade80; --input: #111827; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 18px/1.4 system-ui, "Noto Sans Sinhala", "Iskoola Pota", sans-serif; }
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 80px; }
[hidden] { display: none !important; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 10px 16px;
  background: var(--primary); color: var(--primary-text); flex-wrap: wrap; }
.bar .who { flex: 1; font-size: 15px; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar button.small { background: rgba(255,255,255,.18); color: inherit; border: 0; }

.card { background: var(--card); border-radius: 12px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
label, .field { display: block; margin-bottom: 14px; font-weight: 600; }
label > span, .field > span { display: block; margin-bottom: 6px; }
input, select, textarea { width: 100%; font: inherit; padding: 12px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--input); color: var(--text); min-height: 52px; }
input:focus, select:focus { outline: 3px solid var(--primary); outline-offset: 1px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 2px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; }
button.small { font-size: 15px; padding: 6px 10px; }
button.big { display: block; width: 100%; min-height: 60px; font-size: 20px; font-weight: 700; margin-bottom: 12px; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }

.seg { display: flex; gap: 8px; }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; text-align: center; padding: 14px; border: 2px solid var(--line); border-radius: 10px; margin: 0; }
.seg input:checked + span { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab { flex: 1; min-height: 48px; }
.tab.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.totals .month { color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.stat span { display: block; color: var(--muted); font-size: 15px; }
.stat b { font-size: 30px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.auto { background: var(--bg); padding: 10px; border-radius: 10px; margin: 0 0 14px; }
.auto b { font-size: 22px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; margin-top: 8px; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.bar .badge { margin: 0; }

.trip { display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; width: 100%; text-align: left; margin-bottom: 8px; padding: 12px; }
.trip .d { font-weight: 700; font-size: 15px; }
.trip .det { font-size: 16px; overflow-wrap: anywhere; }
.trip small { display: block; color: var(--muted); font-size: 13px; }
.trip .amt { text-align: right; font-weight: 700; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); }

.toast { position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 528px; margin: 0 auto; padding: 14px 16px;
  border-radius: 10px; background: var(--ok); color: #fff; font-weight: 600; z-index: 20; }
.toast.bad { background: var(--danger); }

/* ---------- admin ---------- */
body.admin main { max-width: 1200px; }
body.admin { font-size: 16px; }
body.admin input, body.admin select { min-height: 42px; padding: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar h2 { margin: 0 auto 0 0; font-size: 20px; }
.toolbar input { width: 130px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; font-size: 15px; }
th { background: var(--bg); }
td.n { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--bg); }
tr.off { opacity: .5; }
.warnbox { border-left: 5px solid var(--warn); }
.warnbox h3 { margin: 0 0 8px; }
.warnbox ul { margin: 0 0 8px; padding-left: 20px; }
dialog { border: 0; border-radius: 12px; padding: 16px; width: min(560px, calc(100% - 32px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.chk { display: flex; gap: 8px; align-items: center; }
.chk input { width: auto; min-height: 0; }

/* ---------- paper sheet (same layout as the printed form) ---------- */
.paper { background: #fff; color: #000; padding: 14px; border-radius: 8px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.paper h1 { text-align: center; font-size: 18px; margin: 0 0 10px; letter-spacing: .3px; }
.phead { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; margin-bottom: 10px; font-size: 15px; }
.phead b, .pfoot b { border-bottom: 1px dotted #000; padding: 0 6px; }
.pscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.sheet { min-width: 860px; width: 100%; border-collapse: collapse; table-layout: fixed; background: #fff; }
table.sheet th, table.sheet td { border: 1px solid #000; padding: 0; height: 34px; font-size: 14px; color: #000; background: #fff; vertical-align: middle; }
table.sheet th { padding: 6px 4px; text-align: center; font-weight: 700; }
table.sheet td.no { text-align: center; font-size: 12px; white-space: nowrap; }
table.sheet td.n { text-align: right; padding: 0 6px; }
table.sheet td.r { text-align: right; padding: 0 8px; }
table.sheet td:not(:has(input,select)) { padding: 0 5px; }
table.sheet input, table.sheet select { width: 100%; min-height: 0; height: 33px; border: 0; border-radius: 0; padding: 0 5px;
  background: transparent; color: #000; font: inherit; font-size: 14px; }
table.sheet input:focus, table.sheet select:focus { outline: 2px solid #1d4ed8; outline-offset: -2px; background: #eff6ff; }
table.sheet input.c-amt { text-align: right; }
table.sheet .msg { font-size: 11px; line-height: 1.2; padding: 0 5px; }
table.sheet .msg:empty { display: none; }
table.sheet tr.saving td { background: #f8fafc; }
table.sheet tr.ok td { background: #f0fdf4; }
table.sheet tr.err td, table.sheet tr.err input { background: #fef2f2; }
table.sheet tr.err .msg { color: #b91c1c; }
table.sheet tr.incomplete td, table.sheet tr.incomplete input, table.sheet tr.warn td, table.sheet tr.pending td { background: #fffbeb; }
table.sheet tr.incomplete .msg, table.sheet tr.warn .msg, table.sheet tr.pending .msg { color: #92400e; }
table.sheet button.x { border: 0; background: none; padding: 0 2px; font-size: 14px; color: #b91c1c; cursor: pointer; }
.pfoot { display: flex; flex-wrap: wrap; gap: 10px 26px; align-items: center; margin-top: 12px; font-size: 15px; }
.pfoot input { width: 110px; min-height: 0; height: 32px; padding: 0 6px; }
.pfoot .sign { margin-left: auto; }
.sheetbar { display: flex; gap: 8px; margin-bottom: 10px; }
.sheetbar button { flex: 1; min-height: 48px; }
main.wide { max-width: 1200px; }

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; }
  .bar, .noprint, .toolbar { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; }
  .pscroll { overflow: visible; }
  table.sheet { min-width: 0; }
  table.sheet th, table.sheet td { height: 22px; font-size: 11px; }
  table.sheet tr { break-inside: avoid; }
  table.sheet thead { display: table-header-group; }
}

.big-link { display: block; text-align: center; padding: 16px; margin-top: 8px; color: var(--primary); font-weight: 700; }
.bar a.navlink { color: inherit; text-decoration: none; background: rgba(255,255,255,.18); border-radius: 10px; padding: 6px 10px; font-size: 15px; }
