/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2563EB;
  --blue-light: #EFF6FF;
  --blue-border: #BFDBFE;
  --green: #16A34A;
  --orange: #EA580C;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --shadow: 0 2px 12px rgba(0,0,0,0.1);
  --radius: 16px;
  --navbar-h: 60px;
  --font: -apple-system, "Noto Sans TC", sans-serif;
}

body {
  font-family: var(--font);
  color: var(--gray-900);
  background: var(--gray-50);
  overflow: hidden;
}

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--navbar-h);
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 1000;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--gray-900);
  flex-shrink: 0;
}

.brand-icon {
  width: 32px; height: 32px;
  background: var(--blue);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 16px;
}

.navbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--gray-200);
  background: #fff;
  font-size: 12px;
  color: var(--gray-700);
  white-space: nowrap;
  flex-shrink: 0;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gray-300, #D1D5DB);
}

.status-dot.on { background: var(--green); }

.navbar-settings {
  width: 36px; height: 36px;
  border: none;
  background: var(--gray-100);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-500);
  flex-shrink: 0;
  transition: background 0.15s;
}
.navbar-settings:hover { background: var(--gray-200); }

/* ── Map container ────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  right: 320px;
  bottom: 0;
  z-index: 0;
}

/* ── Float cards on map ───────────────────────────────────────────────────── */
.float-card {
  /* fixed 定位＋讓出 navbar 高度：absolute 對 body 會疊進固定頂部列底下（07-27 破版根因） */
  position: fixed;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 400;
  padding: 16px;
}

.card-event {
  top: calc(var(--navbar-h) + 16px); left: 16px;
  width: 260px;
}

.card-event .label {
  font-size: 11px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.card-event .event-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.card-event .event-time {
  font-size: 22px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 4px;
}

.card-event .event-addr {
  font-size: 12px;
  color: var(--gray-500);
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 12px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
}
.btn-primary:hover { background: #1D4ED8; }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 10px;
  background: #fff;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover { background: var(--blue-light); }

.empty-state {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* Depart card (top-center) */
.card-depart {
  top: calc(var(--navbar-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 320px;
  text-align: center;
}

.card-depart .depart-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
}
.card-depart .depart-row .time { color: var(--blue); }
.card-depart .depart-sub {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 3px;
}

/* Map legend */
.map-legend {
  bottom: 16px; left: 16px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--gray-700);
}
.map-legend ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.map-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
}
.legend-line.drive { background: var(--blue); }
.legend-line.walk {
  background: transparent;
  border-top: 2.5px dashed #16A34A;
}

/* ── Right panel ──────────────────────────────────────────────────────────── */
.panel-right {
  position: fixed;
  top: var(--navbar-h);
  right: 0;
  width: 320px;
  bottom: 0;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,0.06);
  overflow-y: auto;
  padding: 16px;
  z-index: 500;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 12px;
}

/* Parking cards */
.parking-card {
  border: 1.5px solid var(--gray-200);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
}
.parking-card:hover { border-color: var(--blue); }
.lot-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #6B7280;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  margin-right: 6px;
  flex-shrink: 0;
}
.lot-letter.top { background: var(--blue); }
.parking-card.active .lot-letter { background: #F59E0B; }

.parking-card.active {
  background: var(--blue-light);
  border-color: var(--blue);
}
.parking-card.top {
  background: var(--blue-light);
  border-color: var(--blue);
}

.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}
.card-header .lot-rate { margin-left: auto; }

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.brand-badge.uspace { color: var(--blue); }
.brand-badge.autopass { color: var(--orange); }
.brand-badge.general { color: var(--gray-500); }

.lot-rate {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
}

.lot-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 6px;
}

.lot-walk {
  font-size: 12px;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.lot-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
}
.tag.green { background: #DCFCE7; color: #166534; }
.tag.gray { background: var(--gray-100); color: var(--gray-500); }

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s;
}

.btn-sm.solid {
  background: var(--blue);
  color: #fff;
}
.btn-sm.solid:hover { background: #1D4ED8; }

.btn-sm.outline {
  background: #fff;
  color: var(--blue);
  border: 1.5px solid var(--blue);
}
.btn-sm.outline:hover { background: var(--blue-light); }

.btn-sm.ghost {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-sm.ghost:hover { background: var(--gray-200); }

/* Loading state */
.panel-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--gray-400);
  font-size: 14px;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--gray-900);
  z-index: 9999;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s, bottom 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; bottom: 40px; }
.toast.success { background: var(--green); }
.toast.error { background: #DC2626; }

/* ── Login overlay ────────────────────────────────────────────────────────── */
#login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9990;
  align-items: center;
  justify-content: center;
}
#login-overlay.show { display: flex; }

.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  width: 340px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.login-card p { font-size: 14px; color: var(--gray-500); margin-bottom: 20px; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--blue); }

