/* ==========================================================================
   Sharco Express — Driver App (Web prototype)
   Mobile-first, high-contrast for in-cab / sunlight readability.
   Large tap targets for BYOD use (drivers, gloves, motion).
   ========================================================================== */

:root {
  /* Brand */
  --brand:        #ff7a1a;   /* Sharco amber/orange accent */
  --brand-ink:    #1a1005;
  --blue:         #2f7bf6;
  --blue-deep:    #0b1424;

  /* Surfaces (dark, in-cab friendly) */
  --bg:           #070d18;
  --surface:      #0f1a2c;
  --surface-2:    #16233a;
  --surface-3:    #1e2f4a;
  --line:         #263650;
  --line-soft:    #1a2942;

  /* Text */
  --text:         #eaf1ff;
  --text-dim:     #9fb0cc;
  --text-faint:   #64748b;

  /* Status */
  --ok:           #2fbf71;
  --warn:         #ffb020;
  --danger:       #ff5c5c;
  --info:         #38bdf8;

  --radius:       16px;
  --radius-sm:    10px;
  --tap:          52px;      /* minimum tap target */
  --pad:          16px;

  --shadow:       0 8px 30px rgba(0,0,0,.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The [hidden] attribute must win over component display rules (flex/grid). */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: #05080f;
  color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ------- Device frame (desktop) ------- */
.device-frame {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
  background:
    radial-gradient(1200px 700px at 50% -10%, #14213a 0%, #070d18 60%, #05080f 100%);
}
@media (min-width: 720px) {
  .device-frame { padding: 28px; }
  .app {
    width: 402px;
    height: 858px;
    border-radius: 44px;
    box-shadow: var(--shadow), 0 0 0 12px #10151f, 0 0 0 14px #232a38;
    overflow: hidden;
  }
}

.app {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* ------- Top bar ------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) var(--pad) 12px;
  background: linear-gradient(180deg, var(--surface) 0%, rgba(15,26,44,.85) 100%);
  border-bottom: 1px solid var(--line-soft);
  z-index: 5;
}
.topbar__title { display: flex; flex-direction: column; line-height: 1.1; flex: 1; min-width: 0; }
.topbar__title > span:first-child { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.topbar__subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.conn-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(47,191,113,.12); color: var(--ok);
  border: 1px solid rgba(47,191,113,.35);
  white-space: nowrap;
}
.conn-pill.offline { background: rgba(255,176,32,.12); color: var(--warn); border-color: rgba(255,176,32,.4); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }

/* ------- View / scroll area ------- */
.view {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}
.view::-webkit-scrollbar { width: 0; }

/* ------- Bottom tab bar ------- */
.tabbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 5;
}
.tab {
  position: relative;
  appearance: none; border: 0; background: transparent;
  color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 2px; border-radius: 12px; cursor: pointer;
  font: inherit; font-size: 10.5px; font-weight: 600;
  min-height: var(--tap);
  transition: color .15s, background .15s;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--brand); }
.tab:active { background: var(--surface-2); }
.tab__badge {
  position: absolute; top: 4px; right: calc(50% - 22px);
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 800;
  border-radius: 999px; display: grid; place-items: center; font-style: normal;
}

