/* ===========================================================================
   Sakay Tablas — driver dispatch panel.

   One stylesheet, loaded by both entry documents (`/` and `/sakay-tablas-pwa`),
   so a driver sees the same dispatch panel wherever the manifest shortcut or a
   deep link happens to drop them. The two documents carry different token sets
   (`--brand-yellow` is #facc15 on one and #ffd60a on the other, and only one of
   them defines `--bg-card`), so every value below is written as
   `var(--token, literal)`: the panel picks up the host page's palette when it
   has one and still renders identically when it does not.

   Class prefix `dd-` keeps this file from colliding with either page's existing
   component classes. The ids inside the markup are the contract shared with
   app-core and assets/driver-dispatch.js and are deliberately not styled here.
   =========================================================================== */

.dd {
  --dd-yellow: var(--brand-yellow, #facc15);
  --dd-green: var(--brand-green, #22c55e);
  --dd-red: var(--danger-red, #ef4444);
  --dd-blue: var(--brand-blue, #38bdf8);
  --dd-surface: #141414;
  --dd-surface-raised: #1c1c1c;
  --dd-line: #2f2f2f;
  --dd-text: #ffffff;
  --dd-text-dim: #d1d5db;
  --dd-text-mute: #94a3b8;
  /* Minimum comfortable touch target; drivers use this one-handed while
     stopped, often in sunlight and often with gloves on. */
  --dd-tap: 48px;

  background: var(--dd-surface);
  border: 1px solid var(--dd-line);
  border-radius: 16px;
  padding: 14px;
  color: var(--dd-text);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- identity */
.dd-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.dd-eyebrow {
  margin: 0;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dd-text-mute);
}

.dd-name {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--dd-text);
}

.dd-head-right {
  align-items: flex-end;
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 6px;
}

.dd-pill {
  flex: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.dd-pill-ok {
  background: rgba(34, 197, 94, 0.14);
  border-color: var(--dd-green);
  color: var(--dd-green);
}

.dd-pill-warn {
  background: rgba(250, 204, 21, 0.14);
  border-color: var(--dd-yellow);
  color: var(--dd-yellow);
}

/* A pill that is also a control gets the full tap target. */
button.dd-pill {
  cursor: pointer;
  min-height: 34px;
}

.dd-notice {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--dd-red);
  border-radius: 12px;
  color: #fecaca;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.45;
  margin-bottom: 12px;
  padding: 11px 13px;
}

/* ------------------------------------------------------------ status strip */
.dd-status {
  align-items: center;
  background: var(--dd-surface-raised);
  border: 1px solid var(--dd-line);
  border-radius: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 10px 12px;
}

.dd-status-main {
  align-items: center;
  display: flex;
  font-size: 0.85rem;
  font-weight: 800;
  gap: 8px;
  min-width: 0;
}

/* The dot carries the online state redundantly with the label's text, for
   drivers glancing at the panel rather than reading it. */
.dd-dot {
  background: var(--dd-text-mute);
  border-radius: 50%;
  flex: none;
  height: 9px;
  width: 9px;
}

.dd[data-driver-online="true"] .dd-dot {
  background: var(--dd-green);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}

.dd-gps {
  color: var(--dd-text-mute);
  font-size: 0.74rem;
  margin: 0;
}

/* --------------------------------------------------------------- metrics */
.dd-metrics {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.dd-metric {
  background: var(--dd-surface-raised);
  border: 1px solid var(--dd-line);
  border-radius: 12px;
  padding: 9px 11px;
}

.dd-metric-val {
  color: var(--dd-yellow);
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.1;
}

.dd-metric-key {
  color: var(--dd-text-mute);
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-top: 2px;
  text-transform: uppercase;
}

/* -------------------------------------------------------- vehicle picker */
.dd-group-label {
  color: var(--dd-text-dim);
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 7px;
}

.dd-vehicles {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.dd-vehicle {
  align-items: center;
  background: var(--dd-surface-raised);
  border: 1.5px solid var(--dd-line);
  border-radius: 12px;
  color: var(--dd-text-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-family: inherit;
  gap: 3px;
  justify-content: center;
  min-height: var(--dd-tap);
  padding: 9px 5px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.dd-vehicle-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.dd-vehicle-name {
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.15;
}

.dd-vehicle[aria-checked="true"] {
  background: rgba(250, 204, 21, 0.12);
  border-color: var(--dd-yellow);
  color: var(--dd-yellow);
}

.dd-vehicle:active { transform: scale(0.97); }

@media (prefers-reduced-motion: reduce) {
  .dd-vehicle { transition: none; }
  .dd-vehicle:active { transform: none; }
}

/* --------------------------------------------------------------- buttons */
/* `.dd-btn` is a complete button definition rather than a modifier, because the
   two host pages style `.btn-action` differently and the dispatch panel has to
   look the same on both. The online toggle keeps its `.btn-action .btn-yellow`
   / `.btn-red` classes as well: app-core swaps those two class names to signal
   state, so removing them would break the toggle. */
.dd-btn,
.dd .btn-action {
  align-items: center;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  gap: 7px;
  justify-content: center;
  letter-spacing: 0.01em;
  line-height: 1.2;
  min-height: var(--dd-tap);
  padding: 11px 14px;
  text-align: center;
  transition: filter 0.15s, transform 0.1s;
  width: 100%;
}

.dd-btn:active,
.dd .btn-action:active { transform: scale(0.99); }

.dd-btn[disabled],
.dd .btn-action[disabled] { cursor: not-allowed; filter: grayscale(0.5); opacity: 0.55; }

@media (prefers-reduced-motion: reduce) {
  .dd-btn, .dd .btn-action { transition: none; }
  .dd-btn:active, .dd .btn-action:active { transform: none; }
}

.dd-btn-yellow, .dd .btn-yellow { background: var(--dd-yellow); color: #1a1400; }
.dd-btn-green, .dd .btn-green { background: var(--dd-green); color: #04240f; }
.dd-btn-red, .dd .btn-red { background: var(--dd-red); color: #ffffff; }
.dd-btn-blue { background: var(--dd-blue); color: #06232e; }

.dd-btn-ghost {
  background: transparent;
  border: 1.5px solid var(--dd-line);
  color: var(--dd-text-dim);
}

.dd-btn-danger-ghost {
  background: transparent;
  border: 1.5px solid var(--dd-red);
  color: var(--dd-red);
}

.dd-toggle { margin-bottom: 12px; }

/* ------------------------------------------------------- incoming requests */
.dd-section-head {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin: 0 0 8px;
}

.dd-section-title {
  color: var(--dd-text);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin: 0;
  text-transform: uppercase;
}

.dd-empty {
  background: var(--dd-surface-raised);
  border: 1px dashed var(--dd-line);
  border-radius: 12px;
  color: var(--dd-text-mute);
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 16px 14px;
  text-align: center;
}

/* One pending trip. Rendered by app-core as well as by driver-dispatch.js, so
   the card styling lives here and neither script carries inline colours. */
.dd-ride {
  background: var(--dd-surface-raised);
  border: 1px solid var(--dd-line);
  border-radius: 12px;
  margin-bottom: 10px;
  padding: 12px;
}

.dd-ride:last-child { margin-bottom: 0; }

.dd-ride-top {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dd-ride-vehicle {
  color: var(--dd-yellow);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dd-ride-fare {
  background: rgba(250, 204, 21, 0.14);
  border-radius: 8px;
  color: var(--dd-yellow);
  flex: none;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 9px;
  white-space: nowrap;
}

.dd-ride-legs {
  color: var(--dd-text-dim);
  display: grid;
  font-size: 0.8rem;
  gap: 4px;
  line-height: 1.4;
  margin-bottom: 10px;
}

.dd-ride-legs strong { color: var(--dd-text); font-weight: 700; }

.dd-bid {
  align-items: center;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid var(--dd-blue);
  border-radius: 10px;
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding: 7px;
}

.dd-bid-input {
  background: var(--dd-surface);
  border: 1px solid var(--dd-line);
  border-radius: 8px;
  color: var(--dd-text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  min-height: 40px;
  padding: 8px;
  width: 92px;
}

.dd-bid .dd-btn { flex: 1; min-height: 40px; padding: 8px 10px; }

/* ------------------------------------------------------------ active trip */
.dd-trip {
  background: rgba(34, 197, 94, 0.07);
  border: 1.5px solid var(--dd-green);
  border-radius: 14px;
  padding: 13px;
}

.dd-trip-head {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dd-trip-title {
  color: var(--dd-green);
  font-size: 0.9rem;
  font-weight: 800;
  margin: 0;
}

.dd-trip-fare {
  color: var(--dd-yellow);
  font-size: 1.15rem;
  font-weight: 800;
  margin: 10px 0;
}

.dd-trip-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 10px;
}

.dd-trip-actions .dd-btn { min-height: 44px; padding: 10px; font-size: 0.8rem; }

/* The PIN step is the handover check: the driver may only start the trip after
   the passenger reads out the code, which is why it is a distinct block rather
   than an optional field. */
.dd-pin {
  background: var(--dd-surface-raised);
  border: 1px solid var(--dd-line);
  border-radius: 12px;
  margin-bottom: 10px;
  padding: 11px;
}

.dd-pin-label {
  color: var(--dd-text-dim);
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 7px;
}

.dd-pin-row { display: flex; gap: 8px; }

.dd-pin-input {
  background: var(--dd-surface);
  border: 1.5px solid var(--dd-line);
  border-radius: 10px;
  color: var(--dd-text);
  flex: 1;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.32em;
  min-height: var(--dd-tap);
  min-width: 0;
  padding: 10px 12px;
  text-align: center;
}

.dd-pin-input::placeholder { letter-spacing: normal; font-size: 0.85rem; font-weight: 600; }
.dd-pin-row .dd-btn { flex: none; width: auto; padding: 11px 18px; }

.dd-chat {
  position: relative;
  margin-top: 8px;
}

.dd-chat-badge {
  background: var(--dd-red);
  border-radius: 999px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  min-width: 20px;
  padding: 2px 6px;
}

/* -------------------------------------------------------------- focus ring */
.dd :focus-visible,
.dd-vehicle:focus-visible,
.dd-btn:focus-visible {
  outline: 3px solid var(--dd-yellow);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- narrow UI */
@media (max-width: 360px) {
  .dd-vehicles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dd-trip-actions { grid-template-columns: 1fr; }
}

/* ===========================================================================
   Ride chat dialog.

   Shared by driver and passenger and by both entry documents. `.hidden-panel`
   is `display: none !important` on both pages, so it still wins over the
   `display: flex` below and stays the single way to hide this dialog.
   =========================================================================== */

.dd-modal {
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 4000;
}

.dd-modal-card {
  background: #141414;
  border: 1px solid #2f2f2f;
  border-radius: 18px 18px 0 0;
  color: #fff;
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 760px);
  padding-bottom: env(safe-area-inset-bottom);
  width: min(560px, 100%);
}

@media (min-width: 600px) {
  .dd-modal { align-items: center; padding: 20px; }
  .dd-modal-card { border-radius: 18px; }
}

.dd-modal-head {
  align-items: center;
  border-bottom: 1px solid #2f2f2f;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 13px 14px;
}

.dd-modal-head-left {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}

.dd-modal-title {
  font-size: 0.95rem;
  font-weight: 800;
  margin: 0;
}

.dd-modal-close {
  background: transparent;
  border: 1px solid #2f2f2f;
  border-radius: 10px;
  color: #d1d5db;
  cursor: pointer;
  flex: none;
  font-family: inherit;
  font-size: 1rem;
  height: 40px;
  line-height: 1;
  width: 40px;
}

.dd-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 140px;
  overflow-y: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.dd-msg { display: flex; max-width: 100%; }
.dd-msg-mine { justify-content: flex-end; }
.dd-msg-system { justify-content: center; }

.dd-bubble {
  background: #1c1c1c;
  border: 1px solid #2f2f2f;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.45;
  max-width: 82%;
  padding: 9px 12px;
  word-break: break-word;
}

.dd-msg-mine .dd-bubble {
  background: rgba(250, 204, 21, 0.14);
  border-color: var(--brand-yellow, #facc15);
}

.dd-msg-system .dd-bubble {
  background: transparent;
  border-style: dashed;
  color: #94a3b8;
  font-size: 0.76rem;
  max-width: 100%;
  text-align: center;
}

.dd-msg-meta {
  color: #94a3b8;
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.dd-chips {
  border-top: 1px solid #2f2f2f;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 10px 14px;
  scrollbar-width: none;
}

.dd-chips::-webkit-scrollbar { display: none; }

.dd-chip {
  background: #1c1c1c;
  border: 1px solid #2f2f2f;
  border-radius: 999px;
  color: #d1d5db;
  cursor: pointer;
  flex: none;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  min-height: 38px;
  padding: 8px 13px;
  white-space: nowrap;
}

.dd-composer {
  border-top: 1px solid #2f2f2f;
  display: flex;
  gap: 8px;
  padding: 11px 14px 14px;
}

.dd-composer-input {
  background: #1c1c1c;
  border: 1.5px solid #2f2f2f;
  border-radius: 12px;
  color: #fff;
  flex: 1;
  font-family: inherit;
  font-size: 0.9rem;
  min-height: 48px;
  min-width: 0;
  padding: 11px 13px;
}

.dd-composer .dd-btn { flex: none; width: auto; padding: 11px 18px; }

.dd-archived {
  background: rgba(148, 163, 184, 0.12);
  border-top: 1px solid #2f2f2f;
  color: #cbd5e1;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.45;
  padding: 11px 14px;
  text-align: center;
}

.dd-modal :focus-visible {
  outline: 3px solid var(--brand-yellow, #facc15);
  outline-offset: 2px;
}
