:root {
  color-scheme: light;
  --bg: #eef2f4;
  --ink: #111c24;
  --muted: #66737f;
  --line: #d3dce2;
  --panel: #ffffff;
  --road: #29343d;
  --road-edge: #1c252c;
  --lane-line: rgba(255, 255, 255, 0.5);
  --fast: #ffbf2f;
  --fast-ink: #211500;
  --accent: #00796b;
  --accent-strong: #005d52;
  --blue: #2e67b1;
  --danger: #b42318;
  --warn: #b46a12;
  --shadow: 0 14px 30px rgba(21, 32, 43, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
select {
  font: inherit;
}

.shell {
  width: min(1360px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

.admin-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 18px;
}

.admin-topbar h1 {
  font-size: 2.4rem;
}

.admin-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.admin-card {
  display: grid;
  gap: 8px;
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.admin-card span,
.admin-card small {
  color: var(--muted);
  font-weight: 800;
}

.admin-card strong {
  font-size: 1.35rem;
}

.correction-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.correction-panel,
.correction-preview {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.field textarea {
  resize: vertical;
  line-height: 1.45;
}

.quick-cameras {
  display: flex;
  gap: 8px;
  margin: -5px 0 14px;
  flex-wrap: wrap;
}

.quick-cameras button,
#saveCorrectionButton {
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.quick-cameras button {
  border: 1px solid rgba(0, 121, 107, 0.28);
  background: #f6fffc;
  color: var(--accent-strong);
}

.lane-checkboxes {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lane-checkboxes legend {
  padding: 0 4px;
}

.lane-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--ink);
}

.lane-checkboxes input {
  width: auto;
  min-height: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.form-status {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-head span {
  color: var(--muted);
  font-weight: 900;
}

.preview-head strong {
  display: block;
  margin-top: 3px;
  font-size: 1.35rem;
}

.correction-preview img {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: 8px;
  background: #101820;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.history-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.history-item div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.history-item p {
  margin: 8px 0 0;
  font-weight: 900;
}

.history-item small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

h1 {
  margin: 4px 0 0;
  font-size: 3.6rem;
  line-height: 1.03;
  letter-spacing: 0;
}

.status-group {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 110px;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(180, 106, 18, 0.16);
}

.status-dot.online {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 121, 107, 0.16);
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.14);
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 140px 120px minmax(180px, 1fr) 76px;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

.select-wrap {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.select-wrap select {
  width: 100%;
  min-height: 42px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

#refreshButton {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

#refreshButton:hover {
  background: var(--accent-strong);
}

#refreshButton:disabled {
  cursor: wait;
  background: #8aa49f;
}

.secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.secondary-button:hover {
  background: #f6f9fb;
}

.secondary-button.tracking-active {
  border-color: rgba(180, 35, 24, 0.3);
  background: #fff1ee;
  color: var(--danger);
}

.route-stat {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: var(--muted);
  font-weight: 800;
}

.admin-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.admin-link:hover {
  background: #f6f9fb;
}

.driver-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(0, 121, 107, 0.22);
  border-radius: 8px;
  background: #f6fffc;
  box-shadow: 0 8px 18px rgba(21, 32, 43, 0.08);
}

.driver-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.driver-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 1.8rem;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.driver-meta {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 440px;
}

.driver-meta span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 0.84rem;
}

.scan-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 18px rgba(21, 32, 43, 0.08);
}

.scan-strip strong {
  display: block;
  font-size: 1rem;
}

.scan-strip span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.scan-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.scan-concurrency {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.scan-concurrency select {
  min-height: 38px;
  min-width: 74px;
  padding: 0 24px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.scan-actions button {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.scan-actions .secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: stretch;
}

.road-scroll,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.road-scroll {
  max-height: 74vh;
  min-height: 560px;
  overflow-x: hidden;
  overflow-y: auto;
  border-width: 2px;
  border-color: #b8c7d1;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.78),
    var(--shadow);
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
  scrollbar-gutter: stable both-edges;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.direction-grid {
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
}

.direction-header-row,
.mile-row {
  display: grid;
  grid-template-columns: repeat(var(--direction-count, 2), minmax(0, 1fr));
}

.direction-switcher {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px 76px;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.direction-nav {
  width: 44px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.direction-nav:disabled {
  cursor: default;
  opacity: 0.35;
}

.mile-order-toggle {
  min-height: 42px;
  border: 1px solid rgba(46, 103, 177, 0.28);
  border-radius: 6px;
  background: #f7fbff;
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}

.mile-order-toggle:hover {
  background: #eaf3ff;
}

.active-direction {
  min-width: 0;
  text-align: center;
}

.active-direction span,
.active-direction small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.active-direction strong {
  display: block;
  margin-top: 1px;
  font-size: 1.34rem;
  line-height: 1.08;
}

.direction-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.direction-header:last-child {
  border-right: 0;
}

.direction-header span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.direction-header strong {
  display: block;
  margin-top: 2px;
  font-size: 1.35rem;
}

.lane-count {
  color: var(--blue);
  font-weight: 900;
}

.direction-slot {
  min-width: 0;
  padding: 6px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid #edf1f3;
}

.direction-slot:last-child {
  border-right: 0;
}

.camera-stack {
  display: grid;
  gap: 6px;
}

.empty-slot {
  min-height: 72px;
  display: flex;
  align-items: center;
  color: transparent;
  user-select: none;
}

.empty-slot span {
  display: none;
}

.camera-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 48px 38px;
  align-items: stretch;
  gap: 8px;
  min-height: 72px;
  padding: 4px 0;
  cursor: pointer;
}

.camera-row.current {
  background: #fff7df;
  outline: 2px solid rgba(255, 191, 47, 0.85);
  outline-offset: -2px;
}

.camera-row:hover {
  background: #f6f9fb;
}

.camera-row.current:hover {
  background: #fff7df;
}

.mile-marker {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.mile-marker strong {
  font-size: 1.03rem;
  line-height: 1;
}

.mile-marker span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.lane-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  min-height: 58px;
  border: 4px solid var(--road-edge);
  border-radius: 7px;
  overflow: hidden;
  background: var(--road);
}

.camera-actions {
  display: flex;
  align-items: center;
  justify-content: center;
}

.same-direction-scan {
  width: 46px;
  min-height: 42px;
  border: 1px solid rgba(0, 121, 107, 0.34);
  border-radius: 6px;
  background: #f6fffc;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.same-direction-scan:hover {
  background: #e5f8f2;
}

.same-direction-scan:disabled {
  cursor: wait;
  border-color: var(--line);
  background: #edf3f5;
  color: var(--muted);
}

.lane-track.inner-left {
  border-left-color: var(--fast);
}

.lane-track.inner-right {
  border-right-color: var(--fast);
}

.road-lane {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-right: 1px dashed var(--lane-line);
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.82rem;
  font-weight: 900;
}

.road-lane:last-child {
  border-right: 0;
}

.road-lane.fastest {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), rgba(255, 191, 47, 0.28)),
    var(--fast);
  color: var(--fast-ink);
  box-shadow: inset 0 0 0 2px rgba(80, 52, 0, 0.24);
}

.road-lane.excluded {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.20) 0 7px, transparent 7px 14px),
    #5d6770;
  color: transparent;
}

.road-lane.analyzing {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.24) 0 8px, transparent 8px 16px),
    #3d4d59;
  color: #fff;
}

