/* Layout: phone-first single column for the driver; wide two-pane for the dashboard. */
:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --ink: #1a1e1c;
  --muted: #646e69;
  --line: #dde1dc;
  --accent: #0d6b5e;
  --accent-ink: #ffffff;
  --accent-soft: #d9ece8;
  --ok: #1d7f47;
  --ok-soft: #dcf0e3;
  --warn: #9a6512;
  --warn-soft: #f7ebd2;
  --bad: #b3362a;
  --bad-soft: #f8dfdb;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --ink: #e9ece9; --muted: #9aa39e;
    --line: #2e3431; --accent: #3fb3a0; --accent-ink: #08201c; --accent-soft: #173a34;
    --ok: #5cc58a; --ok-soft: #173826; --warn: #e2ac54; --warn-soft: #3a2e17; --bad: #f08374; --bad-soft: #3e1f1b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --ink: #e9ece9; --muted: #9aa39e;
  --line: #2e3431; --accent: #3fb3a0; --accent-ink: #08201c; --accent-soft: #173a34;
  --ok: #5cc58a; --ok-soft: #173826; --warn: #e2ac54; --warn-soft: #3a2e17; --bad: #f08374; --bad-soft: #3e1f1b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.55;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
img { max-width: 100%; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.wrap { max-width: 560px; margin: 0 auto; display: grid; gap: 14px; }
.wide { max-width: 1280px; margin: 0 auto; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 auto; min-width: 0; }
.stack { display: grid; gap: 10px; }
.between { justify-content: space-between; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-block: 14px 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card.flat { border: 0; background: var(--surface-2); }

label.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; min-width: 0;
}
textarea { min-height: 70px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type=number] { direction: ltr; text-align: center; font-variant-numeric: tabular-nums; }

.btn {
  font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 9px; padding: 11px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.big { width: 100%; padding: 15px; font-size: 1.05rem; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.seg button { font: inherit; font-weight: 700; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.pill.idle { background: var(--surface-2); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot.live { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); font-weight: 700; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: center; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
tr.short td { background: var(--bad-soft); }
tr.extra td { background: var(--warn-soft); }

.item-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: 0; }
.item-row .name { font-weight: 600; min-width: 0; }
.item-row .meta { font-size: .8rem; color: var(--muted); }
.qty { display: grid; grid-template-columns: 38px 70px 38px; gap: 4px; align-items: center; }
.qty button { font: inherit; font-size: 1.1rem; font-weight: 700; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; }
.qty input { padding: 7px 4px; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); max-width: 100%; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph button { position: absolute; top: 4px; left: 4px; border: 0; background: rgb(0 0 0 / .6); color: #fff; border-radius: 6px; width: 26px; height: 26px; cursor: pointer; }

.sig-box { border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff; position: relative; }
.sig-box canvas { width: 100%; height: 190px; display: block; touch-action: none; border-radius: var(--radius); }
.sig-box .hint { position: absolute; inset: auto 0 8px; text-align: center; color: #9aa; font-size: .8rem; pointer-events: none; }
.sig-img { background: #fff; border-radius: 8px; border: 1px solid var(--line); max-height: 140px; }

.notice { padding: 12px 14px; border-radius: var(--radius); font-size: .9rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 9999; max-width: calc(100% - 32px); }

.empty { text-align: center; color: var(--muted); padding: 22px 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .8rem; color: var(--muted); }

.loading { opacity: .6; pointer-events: none; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
