/*
 * Densep Driver — stylesheet
 *
 * Palette follows app.densep.com/docs/style-guide.md (Minimal Professional).
 * Two additions, with the UX rationale that style guide requires:
 *
 *   --danger / --warn : the shared guide collapses danger to grey (#4A4A4A).
 *     A driver reads this screen one-handed, in sunlight, while a passenger
 *     waits. "ส่งไม่สำเร็จ" and "จบงาน" must not look like body text — the
 *     whole point of those states is that they stop the eye.
 *
 * Everything is sized for a thumb: no interactive target below 48px.
 */

:root {
  /* densep shared palette */
  --bg: #ffffff;
  --bg-soft: #f7f7f7;
  --surface: #ffffff;
  --line: #e0e0e0;
  --text: #4a4a4a;
  --muted: rgba(74, 74, 74, 0.68);
  --accent: #2d7d99;
  --accent-soft: rgba(45, 125, 153, 0.12);
  --positive: #5c996d;
  --inverse: #ffffff;

  /* driver-app additions (see header note) */
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.1);
  --warn: #8a5300;
  --warn-soft: rgba(138, 83, 0, 0.12);

  /* headings run darker than the shared #4A4A4A: pickup times and plate
     numbers are read at a glance in bright light. */
  --heading: #24323a;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow: 0 6px 18px rgba(36, 50, 58, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --tabbar-h: 62px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-soft);
  color: var(--text);
  font-family: "Noto Sans Thai", "IBM Plex Sans Thai", "Sarabun", -apple-system,
    BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1,
h2,
h3 {
  color: var(--heading);
  margin: 0;
  line-height: 1.3;
}

a {
  color: var(--accent);
}

/* ---------------------------------------------------------------- layout */

.app-root {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 14px
    calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  min-height: 100vh;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.screen-head h1 {
  font-size: 21px;
  flex: 1;
  min-width: 0;
}

.screen-sub {
  color: var(--muted);
  font-size: 13.5px;
  margin: 2px 0 0;
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.spacer {
  flex: 1;
}

/* ------------------------------------------------------------- boot/toast */

.boot {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 22vh 0;
  text-align: center;
}

.boot-mark {
  width: 62px;
  height: 62px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: var(--inverse);
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 800;
}

.boot-text {
  color: var(--muted);
  margin: 0;
}

.boot-error {
  color: var(--danger);
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px);
  max-width: min(560px, calc(100vw - 28px));
  background: var(--heading);
  color: var(--inverse);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  font-weight: 500;
  box-shadow: 0 10px 26px rgba(36, 50, 58, 0.26);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
}

.toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-danger {
  background: var(--danger);
}

/* ------------------------------------------------------------ net banner */

.net-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: calc(var(--safe-top) + 9px) 14px 9px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.net-banner[hidden] {
  display: none;
}

.net-banner.is-offline {
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid rgba(138, 83, 0, 0.28);
}

.net-banner.is-pending {
  background: var(--accent-soft);
  color: var(--accent);
  border-bottom: 1px solid rgba(45, 125, 153, 0.28);
}

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--heading);
  margin: 0 0 8px;
}

.job-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 13px 14px;
  box-shadow: var(--shadow);
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 48px;
}

.job-card:active {
  background: var(--bg-soft);
}

.job-card.is-done {
  border-left-color: var(--positive);
}

.job-card.is-cancelled {
  border-left-color: var(--line);
  opacity: 0.72;
}

.job-time {
  font-size: 22px;
  font-weight: 800;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

.job-route {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--heading);
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.job-meta {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.date-head {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: none;
  padding: 6px 2px 0;
  letter-spacing: 0.2px;
}

/* ----------------------------------------------------------------- pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}

.pill.s-planned,
.pill.s-assigned {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(45, 125, 153, 0.3);
}

.pill.s-queued,
.pill.s-monitoring {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(138, 83, 0, 0.3);
}

.pill.s-en_route,
.pill.s-arrived {
  background: rgba(45, 125, 153, 0.2);
  color: #1c5a70;
  border-color: rgba(45, 125, 153, 0.42);
}

.pill.s-completed {
  background: rgba(92, 153, 109, 0.16);
  color: #3d6b4a;
  border-color: rgba(92, 153, 109, 0.4);
}

.pill.s-cancelled {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(179, 38, 30, 0.32);
}

/* --------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-weight: 700;
  min-height: 48px;
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--inverse);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 56px;
  font-size: 17px;
}

.btn-ghost {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line);
}

.btn-quiet {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--line);
}

.btn-positive {
  background: var(--positive);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger-ghost {
  background: var(--surface);
  color: var(--danger);
  border-color: rgba(179, 38, 30, 0.4);
}

.btn-sm {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
}

.btn-icon {
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line);
  font-size: 18px;
}

/* ---------------------------------------------------------------- fields */

.field {
  display: grid;
  gap: 6px;
}

.label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--heading);
}

