/* Private Fuel Tracker v2 – red theme, mobile first, nothing wider than the screen */
:root {
  --pri: #b71c1c; --pri-dark: #8e1515; --pri-ink: #7a1111; --pri-soft: #fdecec; --pri-ring: #f3b4b4;
  --bg: #f7f3f3; --card: #fff; --ink: #1f1a1a; --muted: #625959; --line: #ece4e4;
  --ok: #0f7a4a; --ok-soft: #e3f5ec; --warn: #8a5100; --warn-soft: #fff4dc; --bad: #9f1239; --bad-soft: #fde7ee;
  --radius: 20px; --tap: 52px; --shadow: 0 1px 2px rgba(60, 10, 10, .06), 0 4px 14px rgba(60, 10, 10, .05);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px); --safe-right: env(safe-area-inset-right, 0px);
}
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; font-size: clamp(18px, 4.9vw, 19px); }   /* 2.0.3: bigger UI – 18px on small phones, 19px from ~390px wide and on desktop */
/* Safety net: never let anything make the page wider than the phone (which makes mobile browsers zoom out). */
html, body { max-width: 100%; overflow-x: hidden; }
@supports (overflow: clip) { html, body { overflow-x: clip; } }   /* clip keeps the sticky header working */
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; padding-bottom: var(--safe-bottom); overflow-wrap: break-word; }
img, svg, video, canvas, iframe, table, pre { max-width: 100%; }
img { height: auto; }
h1, h2, h3, p, label, td, th, .badge, .sub, .msg, .hint, .muted, .name { overflow-wrap: anywhere; }
button, input, select, textarea { font: inherit; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 12px calc(16px + var(--safe-left));
  background: linear-gradient(135deg, var(--pri) 0%, var(--pri-dark) 100%); color: #fff; box-shadow: 0 2px 8px rgba(80, 0, 0, .25); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.22rem; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.brand span { white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); border: 0; border-radius: 999px; padding: 8px 18px; font-size: .94rem; font-weight: 700; background: rgba(255, 255, 255, .2); color: #fff; cursor: pointer; white-space: nowrap; }
.pill.offline { background: #fff; color: var(--pri-ink); }
.pill.wait { background: #ffd8a8; color: #5c3200; }
.pill.check { background: #fff; color: var(--pri); }
#btn-logout { min-height: var(--tap); }
.who { display: flex; gap: 8px; align-items: center; min-width: 0; }
.who .name { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .96rem; }
.banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 18px; font-size: 1rem; background: var(--warn-soft); color: #5c3a00; border-bottom: 1px solid #f0dcb0; }

/* ---------- layout ---------- */
main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 16px calc(14px + var(--safe-right)) 56px calc(14px + var(--safe-left)); }
.view { min-width: 0; }
h1 { font-size: 2.05rem; line-height: 1.2; margin: 8px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 1.42rem; line-height: 1.3; margin: 0 0 14px; }
.card { background: var(--card); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { max-width: 560px; margin: 24px auto; }
.card.accent { border-top: 4px solid var(--pri); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.muted { color: var(--muted); } .hint { color: var(--muted); font-size: .94rem; }
.hidden { display: none !important; } .center { text-align: center; }

/* ---------- forms ---------- */
label { display: block; font-size: 1rem; color: var(--muted); margin: 12px 0; font-weight: 600; min-width: 0; }
input, select { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 56px; margin-top: 8px; padding: 13px 16px; font-size: max(18px, 1.05rem); border: 1.5px solid #dfd4d4; border-radius: 14px; background: #fff; color: var(--ink); font-weight: 400; }
input[type=date] { -webkit-appearance: none; appearance: none; text-align: left; }
input:focus, select:focus { outline: 3px solid var(--pri-ring); border-color: var(--pri); }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; } .row2 label { margin: 8px 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: var(--tap); padding: 14px 22px; border-radius: 14px; border: 1.5px solid #e2d6d6; background: #fff; color: var(--ink); font-size: 1.05rem; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center; max-width: 100%; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; box-shadow: 0 2px 6px rgba(183, 28, 28, .3); }
.btn.primary:active { background: var(--pri-dark); }
.btn.ghost { background: transparent; } .btn.soft { background: var(--pri-soft); border-color: var(--pri-soft); color: var(--pri-ink); }
.btn.danger { color: var(--bad); border-color: #f1c2cf; }
.btn.small { padding: 12px 18px; font-size: .98rem; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn.big { min-height: 64px; padding: 18px 26px; font-size: 1.18rem; }
.btn:disabled { opacity: .55; }
.filebtn { position: relative; overflow: hidden; } .filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; margin: 0; }
.msg { min-height: 1em; font-size: 1rem; } .msg.err { color: var(--bad); font-weight: 650; } .msg.ok { color: var(--ok); } .msg.warn { color: var(--warn); }

/* ---------- dashboard ---------- */
.hello { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin: 8px 0 20px; }
.hello > div { min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 20px; margin-bottom: 20px; } .grid .card { margin-bottom: 0; }
.stat { position: relative; overflow: hidden; padding-left: 30px; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: var(--pri); }
.stat.c2::before { background: #e0663b; } .stat.c3::before { background: #6b6262; }
.stat-label { font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.stat-value { font-size: 2.6rem; line-height: 1.15; font-weight: 800; margin: 8px 0; letter-spacing: -.02em; overflow-wrap: anywhere; }
.bar { height: 14px; background: #f1e6e6; border-radius: 6px; overflow: hidden; margin: 8px 0; } .bar-fill { height: 100%; background: var(--pri); width: 0; max-width: 100%; transition: width .4s; } .bar-fill.over { background: #5a0b0b; }

/* ---------- lists ---------- */
.list .item { display: flex; justify-content: space-between; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); align-items: center; min-width: 0; }
.list .item > * { min-width: 0; }
.list .item:last-child { border-bottom: 0; }
.item .main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.item .sub { font-size: .95rem; color: var(--muted); }
.item .right { flex: none; text-align: right; white-space: nowrap; }
.empty { color: var(--muted); padding: 8px 0; }
.item .thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; background: #eee; flex: none; }
.badge { display: inline-block; max-width: 100%; font-size: .84rem; line-height: 1.35; font-weight: 750; padding: 4px 12px; border-radius: 14px; background: #f1ecec; color: #3a3333; letter-spacing: .02em; white-space: normal; overflow-wrap: anywhere; vertical-align: middle; }
.badge.PENDING { background: var(--warn-soft); color: var(--warn); } .badge.APPROVED { background: var(--ok-soft); color: var(--ok); } .badge.REJECTED { background: var(--bad-soft); color: var(--bad); }
.badge.OVER { background: var(--bad-soft); color: var(--bad); } .badge.UNDER { background: var(--ok-soft); color: var(--ok); } .badge.AT { background: var(--warn-soft); color: var(--warn); }
.badge.flag { background: var(--warn-soft); color: var(--warn); }
.badge.q-wait { background: #ffe9cc; color: #6b3d00; } .badge.q-review { background: var(--pri); color: #fff; } .badge.q-attn { background: var(--bad-soft); color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; align-items: center; }
.list .item.slip { flex-wrap: wrap; }
.item.slip .actions { flex: 1 1 100%; margin-top: 0; }

/* ---------- tables (scroll inside their own box; stacked cards on phones) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.tbl { width: 100%; border-collapse: collapse; font-size: 1rem; }
.tbl th, .tbl td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; } .tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { font-size: .86rem; color: var(--muted); text-transform: uppercase; }
.tbl td:first-child { white-space: normal; min-width: 9em; }   /* long names wrap instead of pushing the table wider */
.tbl .badge { white-space: nowrap; overflow-wrap: normal; }        /* a squeezed column must never break a badge letter by letter */
@media (max-width: 700px) {
  .tbl.stack, .tbl.stack tbody, .tbl.stack tr, .tbl.stack td, .tbl.stack th { display: block; width: 100%; }
  .tbl.stack tr.head { display: none; }
  .tbl.stack tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .tbl.stack tr:last-child { border-bottom: 0; }
  .tbl.stack td, .tbl.stack th { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; column-gap: 6px; row-gap: 2px; padding: 4px 0; border: 0; white-space: normal; text-align: right; font-size: 1.02rem; text-transform: none; color: var(--ink); }
  .tbl.stack td::before, .tbl.stack th::before { content: attr(data-label); flex: none; max-width: 50%; margin-right: auto; padding-right: 12px; text-align: left; color: var(--muted); font-size: .94rem; font-weight: 600; }
  .tbl.stack td:first-child, .tbl.stack th:first-child { font-weight: 750; font-size: 1.12rem; justify-content: flex-start; text-align: left; }
  .tbl.stack td:first-child::before, .tbl.stack th:first-child::before { content: none; }
  .tbl.stack td:empty, .tbl.stack th:empty { display: none; }
  .tbl.stack tr.total { background: var(--pri-soft); border-radius: 12px; padding: 12px; margin-top: 8px; }
}

/* ---------- capture ---------- */
/* in-app camera */
.cam-box { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 58vh; background: #120c0c; border-radius: 16px; overflow: hidden; margin: 0 0 10px; }
.cam-box video { display: block; width: 100%; height: 100%; object-fit: contain; }   /* show the whole frame that will be captured */
.cam-guide { position: absolute; inset: 5% 7%; border: 2px dashed #fff; border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .45), inset 0 0 0 1.5px rgba(0, 0, 0, .45); }
#view-capture:has(#cap-step-camera:not(.hidden)) h1 { display: none; }
.cam-row { display: flex; gap: 10px; margin-top: 10px; } .cam-row .btn { flex: 1 1 0; }
.preview { display: block; width: 100%; max-height: 340px; object-fit: contain; background: #1b1414; border-radius: 14px; }
details.ocr { margin: 12px 0; font-size: .95rem; } details.ocr summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; }
details.ocr pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #faf6f6; padding: 10px; border-radius: 10px; max-height: 240px; overflow: auto; }
.scan-hint { display: block; font-size: .9rem; color: var(--warn); margin-top: 4px; font-weight: 600; }
.spinner { width: 48px; height: 48px; margin: 28px auto 10px; border: 5px solid var(--pri-soft); border-top-color: var(--pri); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.saved-phone { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-soft); color: #5c3a00; border-radius: 14px; padding: 16px; margin: 14px 0; font-size: 1rem; }
.saved-phone > span:last-child { min-width: 0; }

/* ---------- admin ---------- */
.admin-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; min-width: 0; }
.admin-actions select { width: auto; margin: 0; }
.tabs { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; scrollbar-width: none; margin: 12px calc(-14px - var(--safe-left)) 14px calc(-14px - var(--safe-right)); padding: 4px 14px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; scroll-snap-align: start; border: 0; background: #efe5e5; min-height: var(--tap); padding: 12px 24px; border-radius: 26px; font-size: 1.04rem; font-weight: 700; color: var(--ink); cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--pri); color: #fff; }
.hist-title { margin-top: 16px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(30, 5, 5, .5); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal-box { background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; overflow-x: hidden; border-radius: 20px 20px 0 0; padding: 24px 22px calc(24px + var(--safe-bottom)); }
@media (min-width: 640px) { .modal { align-items: center; } .modal-box { border-radius: 20px; } }
.modal-box img { display: block; width: 100%; border-radius: 10px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(22px + var(--safe-bottom)); margin: 0 auto; width: max-content; max-width: calc(100% - 24px); background: #2a1515; color: #fff; padding: 14px 22px; border-radius: 14px; z-index: 30; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: 1.05rem; overflow-wrap: anywhere; }
.foot-actions { text-align: center; margin-top: 10px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.4rem; background: #faf6f6; padding: 12px; border-radius: 10px; text-align: center; letter-spacing: .06em; user-select: all; overflow-wrap: anywhere; }
.install { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.install > div { min-width: 0; flex: 1 1 180px; }
.version { text-align: center; color: #857b7b; font-size: .86rem; margin-top: 24px; }

/* ---------- phones ---------- */
@media (max-width: 600px) {
  h1 { font-size: 1.75rem; }
  .card { padding: 18px; }
  .stat { padding-left: 26px; }
  .stat-value { font-size: 2.3rem; }
  .hello { flex-direction: column; align-items: stretch; }
  .hello .btn.big { width: 100%; }
  .admin-head { flex-direction: column; align-items: stretch; }
  .admin-actions { flex-direction: column; }
  .admin-actions select, .admin-actions .btn { width: 100%; }
  .card-head .btn { flex: 1 1 auto; }
  .list .item { flex-wrap: wrap; }
  .list .item .main { flex: 1 1 60%; }
  /* admin slip: details, then litres/amount on one line, then status + full-width-friendly buttons */
  .item.slip .main { flex: 1 1 100%; }
  .item.slip .right { flex: 1 1 100%; display: flex; gap: 12px; align-items: baseline; text-align: left; font-size: 1.12rem; }
  .item.slip .right .sub { font-size: 1rem; }
  .item .actions .btn { flex: 1 1 auto; }
  /* header: brand + log out on the first line, status pills on their own line below */
  .topbar { justify-content: flex-start; }
  .top-right { display: contents; }
  .brand { order: 0; flex: 1 1 auto; }
  .who { order: 1; }
  #net-pill, #q-pill-wait, #q-pill-check { order: 3; }
  .topbar:has(> .top-right > .pill:not(.hidden))::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .who .name { display: none; }
}
@media (max-width: 380px) {
  .row2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .brand span { font-size: 1.06rem; }
  .pill { padding: 6px 12px; font-size: .86rem; }
  .card { padding: 16px; }
}

/* ---------- 2.0.3: dashboard stat cards ----------
   phones: stacked; laptops (incl. 1280 and 1440 wide): first two side by side, third full width underneath
   (three across does not fit "240 L / month" at this size); very wide screens: three across. */
.grid.stats { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 700px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.stats > :nth-child(3) { grid-column: 1 / -1; }
}
@media (min-width: 1500px) {
  main { max-width: 1340px; }
  .grid.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.stats > :nth-child(3) { grid-column: auto; }
}
/* desktop: roomier column padding */
@media (min-width: 1000px) {
  main { padding: 24px calc(28px + var(--safe-right)) 64px calc(28px + var(--safe-left)); }
  .tabs { margin-left: -28px; margin-right: -28px; padding: 4px 28px; }
  .topbar { padding-left: 28px; padding-right: 28px; }
}