.road-lane.fastest strong {
  font-size: 0.78rem;
  line-height: 1;
}

.road-lane.fastest small {
  display: block;
  margin-top: 3px;
  font-size: 0.68rem;
  line-height: 1;
}

.camera-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-pin {
  position: relative;
  width: 31px;
  height: 24px;
  border-radius: 6px;
  background: var(--blue);
  box-shadow: 0 5px 12px rgba(46, 103, 177, 0.28);
}

.camera-pin::before {
  content: "";
  position: absolute;
  left: 5px;
  top: -5px;
  width: 12px;
  height: 6px;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
}

.camera-pin span {
  position: absolute;
  left: 10px;
  top: 6px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 999px;
}

.camera-pin.active {
  background: #d97706;
  box-shadow: 0 0 0 5px rgba(255, 191, 47, 0.24), 0 8px 16px rgba(161, 98, 7, 0.28);
}

.camera-pin.active::before {
  background: #d97706;
}

.camera-pin.analyzed:not(.active) {
  background: var(--accent);
  box-shadow: 0 5px 12px rgba(0, 121, 107, 0.24);
}

.camera-pin.analyzed:not(.active)::before {
  background: var(--accent);
}

.camera-pin.nearest {
  box-shadow: 0 0 0 5px rgba(46, 103, 177, 0.2), 0 0 0 9px rgba(255, 191, 47, 0.22);
}