.login-error {
  font-size: 13px;
  color: #DC2626;
  margin-top: 8px;
  display: none;
}
.login-error.show { display: block; }

/* ── Settings page ────────────────────────────────────────────────────────── */
.settings-page {
  min-height: 100vh;
  overflow: auto;
  background: var(--gray-50);
  padding-bottom: 40px;
}
.settings-page .navbar { position: sticky; }
.settings-page body { overflow: auto; }

.settings-body {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px;
}

.settings-section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.settings-section h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--gray-900);
  border-bottom: 1px solid var(--gray-100);
  padding-bottom: 12px;
}

.settings-field {
  margin-bottom: 16px;
}
.settings-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.settings-field input,
.settings-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.settings-field input:focus,
.settings-field textarea:focus { border-color: var(--blue); }

.settings-field input[type="number"] { width: 100px; }

/* Connection status in settings */
.conn-list { display: flex; flex-direction: column; gap: 10px; }
.conn-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  background: var(--gray-50);
}
.conn-item .conn-name {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.conn-status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.conn-status.on { background: #DCFCE7; color: #166534; }
.conn-status.off { background: var(--gray-100); color: var(--gray-500); }

/* Brand priority drag list */
.brand-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
}
.brand-list-item:active { cursor: grabbing; }
.brand-list-item .drag-handle { color: var(--gray-400); }

.btn-move {
  padding: 3px 8px;
  border: none;
  background: var(--gray-200);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  margin-left: auto;
}
.btn-move:hover { background: var(--gray-300, #D1D5DB); }

/* Save bar */
.save-bar {
  margin-top: 24px;
  text-align: right;
}

/* ── Mobile (≤ 768px) ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { overflow: auto; }

  #map {
    right: 0;
    bottom: 200px;
    position: fixed;
  }

  .panel-right {
    top: auto;
    width: 100%;
    height: 200px;
    left: 0;
    right: 0;
    bottom: 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .panel-scroll-x {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    flex: 1;
    padding: 0 0 8px 0;
    scroll-snap-type: x mandatory;
  }

  .parking-card {
    min-width: 240px;
    flex-shrink: 0;
    scroll-snap-align: start;
    margin-bottom: 0;
  }

  .card-event {
    width: calc(100vw - 32px);
    max-width: 300px;
  }

  #today-list {
    max-height: 120px; /* 手機上限縮清單高度，避免卡片擋住地圖 */
  }

  .card-depart {
    display: none;
  }

  .navbar-status {
    display: none;
  }

  .map-legend {
    bottom: 216px; /* 讓出底部 200px 停車卡列 */
  }
}

/* ── Score breakdown (卡片內評分明細) ──────────────────────────────────────── */
.score-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--gray-500);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  margin-top: 4px;
  line-height: 1.4;
}
.score-toggle:hover { color: var(--blue); }
.score-toggle .toggle-arrow { transition: transform 0.2s; display: inline-block; }
.score-toggle.open .toggle-arrow { transform: rotate(180deg); }

.score-breakdown {
  display: none;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 11px;
  color: var(--gray-700);
}
.score-breakdown.open { display: block; }

.score-breakdown table {
  width: 100%;
  border-collapse: collapse;
}
.score-breakdown td {
  padding: 2px 4px;
  vertical-align: middle;
}
.score-breakdown td:nth-child(2),
.score-breakdown td:nth-child(3),
.score-breakdown td:nth-child(4) {
  text-align: right;
  color: var(--gray-500);
  white-space: nowrap;
}
.score-breakdown tr.total-row td {
  border-top: 1px solid var(--gray-200);
  padding-top: 4px;
  font-weight: 600;
  color: var(--gray-900);
}

/* ── Rank-weights sliders (設定頁) ─────────────────────────────────────────── */
.weight-row {
  display: grid;
  grid-template-columns: 80px 1fr 48px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.weight-row label {
  font-size: 13px;
  color: var(--gray-700);
  white-space: nowrap;
}
.weight-row input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}
.weight-pct {
  font-size: 12px;
  color: var(--blue);
  font-weight: 600;
  text-align: right;
}

/* ── 今日行程清單（card-event 內，點選切換主卡片） ─────────────────────────── */
#today-list {
  margin: 4px 0 8px;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 6px;
  max-height: 168px;
  overflow-y: auto;
}
.today-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--gray-700);
  cursor: pointer;
}
.today-item:hover { background: var(--gray-100); }
.today-item.active {
  background: #EFF6FF;
  color: var(--blue);
  font-weight: 600;
}
.today-item.past { opacity: 0.45; }
.today-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  flex-shrink: 0;
}
.today-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.today-noaddr {
  flex-shrink: 0;
  font-size: 10px;
  color: #B45309;
  background: #FEF3C7;
  border-radius: 4px;
  padding: 1px 5px;
}
.today-empty {
  font-size: 12px;
  color: var(--gray-400);
  padding: 2px 6px 4px;
}