/* ------- Buttons ------- */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 15px; width: 100%;
  background: var(--surface-3); color: var(--text);
  transition: transform .06s, filter .15s, background .15s;
}
.btn:active { transform: scale(.985); }
.btn--primary { background: var(--brand); color: var(--brand-ink); }
.btn--blue { background: var(--blue); color: #fff; }
.btn--ok { background: var(--ok); color: #05230f; }
.btn--ghost { background: transparent; border: 1.5px solid var(--line); color: var(--text); }
.btn--danger { background: transparent; border: 1.5px solid rgba(255,92,92,.5); color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--sm { min-height: 40px; font-size: 13px; padding: 0 14px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: 100%; }

.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
}
.icon-btn::before { content: "‹"; font-size: 26px; line-height: 1; margin-top: -3px; }

/* ------- Cards & layout ------- */
.stack { padding: var(--pad); display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
}
.card--flush { padding: 0; overflow: hidden; }
.section-label { font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--text-faint); margin: 4px 2px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.row { display: flex; align-items: center; gap: 12px; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.divider { height: 1px; background: var(--line-soft); margin: 4px 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------- Badges / chips ------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 800; letter-spacing: .3px;
  padding: 5px 9px; border-radius: 999px; text-transform: uppercase;
  background: var(--surface-3); color: var(--text-dim);
}
.badge--ok { background: rgba(47,191,113,.14); color: var(--ok); }
.badge--warn { background: rgba(255,176,32,.14); color: var(--warn); }
.badge--danger { background: rgba(255,92,92,.14); color: var(--danger); }
.badge--info { background: rgba(56,189,248,.14); color: var(--info); }
.badge--brand { background: rgba(255,122,26,.16); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ------- Load list ------- */
.load-card { display: block; text-align: left; width: 100%; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 0; overflow: hidden; cursor: pointer; }
.load-card:active { border-color: var(--line); }
.load-card__top { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line-soft); }
.load-card__id { font-weight: 800; font-size: 15px; }
.load-card__body { padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }

/* Route stops (pickup -> delivery timeline) */
.stops { position: relative; display: flex; flex-direction: column; gap: 14px; padding-left: 26px; }
.stops::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.stop { position: relative; }
.stop::before { content: ""; position: absolute; left: -26px; top: 3px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--bg); }
.stop--pickup::before { background: var(--blue); }
.stop--delivery::before { background: var(--brand); }
.stop__type { font-size: 11px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; color: var(--text-faint); }
.stop__place { font-weight: 700; font-size: 14.5px; margin-top: 1px; }
.stop__addr { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.stop__time { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }

.load-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-chip { font-size: 12px; color: var(--text-dim); background: var(--surface-2); border-radius: 8px; padding: 5px 9px; display: inline-flex; gap: 6px; align-items: center; }
.meta-chip b { color: var(--text); font-weight: 700; }

/* ------- Key/value info ------- */
.kv { display: flex; flex-direction: column; gap: 12px; }
.kv__row { display: flex; justify-content: space-between; gap: 16px; }
.kv__k { color: var(--text-dim); font-size: 13px; }
.kv__v { font-weight: 600; font-size: 14px; text-align: right; }

/* ------- Status stepper ------- */
.status-steps { display: flex; flex-direction: column; gap: 0; }
.status-step { display: flex; gap: 14px; align-items: flex-start; padding: 4px 0; }
.status-step__marker { position: relative; flex: 0 0 auto; width: 22px; display: flex; justify-content: center; }
.status-step__marker::after { content: ""; position: absolute; top: 22px; bottom: -14px; width: 2px; background: var(--line); }
.status-step:last-child .status-step__marker::after { display: none; }
.status-step__dot { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); border: 2px solid var(--line); display: grid; place-items: center; z-index: 1; }
.status-step.done .status-step__dot { background: var(--ok); border-color: var(--ok); color: #05230f; }
.status-step.current .status-step__dot { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 0 0 4px rgba(255,122,26,.2); }
.status-step__dot svg { width: 12px; height: 12px; stroke: currentColor; stroke-width: 3; fill: none; }
.status-step__label { padding-bottom: 14px; }
.status-step__name { font-weight: 700; font-size: 14.5px; }
.status-step.pending .status-step__name { color: var(--text-faint); font-weight: 600; }
.status-step__time { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ------- HOS clocks ------- */
.clock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.clock { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px; }
.clock__label { font-size: 11px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--text-faint); }
.clock__time { font-size: 26px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.clock__bar { height: 6px; border-radius: 999px; background: var(--surface-3); margin-top: 10px; overflow: hidden; }
.clock__fill { height: 100%; border-radius: 999px; background: var(--ok); }
.clock__fill.warn { background: var(--warn); }
.clock__fill.danger { background: var(--danger); }
.duty-banner { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: var(--radius); }
.duty-banner__status { font-size: 20px; font-weight: 800; }

/* ------- Messages ------- */
.msg-list { display: flex; flex-direction: column; }
.msg-thread { display: flex; gap: 12px; padding: 14px var(--pad); border-bottom: 1px solid var(--line-soft); cursor: pointer; background: transparent; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; color: inherit; font: inherit; }
.msg-thread:active { background: var(--surface); }
.avatar { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 800; font-size: 15px; color: var(--text); }
.avatar--dispatch { background: linear-gradient(135deg, var(--blue), #1b4ea8); color: #fff; }
.msg-thread__meta { display: flex; justify-content: space-between; align-items: baseline; }
.msg-thread__name { font-weight: 700; font-size: 14.5px; }
.msg-thread__time { font-size: 11px; color: var(--text-faint); }
.msg-thread__preview { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.msg-thread.unread .msg-thread__preview { color: var(--text); font-weight: 600; }
.unread-dot { width: 9px; height: 9px; background: var(--brand); border-radius: 50%; flex: 0 0 auto; align-self: center; }

/* Conversation */
.chat { display: flex; flex-direction: column; gap: 10px; padding: var(--pad); }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 16px; font-size: 14.5px; line-height: 1.35; position: relative; }
.bubble__time { display: block; font-size: 10.5px; margin-top: 4px; opacity: .7; }
.bubble--in { background: var(--surface-2); border-bottom-left-radius: 5px; align-self: flex-start; }
.bubble--out { background: var(--blue); color: #fff; border-bottom-right-radius: 5px; align-self: flex-end; }
.chat-compose { display: flex; gap: 8px; padding: 10px var(--pad) max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.chat-compose input { flex: 1; }

/* ------- Forms / inputs ------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 14px; width: 100%; outline: none; min-height: var(--tap);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); background: var(--surface-3); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* ------- Login ------- */
.login { display: flex; flex-direction: column; min-height: 100%; padding: 0 24px 24px; }
.login__brand { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12dvh 0 6dvh; }
.logo-badge { width: 96px; height: 96px; border-radius: 22px; background: #fff; display: grid; place-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); overflow: hidden; }
.logo-badge img { width: 100%; height: 100%; object-fit: contain; }
.login__title { font-size: 24px; font-weight: 800; }
.login__sub { color: var(--text-dim); font-size: 14px; margin-top: -6px; }
.login__form { display: flex; flex-direction: column; gap: 16px; }
.login__hint { text-align: center; color: var(--text-faint); font-size: 12.5px; margin-top: 4px; }

/* ------- POD capture ------- */
.capture-tile { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; background: var(--surface); cursor: pointer; }
.capture-tile svg { width: 34px; height: 34px; stroke: var(--brand); fill: none; stroke-width: 1.8; }
.capture-tile__title { font-weight: 700; }
.capture-tile__sub { font-size: 12.5px; color: var(--text-faint); }
.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line-soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb__x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 0; cursor: pointer; font-size: 15px; line-height: 1; display: grid; place-items: center; }
.thumb__tag { position: absolute; bottom: 4px; left: 4px; font-size: 9px; font-weight: 800; letter-spacing: .5px; background: rgba(47,191,113,.9); color: #05230f; padding: 2px 5px; border-radius: 5px; }
.thumb__adj { position: absolute; bottom: 4px; right: 4px; font: inherit; font-size: 10px; font-weight: 700; border: 0; cursor: pointer; background: rgba(0,0,0,.62); color: #fff; padding: 3px 7px; border-radius: 6px; }

/* Manual corner-crop editor (overlay) */
.crop-editor { position: absolute; inset: 0; z-index: 60; background: #05080f; display: flex; flex-direction: column; align-items: center; }
.crop-editor__bar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: max(12px, env(safe-area-inset-top)) var(--pad) 12px; border-bottom: 1px solid var(--line); }
.crop-editor__title { font-size: 13px; color: var(--text-dim); text-align: center; flex: 1; }
.crop-stage { position: relative; margin: auto; touch-action: none; }
.crop-stage #cropImg { display: block; border-radius: 6px; }
.crop-stage #cropSvg { position: absolute; inset: 0; pointer-events: none; }
.crop-stage #cropSvg polygon { fill: rgba(255,122,26,.16); stroke: var(--brand); stroke-width: 2; }
.crop-handle { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: rgba(255,122,26,.25); border: 2.5px solid var(--brand); box-shadow: 0 0 0 2px rgba(0,0,0,.4); cursor: grab; touch-action: none; }
.crop-handle::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--brand); }
.crop-editor__actions { width: 100%; display: flex; gap: 10px; justify-content: center; padding: 12px var(--pad) max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.crop-editor__actions .btn { width: auto; }

/* Segmented control (scan mode selector) */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg { appearance: none; border: 0; background: transparent; color: var(--text-dim); font: inherit; font-weight: 700; font-size: 13px; padding: 9px 0; border-radius: 9px; cursor: pointer; min-height: 40px; }
.seg.on { background: var(--brand); color: var(--brand-ink); }

/* Sent-document row thumbnail */
.doc-thumb { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 10px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 22px; border: 1px solid var(--line-soft); }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Chat image attachment */
.bubble__img { display: block; width: 100%; max-width: 220px; border-radius: 10px; margin-bottom: 6px; }
.attach-btn { flex: 0 0 auto; }
.attach-btn::before { content: "📎"; font-size: 18px; margin: 0; }
.sig-pad { width: 100%; height: 180px; background: #f7fafc; border-radius: var(--radius-sm); touch-action: none; display: block; }

/* ------- Empty states ------- */
.empty { text-align: center; padding: 48px 24px; color: var(--text-faint); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty svg { width: 48px; height: 48px; stroke: var(--line); fill: none; stroke-width: 1.6; }

/* ------- Toast + sync banner ------- */
.toast {
  position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: #05224a; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); z-index: 50;
  max-width: 86%; text-align: center; border: 1px solid rgba(255,255,255,.08);
  animation: toastIn .2s ease;
}
.toast--ok { background: #063a1e; border-color: rgba(47,191,113,.4); }
.toast--warn { background: #3d2c05; border-color: rgba(255,176,32,.4); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

.sync-banner {
  position: absolute; left: 12px; right: 12px; bottom: 88px;
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 10px;
  font-size: 13px; z-index: 40; box-shadow: var(--shadow);
}
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--brand); animation: spin .7s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* pending sync pill on cards */
.pending-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: var(--warn); }

/* fade-in for view transitions */
.view > * { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* utility */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.text-danger { color: var(--danger); } .text-warn { color: var(--warn); } .text-ok { color: var(--ok); }
.center { text-align: center; }

/* Six tabs need a touch less room per cell than five. */
.tab { font-size: 10px; padding: 8px 1px; }
.tab svg { width: 22px; height: 22px; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Fuel screen -------------------------------------------------------- */
.fuel-hero__row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.fuel-hero__pump { font-size: 26px; line-height: 1; }
.fuel-stop { padding: 12px 14px; }
.fuel-stop--on { border-color: rgba(47,191,113,.5); box-shadow: 0 0 0 1px rgba(47,191,113,.25) inset; }
.fuel-stop__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.fuel-stop__name { font-weight: 700; font-size: 14px; }
.fuel-stop__ex { font-weight: 800; font-size: 20px; color: var(--ok); white-space: nowrap; text-align: right; }
.fuel-stop__ex span { display: block; font-size: 10px; font-weight: 600; color: var(--text-faint); letter-spacing: .3px; }
.fuel-stop__sub { font-size: 12px; margin-top: 2px; }
.fuel-stop__meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.fuel-stop__meta .mono { font-size: 12.5px; }
.fuel-stop__badges { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.fuel-note { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(56,189,248,.1);
  border: 1px solid rgba(56,189,248,.28); color: var(--info); font-size: 12px; line-height: 1.35; }
.pill-sample { display: inline-flex; align-items: center; font-size: 10px; font-weight: 800; letter-spacing: .3px;
  text-transform: uppercase; padding: 3px 7px; border-radius: 999px; background: var(--surface-2);
  color: var(--text-faint); border: 1px dashed var(--line); }
