:root {
  --primary-color: #2d3436;
  --accent-blue: #0984e3;
  --accent-red: #d63031;
  --accent-green: #00b894;
  --cctv-purple: #6c5ce7;
  --bg-glass: rgba(255, 255, 255, 0.98);
  --bg-panel: #ffffff;
  --bg-item: #ffffff;
  --text-main: #2d3436;
  --text-sub: #636e72;
  --border-color: #eeeeee;
  --nav-height: 60px;
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.15);
  --z-sidebar: 3000;
  --z-nav: 3100;
  --z-modal: 4000;
}

body.dark-theme {
  --primary-color: #dfe6e9;
  --bg-glass: rgba(45, 52, 54, 0.98);
  --bg-panel: #2d3436;
  --bg-item: #353b48;
  --text-main: #dfe6e9;
  --text-sub: #b2bec3;
  --border-color: #4b4b4b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #e5e5e5; font-family: "Noto Sans TC", sans-serif; }
button { font: inherit; }
.mono { font-family: "JetBrains Mono", monospace; }

.navbar {
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--nav-height);
  background: #2d3436;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  z-index: var(--z-nav);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.navbar-left { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 0; }
.navbar-brand {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  cursor: pointer;
}
.navbar-brand:hover { opacity: 0.82; }
.navbar-brand img { height: 36px; max-width: 96px; object-fit: contain; background: rgba(255, 255, 255, 0.92); border-radius: 4px; padding: 2px 6px; }
.navbar-stats { display: flex; align-items: center; gap: 15px; margin-left: 20px; padding-left: 20px; border-left: 1px solid rgba(255, 255, 255, 0.2); }
.nav-stat-item { display: flex; flex-direction: column; line-height: 1.1; }
.nav-stat-label { font-size: 9px; color: #b2bec3; text-transform: uppercase; }
.nav-stat-value { font-size: 16px; font-weight: 700; color: var(--accent-green); }

.nav-tabs { display: flex; background: rgba(255, 255, 255, 0.1); border-radius: 20px; padding: 3px; }
.nav-tab {
  border: 0;
  background: transparent;
  padding: 6px 20px;
  border-radius: 17px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #b2bec3;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.nav-tab.active { background: #ffffff; color: #2d3436; font-weight: 700; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); }
.nav-tab:hover:not(.active) { color: #ffffff; }
.nav-link { text-decoration: none; }
.menu-toggle { border: 0; background: transparent; cursor: pointer; font-size: 24px; padding: 10px; color: #ffffff; transition: color 0.2s; }
.menu-toggle:hover { color: var(--accent-green); }
.progress-container { position: absolute; bottom: 0; left: 0; width: 100%; height: 4px; background: rgba(255, 255, 255, 0.2); }
.progress-bar { height: 100%; background: var(--accent-green); width: 0%; transition: width 12s linear; }

.view-container { position: absolute; top: var(--nav-height); left: 0; width: 100%; height: calc(100% - var(--nav-height)); display: none; }
.view-container.active { display: block; }
#map { width: 100%; height: 100%; z-index: 1; background: #dfe6e9; transition: filter 0.3s; }
body.dark-theme #map { background: #0f0f0f; }
body.dark-theme .leaflet-tile-pane { filter: invert(100%) hue-rotate(180deg) contrast(90%); }

.sidebar-left, .sidebar-right {
  position: absolute;
  top: var(--nav-height);
  height: calc(100% - var(--nav-height));
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  z-index: var(--z-sidebar);
  color: var(--text-main);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-left { left: 0; width: 320px; transform: translateX(-100%); box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; }
.sidebar-left.active { transform: translateX(0); }
.sidebar-right { right: 0; width: 280px; transform: translateX(100%); box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1); padding: 20px; }
.sidebar-right.active { transform: translateX(0); }
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border-color); background: var(--bg-panel); }
.sidebar-tab { flex: 1; border: 0; background: transparent; text-align: center; padding: 15px 0; cursor: pointer; font-weight: 700; color: var(--text-sub); font-size: 14px; transition: 0.2s; }
.sidebar-tab.active { color: var(--text-main); border-bottom: 3px solid var(--accent-blue); background: rgba(0, 0, 0, 0.05); }
body.dark-theme .sidebar-tab.active { background: rgba(255, 255, 255, 0.05); }
.sidebar-content { flex: 1; overflow-y: auto; padding: 15px; }
.sidebar-pane { display: none; }
.sidebar-pane.active { display: block; }
.empty-state { text-align: center; color: #999999; margin-top: 20px; }

.list-item {
  padding: 12px;
  background: var(--bg-item);
  margin-bottom: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  color: var(--text-main);
}
.list-item:hover { border-color: var(--accent-blue); transform: translateY(-2px); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }
.list-item.active { background: #f0f9ff; border-left: 4px solid var(--accent-blue); }
body.dark-theme .list-item.active { background: #30336b; border-left-color: #6c5ce7; }
.t-row, .st-header, .st-arrival-row { display: flex; justify-content: space-between; align-items: center; }
.t-id { font-weight: 800; font-size: 16px; color: var(--accent-blue); }
body.dark-theme .t-id { color: #74b9ff; }
.t-spd { font-weight: 700; color: var(--text-sub); }
.t-dir { font-size: 10px; padding: 2px 6px; border-radius: 4px; color: #ffffff; margin-top: 4px; display: inline-block; }
.cw { background: var(--accent-blue); }
.ccw { background: var(--accent-red); }
.st-header { margin-bottom: 6px; }
.st-name { font-weight: 700; font-size: 15px; color: var(--text-main); }
.st-code { font-size: 11px; color: var(--text-sub); background: rgba(0, 0, 0, 0.05); padding: 1px 5px; border-radius: 4px; font-family: "JetBrains Mono", monospace; }
body.dark-theme .st-code { background: rgba(255, 255, 255, 0.1); }
.st-arrival-row { font-size: 12px; color: var(--text-sub); padding: 4px 0 2px; border-top: 1px dashed var(--border-color); margin-top: 4px; }
.st-arrival-dest { color: var(--text-main); font-weight: 500; }
.st-arrival-time { font-weight: 700; color: var(--accent-green); }
.st-arrival-time.soon { color: var(--accent-red); }

.menu-title { font-size: 14px; color: var(--text-sub); font-weight: 700; margin: 20px 0 15px; text-transform: uppercase; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; }
.menu-title:first-child { margin-top: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; font-size: 15px; color: var(--text-main); }
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: #cccccc; transition: 0.4s; border-radius: 20px; }
.slider::before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: #ffffff; transition: 0.4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-blue); }
input:checked + .slider::before { transform: translateX(20px); }
.legend-panel { background: var(--bg-panel); padding: 10px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); color: var(--text-main); }
.status-item { display: flex; align-items: center; margin-bottom: 8px; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; flex: none; }
.dot.cw { background: var(--accent-blue); }
.dot.ccw { background: var(--accent-red); }
.dot.station { border: 2px solid #636e72; background: #ffffff; }
.dot.cctv { background: var(--cctv-purple); }
.source-note { margin-top: 30px; font-size: 12px; color: #999999; text-align: center; line-height: 1.55; }

.weather-widget {
  position: absolute;
  top: 20px;
  right: 60px;
  z-index: 1000;
  background: var(--bg-panel);
  padding: 8px 12px;
  border-radius: 30px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}
.weather-icon { font-size: 18px; color: var(--accent-blue); }

.bottom-panel {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 150%);
  width: 90%;
  max-width: 280px;
  background: var(--bg-panel);
  z-index: 2100;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
  color: var(--text-main);
}
.bottom-panel.active { transform: translate(-50%, 0); }
.panel-header { padding: 8px 12px; background: #2d3436; color: #ffffff; display: flex; justify-content: space-between; align-items: center; }
.panel-title { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.panel-close, .cctv-close { border: 0; background: transparent; cursor: pointer; color: inherit; font-size: 16px; opacity: 0.85; }
.panel-content { padding: 10px 12px; }
.compact-info { display: flex; justify-content: space-between; align-items: center; }
.main-stat { text-align: right; }
.speed-value { font-size: 26px; font-weight: 800; color: var(--text-main); line-height: 1; }
.speed-unit { font-size: 11px; color: var(--text-sub); font-weight: 500; }
.sub-stats { display: flex; flex-direction: column; gap: 3px; }
.stat-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-sub); }
.stat-icon { width: 14px; text-align: center; color: var(--text-main); }
.status-text-ok { color: var(--accent-green); font-weight: 700; }
.status-text-warn { color: var(--accent-red); font-weight: 700; }
.follow-btn { margin-top: 10px; width: 100%; padding: 8px; border: 0; border-radius: 6px; background: #f1f2f6; color: #2d3436; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px; }
body.dark-theme .follow-btn { background: #353b48; color: #dfe6e9; }
.follow-btn.active { background: var(--accent-green); color: #ffffff; }
.arrival-list { list-style: none; padding: 0; margin: 0; max-height: 120px; overflow-y: auto; }
.arrival-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border-color); }
.arrival-dest { font-weight: 700; font-size: 12px; color: var(--text-main); }
.arrival-time { padding: 2px 6px; border-radius: 10px; font-size: 10px; font-weight: 700; color: #ffffff; }
.arrival-time.now { background: #d63031; }
.arrival-time.soon { background: #e17055; }
.arrival-time.normal { background: #00b894; }

.train-container { width: 100%; height: 100%; position: relative; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)); }
.train-shape { width: 100%; height: 100%; background: #ffffff; border-radius: 50% 50% 50% 0; display: flex; align-items: center; justify-content: center; border: 2px solid #ffffff; position: absolute; top: 0; left: 0; transition: transform 0.3s ease-out; }
.train-dot { width: 60%; height: 60%; border-radius: 50%; animation: breathe 2s infinite ease-in-out; }
.train-cw .train-dot { background: var(--accent-blue); }
.train-cw .train-shape { border-color: var(--accent-blue); }
.train-ccw .train-dot { background: var(--accent-red); }
.train-ccw .train-shape { border-color: var(--accent-red); }
@keyframes breathe {
  0%, 100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
  50% { transform: scale(1.1); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0); }
}
.station-icon-container { background: #ffffff; border-radius: 50px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); display: flex; align-items: center; justify-content: center; border: 1px solid #dddddd; width: 100%; height: 100%; overflow: hidden; }
.station-icon-container img { width: 85%; height: auto; }
.zoom-low .station-icon-container { width: 8px !important; height: 8px !important; border-radius: 50%; padding: 0; background: #ffffff; border: 2px solid #666666; transform: translate(10px, 4px) !important; }
.zoom-low .station-icon-container img { display: none; }
.station-label { background: rgba(255, 255, 255, 0.9); border: 1px solid #cccccc; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #2d3436; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.cctv-icon { background: var(--cctv-purple); color: #ffffff; border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); border: 2px solid #ffffff; transition: transform 0.2s; }
.cctv-icon:hover { transform: scale(1.2); background: #5f27cd; }
.leaflet-popup-content-wrapper { border-radius: 8px; padding: 0; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2); }
body.dark-theme .leaflet-popup-content-wrapper, body.dark-theme .leaflet-popup-tip { background: #2d3436; color: #dfe6e9; }
.leaflet-popup-content { margin: 0 !important; width: 140px !important; padding: 8px; text-align: center; position: relative; }
.popup-tools { display: flex; justify-content: center; gap: 8px; margin-bottom: 4px; }
.popup-btn { width: 24px; height: 24px; border-radius: 50%; border: 0; color: #ffffff; font-size: 11px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.popup-btn-info { background: #2d3436; }
body.dark-theme .popup-btn-info { background: #636e72; }
.popup-btn-lock { background: #b2bec3; }
.popup-btn-lock.active { background: var(--accent-green); box-shadow: 0 0 5px var(--accent-green); }
.popup-title { font-size: 13px; font-weight: 700; display: block; color: #2d3436; }
body.dark-theme .popup-title { color: #dfe6e9; }
.popup-sub { font-size: 15px; font-weight: 800; color: #2d3436; display: block; font-family: "JetBrains Mono", monospace; line-height: 1.2; }
body.dark-theme .popup-sub { color: #74b9ff; }
.popup-detail { font-size: 10px; color: #636e72; display: block; margin-top: 2px; }
body.dark-theme .popup-detail { color: #b2bec3; }

#cctv-view { background: #1e272e; overflow-y: auto; padding: 20px; }
.cctv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; max-width: 1600px; margin: 0 auto; }
.cctv-card { background: #2d3436; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); transition: transform 0.2s; display: flex; flex-direction: column; }
.cctv-card:hover { transform: translateY(-5px); box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4); }
.cctv-card-header { padding: 10px 15px; background: rgba(0, 0, 0, 0.2); color: #dfe6e9; font-size: 14px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.cctv-card-body { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000000; cursor: pointer; border: 0; padding: 0; display: block; }
.cctv-card-img { width: 100%; height: 100%; object-fit: cover; opacity: 0.9; transition: opacity 0.2s; display: block; }
.cctv-card-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; transition: opacity 0.2s; color: #ffffff; font-size: 28px; }
.cctv-card-body:hover .cctv-card-overlay { opacity: 1; }
.cctv-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.9); z-index: var(--z-modal); display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.cctv-modal.active { opacity: 1; pointer-events: auto; }
.cctv-container { position: relative; width: 95%; max-width: 900px; background: #000000; border-radius: 8px; overflow: hidden; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.cctv-header { padding: 10px 15px; background: rgba(255, 255, 255, 0.1); color: #ffffff; display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.cctv-content { width: 100%; aspect-ratio: 16 / 9; background: #000000; display: flex; align-items: center; justify-content: center; }
.cctv-content img { width: 100%; height: 100%; object-fit: contain; }

.loader-overlay { position: fixed; inset: 0; background: rgba(255, 255, 255, 0.9); z-index: 5000; display: flex; justify-content: center; align-items: center; flex-direction: column; }
.loader-overlay p { margin-top: 10px; color: #666666; }
.spinner { width: 40px; height: 40px; border: 4px solid #eeeeee; border-top-color: var(--primary-color); border-radius: 50%; animation: spin 1s infinite linear; }
@keyframes spin { 100% { transform: rotate(360deg); } }

@media (max-width: 768px) {
  .navbar { gap: 8px; padding: 0 10px; }
  .navbar-brand span { display: none; }
  .navbar-stats { margin-left: 4px; padding-left: 10px; gap: 10px; }
  .nav-tab { padding: 6px 12px; }
  .weather-widget { transform: scale(0.86); transform-origin: top right; top: 10px; right: 10px; }
  .sidebar-left { width: min(320px, 88vw); }
  .sidebar-right { width: min(280px, 82vw); }
  .cctv-grid { grid-template-columns: 1fr; }
}
