:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #14171c;
  --muted: #6b7280;
  --line: #e3e5ea;
  --orange: #f5821f;
  --orange-ink: #7a3d0a;
  --blue: #142850;
  --blue-soft: #eaf0fb;
  --green: #1b8a5a;
  --green-soft: #e7f6ee;
  --red: #c0392b;
  --red-soft: #fbeae8;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 4px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* Topbar */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--blue);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--orange), #ffb066);
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 0.95rem; }
.brand-text small { color: #b9c4dd; font-size: 0.72rem; }
.status-cluster { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill-online { background: var(--green-soft); color: var(--green); }
.pill-offline { background: var(--red-soft); color: var(--red); }
.pill-pending { background: #fff2e2; color: var(--orange-ink); }
.pill-done { background: var(--green-soft); color: var(--green); }
.pill-locked { background: #eceef2; color: var(--muted); }

.btn-ghost {
  background: transparent;
  border: 1px solid #3a4a70;
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Layout */
#app { max-width: 640px; margin: 0 auto; padding: 16px; padding-block: 16px; }
.view { display: none; }
.view.active { display: block; }

.hero { padding: 8px 4px 20px; }
.hero h1 { font-size: 1.5rem; }

.role-grid { display: grid; gap: 12px; }
.role-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 2px rgba(20,23,28,0.04);
}
.role-icon { font-size: 1.6rem; }
.role-title { font-weight: 700; font-size: 1.02rem; }
.role-desc { color: var(--muted); font-size: 0.85rem; }

.back-link {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 600;
  padding: 0;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 0.9rem;
}

.segmented {
  display: flex;
  background: #eceef2;
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 16px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 8px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.seg-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

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

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: #333; }
.form input, .form select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.form input:focus { outline: 2px solid var(--orange); outline-offset: 1px; }

.btn-primary {
  background: var(--orange);
  color: #1a0e00;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
  background: var(--blue-soft);
  color: var(--blue);
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}
.btn-small {
  background: #eceef2;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}

.field-error { color: var(--red); font-size: 0.82rem; }

.hint { margin-top: 4px; font-size: 0.85rem; color: var(--muted); }
.hint summary { cursor: pointer; font-weight: 600; }
.hint-body { padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.seed-item {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

/* Driver process card */
.process-card { display: flex; flex-direction: column; gap: 8px; }
.process-card .proc-title { font-size: 1.05rem; font-weight: 700; }
.process-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 6px; }
.proc-field { font-size: 0.82rem; }
.proc-field span { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }

.section-title { font-size: 0.95rem; margin: 18px 0 10px; }

/* Step list */
.step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.step-item.locked { opacity: 0.55; }
.step-item.current { border-color: var(--orange); box-shadow: 0 0 0 1px var(--orange); }
.step-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.step-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; }
.step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: #eceef2; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.step-item.done .step-num { background: var(--green-soft); color: var(--green); }
.step-item.current .step-num { background: var(--orange); color: #fff; }
.step-meta { font-size: 0.78rem; color: var(--muted); }
.step-thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.step-thumbs img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.sync-tag { font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.sync-tag.pending { background: #fff2e2; color: var(--orange-ink); }
.sync-tag.synced { background: var(--green-soft); color: var(--green); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,12,16,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50; padding: 0;
}
.modal-backdrop[hidden] { display: none; }
[hidden] { display: none !important; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: #eceef2; border: none; border-radius: 50%;
  width: 30px; height: 30px; font-size: 0.9rem; cursor: pointer;
}
.modal-block { margin: 16px 0; }
.modal-block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 700; font-size: 0.88rem; }
#gpsResult { margin-top: 6px; }

.photo-slot { margin-bottom: 14px; }
.photo-slot-label { font-weight: 700; font-size: 0.85rem; margin-bottom: 6px; display: block; }
.photo-input-row { display: flex; align-items: center; gap: 10px; }
.photo-preview { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: #f0f1f4; }
.photo-input-row input[type=file] { font-size: 0.78rem; max-width: 170px; }

/* Office */
.office-tab { display: block; }
.office-tab[hidden] { display: none; }
.proc-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
}
.proc-row-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.proc-row-head strong { font-size: 0.92rem; }
.proc-row .muted { font-size: 0.78rem; }
.status-chip { font-size: 0.7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.status-chip.complete { background: var(--green-soft); color: var(--green); }

.client-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px;
}
.client-row-head { display: flex; justify-content: space-between; align-items: center; }
.client-row-head strong { font-size: 0.9rem; }
.email-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eceef2; border-radius: 999px; padding: 4px 10px; font-size: 0.78rem; margin: 6px 6px 0 0;
}
.email-chip button { background: none; border: none; color: var(--red); cursor: pointer; font-size: 0.85rem; padding: 0; }

.notif-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; font-size: 0.85rem;
}
.notif-item .notif-time { color: var(--muted); font-size: 0.74rem; }
.notif-item .notif-to { color: var(--blue); font-size: 0.78rem; margin-top: 4px; }

.timeline { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.timeline-item { border-left: 2px solid var(--line); padding-left: 14px; position: relative; }
.timeline-item::before {
  content: ""; position: absolute; left: -6px; top: 2px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--orange);
}
.timeline-item.pending-dot::before { background: #ccc; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 0.85rem; z-index: 100; max-width: 88vw; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

@media (min-width: 640px) {
  .process-grid { grid-template-columns: 1fr 1fr 1fr; }
}
