:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 1.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}
.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.mock-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--warning);
  color: var(--bg);
  border-radius: 4px;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 0;
  padding: 0 1rem 0.5rem;
}
.tabs .tab {
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  border-radius: 0;
}
.tabs .tab:hover {
  color: var(--text);
}
.tabs .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.btn-viewport {
  margin-left: auto;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  background: var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  white-space: nowrap;
}
.btn-viewport:hover {
  background: var(--accent);
  color: var(--bg);
}

/* 手機模擬模式 (iPhone 14 — 390×844) */
body.mobile-sim {
  max-width: 390px;
  max-height: 844px;
  margin: 0 auto;
  border: 2px solid var(--border);
  overflow-y: auto;
}

.map-section {
  flex: 1;
  position: relative;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.map-section.hidden {
  display: none;
}
.map {
  flex: 1;
  min-height: 320px;
  width: 100%;
  background: var(--surface);
}
.map-loading,
.zoom-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 500;
}
.stop-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}
.stop-panel[hidden] {
  display: none;
}
.stop-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.stop-panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stop-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.btn-sort {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: var(--border);
  color: var(--text-muted);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sort:hover {
  background: var(--accent);
  color: var(--bg);
}
.panel-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  border-radius: 4px;
}
.panel-close:hover {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}
.stop-panel-buses {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
}
.bus-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}
.bus-row:last-child {
  border-bottom: none;
}
.bus-row .route-name {
  font-weight: 600;
  min-width: 3em;
}
.bus-row .destination {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.bus-row .eta {
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
}
.bus-row .eta.status {
  color: var(--warning);
}
.bus-row .eta-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}
.bus-row .eta-second {
  font-size: 0.8rem;
  opacity: 0.6;
}
.stop-panel .btn-refresh {
  margin: 0 1rem 1rem;
}
.bus-row.clickable {
  cursor: pointer;
}
.bus-row.clickable:hover {
  background: rgba(88, 166, 255, 0.1);
}
.bus-row .arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
  margin-left: 0.25rem;
}

/* 路線詳細 */
.route-detail-back {
  padding: 0.5rem 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
}
.route-detail-back:hover {
  text-decoration: underline;
}
.route-detail-title {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.route-stop-list {
  position: relative;
  padding-left: 0.25rem;
}
.route-stop-item {
  display: flex;
  align-items: center;
  padding: 0.45rem 0.5rem;
  gap: 0.75rem;
  position: relative;
}
.route-stop-item::before {
  content: '';
  position: absolute;
  left: 0.82rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.route-stop-item:first-child::before {
  top: 50%;
}
.route-stop-item:last-child::before {
  bottom: 50%;
}
.route-stop-item.current {
  background: rgba(88, 166, 255, 0.12);
  border-radius: 6px;
}
.route-stop-item .stop-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.route-stop-item.current .stop-dot {
  width: 12px;
  height: 12px;
  background: var(--error);
}
.route-stop-item .stop-name {
  flex: 1;
  font-size: 0.95rem;
}
.route-stop-item .stop-eta {
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
  font-size: 0.9rem;
}
.route-stop-item .stop-eta.status {
  color: var(--warning);
}

.route-section {
  flex: 1;
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}
.route-section.hidden {
  display: none;
}
.route-section .search label,
.route-section .eta-controls label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.search label,
.eta-controls label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.input-row {
  display: flex;
  gap: 0.5rem;
}
.input-row input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.input-row input::placeholder {
  color: var(--text-muted);
}
.input-row input:focus {
  outline: none;
  border-color: var(--accent);
}
button {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
button:hover {
  background: var(--accent-hover);
}
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.route-list {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  max-height: 240px;
  overflow-y: auto;
}
.route-list:empty {
  display: none;
}
.route-item {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.route-item:last-child {
  border-bottom: none;
}
.route-item:hover {
  background: rgba(88, 166, 255, 0.1);
}
.route-item .name {
  font-weight: 500;
}
.route-item .info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.result h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}
.eta-controls {
  margin-bottom: 1rem;
}
.eta-controls select {
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.eta-display {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  margin-bottom: 1rem;
}
.eta-display .eta-time {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}
.eta-display .eta-detail {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.eta-display .eta-status {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
.eta-display .status-pending { color: var(--warning); }
.eta-display .status-none { color: var(--text-muted); }
.btn-refresh {
  margin-top: 0.5rem;
}

.loading,
.error {
  padding: 1rem;
  text-align: center;
}
.error {
  color: var(--error);
}

/* 路線詳細 section */
.route-detail-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.route-detail-section[hidden] {
  display: none;
}

/* 工具列 */
.route-detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
  flex-shrink: 0;
}
.route-detail-info {
  flex: 1;
  min-width: 0;
}
.route-detail-info .route-detail-title {
  border-bottom: none;
  padding: 0;
  margin-bottom: 0;
}
.route-detail-dest {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route-detail-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}
.btn-toggle {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  background: var(--border);
  color: var(--text-muted);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-toggle:hover {
  background: var(--accent);
  color: var(--bg);
}
.route-detail-actions .btn-refresh {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  margin: 0;
}

/* 公車資訊卡 */
.route-detail-bus-info {
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  font-size: 0.88rem;
  flex-shrink: 0;
}
.route-detail-bus-info[hidden] {
  display: none;
}
.bus-info-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.bus-info-label {
  color: var(--text-muted);
}
.bus-info-value {
  font-weight: 500;
  color: var(--accent);
}
.bus-info-item:not(:last-child)::after {
  content: '';
  display: inline-block;
  width: 1px;
  height: 0.9em;
  background: var(--border);
  margin-left: 0.6rem;
  vertical-align: middle;
}

/* 文字模式 */
.route-detail-stops {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem 1rem;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.route-detail-stops[hidden] {
  display: none;
}

/* 地圖模式 */
.route-detail-map {
  flex: 1;
  min-height: 320px;
  width: 100%;
  background: var(--surface);
}
.route-detail-map[hidden] {
  display: none;
}

/* 動態 tab 關閉按鈕 */
.tab .tab-close {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0 0.2rem;
  cursor: pointer;
  vertical-align: middle;
  border-radius: 3px;
}
.tab .tab-close:hover {
  color: var(--error);
  background: rgba(248, 81, 73, 0.15);
}

.data-notice {
  margin-top: 2rem;
  padding: 1.25rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.data-notice h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}
.data-notice p {
  margin: 0.35rem 0;
}