.detail-panel {
  align-self: start;
  overflow: hidden;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.detail-head span {
  color: var(--muted);
  font-weight: 900;
}

.detail-head strong {
  font-size: 1.4rem;
}

.detail-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #101820;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-grid div {
  min-height: 76px;
  padding: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-grid div:nth-child(2n) {
  border-right: 0;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.metric-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1.15rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.lane-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  font-weight: 800;
}

.lane-rank {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.lane-rank.fastest {
  border-color: rgba(217, 119, 6, 0.72);
  background: #fff7df;
}

.lane-rank.excluded {
  border-color: rgba(100, 116, 139, 0.45);
  background: #f8fafc;
  color: #64748b;
}

.lane-rank-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.92rem;
}

.lane-rank-head strong,
.lane-rank-head span {
  font-weight: 900;
}

.rank-bar {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8eb;
}

.rank-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.lane-rank.fastest .rank-bar span {
  background: #d97706;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 2.6rem;
  }

  .control-strip,
  .map-layout,
  .admin-nav,
  .correction-layout {
    grid-template-columns: 1fr;
  }

  .admin-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scan-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .driver-strip {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .driver-strip strong {
    font-size: 1.45rem;
  }

  .driver-meta {
    justify-content: flex-start;
    max-width: none;
  }

  .route-stat {
    justify-content: flex-start;
  }

  .road-scroll {
    min-height: 500px;
    max-height: 70vh;
  }

  .detail-panel {
    align-self: stretch;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 18px, 1360px);
    padding-top: 10px;
  }

  h1 {
    font-size: 2.1rem;
  }

  .direction-grid {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .direction-switcher {
    grid-template-columns: 38px minmax(0, 1fr) 38px 62px;
    min-height: 56px;
    padding: 8px 6px;
    gap: 5px;
  }

  .direction-nav {
    width: 38px;
    height: 38px;
    font-size: 1.35rem;
  }

  .active-direction strong {
    font-size: 1.05rem;
  }

  .mile-order-toggle {
    min-height: 38px;
    font-size: 0.7rem;
    padding: 0 4px;
  }

  .direction-header {
    min-height: 54px;
    padding: 8px 6px;
  }

  .direction-header strong {
    font-size: 1rem;
  }

  .lane-count {
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .direction-slot {
    padding: 5px 4px;
  }

  .camera-row {
    grid-template-columns: 52px minmax(0, 1fr) 40px 24px;
    gap: 4px;
    min-height: 62px;
  }

  .same-direction-scan {
    width: 38px;
    min-height: 36px;
    padding: 0;
    font-size: 0.68rem;
  }

  .mile-marker strong {
    font-size: 0.78rem;
  }

  .mile-marker span,
  .camera-pin::before {
    display: none;
  }

  .lane-track {
    min-height: 48px;
    border-width: 3px;
  }

  .road-lane {
    font-size: 0.62rem;
  }

  .road-lane.fastest {
    color: transparent;
  }

  .road-lane.fastest::after {
    content: "";
    width: 9px;
    height: 30px;
    border-radius: 999px;
    background: rgba(33, 21, 0, 0.86);
  }

  .road-lane.excluded {
    color: transparent;
  }

  .road-lane.excluded::after {
    content: "";
    width: 9px;
    height: 30px;
    border-radius: 999px;
    background:
      repeating-linear-gradient(180deg, #fff 0 4px, transparent 4px 8px),
      rgba(15, 23, 42, 0.56);
  }

  .camera-pin {
    width: 22px;
    height: 20px;
    border-radius: 5px;
  }

  .camera-pin span {
    left: 7px;
    top: 5px;
    width: 8px;
    height: 8px;
    border-width: 1px;
  }
}