.input,
.select,
.textarea {
  appearance: none;
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* 16px minimum stops iOS Safari from zooming the viewport on focus. */
  font-size: 16px;
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus,
.btn:focus-visible,
.job-card:focus-visible,
.tab:focus-visible {
  outline: 3px solid rgba(45, 125, 153, 0.45);
  outline-offset: 2px;
}

.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

/* ------------------------------------------------------- status messages */

/*
 * Three visually distinct states, because conflating them is how a driver ends
 * up not knowing whether ops received "ถึงแล้ว":
 *   .error-box  — the action failed and nothing was recorded
 *   .warn-box   — accepted locally, NOT yet on the server (queued)
 *   .empty      — nothing to show, and that is not a failure
 */

.error-box {
  background: var(--danger-soft);
  border: 1px solid rgba(179, 38, 30, 0.32);
  color: var(--danger);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
}

.error-box p,
.warn-box p {
  margin: 4px 0 0;
  font-weight: 500;
}

.warn-box {
  background: var(--warn-soft);
  border: 1px solid rgba(138, 83, 0, 0.3);
  color: var(--warn);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 34px 18px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
}

.empty strong {
  display: block;
  color: var(--heading);
  margin-bottom: 4px;
}

.stale-note {
  font-size: 13px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

/* --------------------------------------------------------- detail blocks */

.kv {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr;
  gap: 8px 12px;
  font-size: 14.5px;
}

.kv dt {
  color: var(--muted);
  font-weight: 600;
}

.kv dd {
  margin: 0;
  color: var(--heading);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pax-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--bg-soft);
}

.pax-name {
  font-weight: 700;
  color: var(--heading);
  font-size: 15px;
}

.pax-note {
  font-size: 13.5px;
  margin: 6px 0 0;
  color: var(--text);
}

.pax-note b {
  color: var(--heading);
}

.tel-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--inverse);
  font-weight: 700;
  text-decoration: none;
  font-size: 14.5px;
}

/* ------------------------------------------------------------ gps / sync */

.gps-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  flex: none;
}

.gps-dot.is-live {
  background: var(--positive);
  box-shadow: 0 0 0 4px rgba(92, 153, 109, 0.22);
}

.gps-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

.sync-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  background: var(--surface);
  font-size: 14px;
}

.sync-item .sync-kind {
  font-weight: 700;
  color: var(--heading);
}

.sync-item .sync-err {
  color: var(--danger);
  font-size: 13px;
  margin: 5px 0 0;
  overflow-wrap: anywhere;
}

.counter {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--heading);
  font-size: 19px;
}

/* --------------------------------------------------------------- tabbar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}

.tabbar[hidden] {
  display: none;
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  min-height: var(--tabbar-h);
  display: grid;
  place-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 6px 2px;
  position: relative;
}

.tab-glyph {
  font-size: 20px;
  line-height: 1;
}

.tab.is-active {
  color: var(--accent);
}

.tab-badge {
  position: absolute;
  top: 7px;
  left: 50%;
  margin-left: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: var(--inverse);
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* ---------------------------------------------------------------- login */

.login-wrap {
  padding-top: 6vh;
  display: grid;
  gap: 18px;
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

.login-brand img {
  width: 68px;
  height: 68px;
  border-radius: var(--radius-lg);
}

.login-brand h1 {
  font-size: 22px;
}

.pw-wrap {
  position: relative;
}

.pw-wrap .input {
  padding-right: 76px;
}

.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  /* without the translate the control hangs below centre — the exact bug
     recorded in the ecosystem notes for .password-toggle */
  transform: translateY(-50%);
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

/* --------------------------------------------------------------- utility */

.mono {
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.spin {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-ghost .spin,
.btn-quiet .spin {
  border-color: rgba(45, 125, 153, 0.3);
  border-top-color: var(--accent);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Drivers work in sunlight; a dark theme would hurt here, so the app stays
   light on purpose. Only the chrome follows the OS hint. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-soft: #f2f3f4;
  }
}
