/* Shiplix driver PWA.
   Built for a phone held in one hand, outdoors, possibly with gloves on: large tap
   targets, high contrast, no hover-dependent affordances. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #10203a;
  --muted: #5d6b80;
  --line: #d8dfe8;
  --brand: #0f2038;
  --accent: #1b74d4;
  --ok: #14804a;
  --warn: #9a6700;
  --danger: #b3261e;
  --radius: 12px;
  --tap: 48px; /* never smaller: this is the glove-and-rain minimum */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1520;
    --surface: #16202e;
    --ink: #e8eef6;
    --muted: #9aabc0;
    --line: #2a3746;
    --brand: #e8eef6;
    --accent: #4c9df0;
    --ok: #4ac07f;
    --warn: #e0aa3e;
    --danger: #ef6a5f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  /* iOS notch and home indicator - the sign button sits at the bottom of the
     screen and would otherwise collide with the gesture bar. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: contain;
}

/* ------------------------------------------------------------------ chrome */
header.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--brand);
  color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top));
}

@media (prefers-color-scheme: dark) {
  header.bar { background: #0a111b; color: var(--ink); }
}

header.bar h1 { font-size: 17px; margin: 0; font-weight: 600; flex: 1; }
header.bar a, header.bar button {
  color: inherit;
  background: none;
  border: 0;
  font: inherit;
  text-decoration: none;
  min-height: 36px;
  padding: 0 8px;
  cursor: pointer;
  opacity: 0.9;
}

main { padding: 16px; max-width: 720px; margin: 0 auto; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

a.card { display: block; text-decoration: none; color: inherit; }

.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.muted { color: var(--muted); font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ref { font-weight: 600; letter-spacing: 0.02em; }

/* ------------------------------------------------------------------- chips */
.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.chip[data-s='DISPATCHED'] { color: var(--muted); }
.chip[data-s='EN_ROUTE']   { color: var(--accent); }
.chip[data-s='AT_PICKUP']  { color: var(--warn); }
.chip[data-s='LOADED']     { color: var(--warn); }
.chip[data-s='DELIVERED']  { color: var(--ok); }
.chip[data-s='CANCELLED']  { color: var(--danger); }

/* ----------------------------------------------------------------- buttons */
button, .btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block   { display: flex; width: 100%; }
.btn-lg      { min-height: 56px; font-size: 17px; }

/* ------------------------------------------------------------------ forms */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input, select, textarea {
  font: inherit;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { margin-bottom: 14px; }

/* --------------------------------------------------------------- signature */
.sigwrap { position: relative; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
canvas.sig { display: block; width: 100%; height: 200px; touch-action: none; border-radius: var(--radius); }
.sigwrap[data-signed='true'] { border-style: solid; border-color: var(--ok); }
.sighint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.sigwrap[data-signed='true'] .sighint { display: none; }

/* ------------------------------------------------------------ damage panels */
.diagram { width: 100%; height: auto; display: block; }
.panel { fill: var(--surface); stroke: var(--muted); stroke-width: 1.5; cursor: pointer; }
.panel[data-marked='true'] { fill: var(--danger); fill-opacity: 0.75; }
.panel-label { font-size: 7px; fill: var(--muted); pointer-events: none; text-anchor: middle; }

/* ------------------------------------------------------------------ scanner */
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; }
#reader video { width: 100% !important; border-radius: var(--radius); }

/* -------------------------------------------------------------- indicators */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
  border: 1px solid;
}
.banner-warn   { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.banner-info   { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 140%);
  max-width: min(92vw, 520px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  z-index: 100;
  transition: transform 0.22s ease;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}
.toast.show { transform: translate(-50%, 0); }
.toast[data-kind='error'] { background: var(--danger); color: #fff; }
.toast[data-kind='ok'] { background: var(--ok); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .toast { transition: none; }
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
