@charset "UTF-8";
.hidden { display: none !important; }

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --primary: #0AB4FF;
  --primary-hover: #0099e0;
  --primary-light: rgba(10, 180, 255, 0.10);
  --primary-glow: rgba(10, 180, 255, 0.25);

  --bg: #F6F6F6;
  --card-bg: #FFFFFF;
  --surface: #FAFAFA;

  --text: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #9ca3af;

  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.10);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-full: 999px;

  --font-ui: 'Outfit', sans-serif;
  --font-text: 'Roboto', sans-serif;

  /* Status colors */
  --color-online: #4CAF50;
  --color-stale: #FF9800;

  /* Counting colors */
  --color-in: #2196F3;
  --color-out: #FF9800;
  --color-total: #4CAF50;
  --color-net: #9C27B0;
}

/* ============================================================
   RESET / BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  font-family: var(--font-text); font-size: 16px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { font-family: var(--font-ui); font-weight: 600; line-height: 1.25; }
a { color: var(--primary); text-decoration: none; }

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: flex; flex-direction: column; min-height: 100vh;
  max-width: 1440px; margin: 0 auto; padding: 0 16px;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header { padding: 14px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-shrink: 0; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.header-inner h1 {
  font-size: 1.35rem; font-weight: 700; display: flex; align-items: center;
  gap: 10px; color: var(--text); letter-spacing: -0.01em;
}
.header-icon { font-size: 1.5rem; }
.header-meta { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.header-loading { display: flex; align-items: center; gap: 6px; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content { display: grid; grid-template-columns: 1fr 380px; gap: 16px; flex: 1; min-height: 480px; }

/* ============================================================
   MAP
   ============================================================ */
#map {
  height: 100%; min-height: 420px; max-height: calc(100vh - 240px);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); z-index: 1;
}
.leaflet-container { font-family: var(--font-text); }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  display: flex; flex-direction: column; background: var(--card-bg);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; min-height: 420px; max-height: calc(100vh - 200px);
}
.sidebar-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border-light); flex-shrink: 0; }
.sidebar-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sidebar-title-row h2 { font-size: 1.05rem; font-weight: 600; }
.station-count { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

/* Filters */
.filters { display: flex; flex-direction: column; gap: 8px; }
.filter-input, .filter-select {
  width: 100%; font-family: var(--font-text); font-size: 0.85rem;
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--card-bg);
  color: var(--text); transition: border-color 0.2s, box-shadow 0.2s; outline: none;
}
.filter-input:focus, .filter-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Station list */
.station-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.station-list::-webkit-scrollbar { width: 6px; }
.station-list::-webkit-scrollbar-track { background: transparent; }
.station-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.station-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* Station item */
.station-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 16px; cursor: pointer;
  transition: background 0.15s; border-left: 3px solid transparent;
}
.station-item:hover { background: var(--surface); }
.station-item.active { background: var(--primary-light); border-left-color: var(--primary); }
.station-item.active .station-item-name { color: var(--primary); }

.station-item-info { flex: 1; min-width: 0; }
.station-item-name { font-family: var(--font-ui); font-weight: 600; font-size: 0.92rem; color: var(--text); }
.station-item-sub {
  font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.station-item-counts {
  display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap;
}
.count-tag {
  font-size: 0.75rem; font-weight: 600; padding: 2px 8px;
  border-radius: var(--radius-full); white-space: nowrap;
}
.count-tag--in { background: #E3F2FD; color: #1565C0; }
.count-tag--out { background: #FFF3E0; color: #E65100; }
.count-tag--total { background: #E8F5E9; color: #2E7D32; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  margin-top: 5px; box-shadow: 0 0 4px rgba(0,0,0,0.15);
}
.status-dot.online { background: var(--color-online); }
.status-dot.stale { background: var(--color-stale); }
.status-dot.problem { background: #EAB308; }
.status-dot.inactive { background: #EF4444; }

/* ============================================================
   DETAIL SECTION
   ============================================================ */
.detail-section { margin-top: 16px; margin-bottom: 20px; }
.detail-placeholder { text-align: center; padding: 60px 20px 48px; color: var(--text-muted); }
.placeholder-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.6; }
.placeholder-text { font-size: 1.05rem; font-weight: 500; }

.detail-header { margin-bottom: 16px; }
.detail-title-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px;
}
.detail-title-row h2 { font-size: 1.3rem; font-weight: 700; }
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.75rem; font-weight: 600; padding: 3px 10px;
  border-radius: var(--radius-full); text-transform: uppercase; letter-spacing: 0.03em;
}
.status-badge.online { background: rgba(76, 175, 80, 0.12); color: var(--color-online); }
.status-badge.stale { background: rgba(255, 152, 0, 0.12); color: var(--color-stale); }
.status-badge.problem { background: rgba(234, 179, 8, 0.12); color: #92400E; }
.status-badge.inactive { background: rgba(239, 68, 68, 0.12); color: var(--color-error, #EF4444); }
.status-badge.online::before, .status-badge.stale::before, .status-badge.problem::before, .status-badge.inactive::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.status-badge.online::before { background: var(--color-online); }
.status-badge.stale::before { background: var(--color-stale); }
.status-badge.problem::before { background: #EAB308; }
.status-badge.inactive::before { background: #EF4444; }

.detail-meta-row { display: flex; gap: 16px; font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; flex-wrap: wrap; }

/* KPI Grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.kpi-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 12px 14px; border: 1px solid var(--border-light); }
.kpi-card--primary { border-left: 3px solid var(--primary); }
.kpi-label { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.kpi-value { font-family: var(--font-ui); font-size: 1.3rem; font-weight: 700; color: var(--text); }
.kpi-value.kpi-loading { color: var(--text-muted); font-weight: 400; }
.kpi-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
@media (max-width: 768px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* Station Ranking */
.station-ranking { border-top: 1px solid var(--border-light); padding: 10px 16px 12px; flex-shrink: 0; }
.ranking-header { font-family: var(--font-ui); font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.ranking-item { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 0.82rem; }
.ranking-label { color: var(--text-secondary); }
.ranking-value { font-family: var(--font-ui); font-weight: 600; color: var(--text); }

/* Overview card (today totals) */
.detail-overview {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.overview-card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; text-align: center;
}
.overview-card-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-bottom: 4px; }
.overview-card-value { font-family: var(--font-ui); font-size: 1.6rem; font-weight: 700; }
.overview-card--in .overview-card-value { color: var(--color-in); }
.overview-card--out .overview-card-value { color: var(--color-out); }
.overview-card--total .overview-card-value { color: var(--color-total); }
.overview-card--net .overview-card-value { color: var(--color-net); }

/* Time range pills */
.detail-ranges { display: flex; gap: 6px; margin-bottom: 16px; }
.pill {
  font-family: var(--font-ui); font-size: 0.82rem; font-weight: 500;
  padding: 6px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-full); background: var(--card-bg);
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s; user-select: none;
}
.pill:hover { border-color: var(--primary); color: var(--primary); }
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px var(--primary-glow); }

/* Toggle buttons for mode */
.detail-modes { display: flex; gap: 6px; margin-bottom: 16px; }
.mode-btn {
  font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600;
  padding: 8px 18px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--card-bg);
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s; user-select: none;
}
.mode-btn:hover { border-color: var(--primary); color: var(--primary); }
.mode-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============================================================
   CHART AREA
   ============================================================ */
.chart-container {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.chart-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.chart-title { font-family: var(--font-ui); font-weight: 600; font-size: 0.92rem; color: var(--text); }
.chart-legend-inline { display: flex; gap: 12px; font-size: 0.78rem; }
.chart-legend-item { display: flex; align-items: center; gap: 4px; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.chart-legend-dot--in { background: var(--color-in); }
.chart-legend-dot--out { background: var(--color-out); }
.chart-legend-dot--total { background: var(--color-total); }

.chart-body { position: relative; height: 300px; }
.chart-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 0.82rem; color: var(--text-muted); text-align: center; padding: 20px; }

/* Data source link */
.chart-source { padding: 8px 0 0; font-size: 0.78rem; text-align: right; }
.chart-source a { color: var(--text-muted); text-decoration: none; opacity: 0.75; transition: color 0.15s; }
.chart-source a:hover { color: var(--primary); opacity: 1; }

/* ============================================================
   SPINNER
   ============================================================ */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner--small { width: 16px; height: 16px; border-width: 2px; }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer { margin-top: auto; padding: 16px 0 20px; border-top: 1px solid var(--border); flex-shrink: 0; }
.footer-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.footer-main { font-size: 0.82rem; color: var(--text-muted); text-align: center; }
.footer-brand { font-weight: 500; }
.footer-data { display: block; font-size: 0.75rem; margin-top: 2px; opacity: 0.7; }

.hint-banner {
  display: flex; align-items: center; gap: 8px; font-size: 0.78rem;
  color: #4a5568; background: #F0F4FF; border: 1px solid #CBD5E1;
  border-radius: var(--radius-sm); padding: 8px 14px; max-width: 680px; line-height: 1.4;
}
.hint-icon { flex-shrink: 0; font-size: 0.9rem; }

/* Legend Button + Modal */
.filter-footer { display: flex; justify-content: flex-end; padding-top: 2px; }
.legend-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: 1px solid var(--border);
  border-radius: var(--radius-xs); background: var(--card-bg);
  color: var(--text-muted); font-family: var(--font-ui); font-size: 0.82rem;
  font-weight: 700; cursor: pointer; transition: all 0.2s; line-height: 1;
}
.legend-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.legend-modal-overlay {
  position: fixed; inset: 0; z-index: 1000; display: flex;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.28); backdrop-filter: blur(2px);
}
.legend-modal {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18); width: 92vw; max-width: 460px;
  max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.legend-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 12px; border-bottom: 1px solid var(--border-light);
}
.legend-modal-header h3 { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.legend-close {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--text-muted); font-size: 1.3rem;
  cursor: pointer; border-radius: var(--radius-xs); line-height: 1;
}
.legend-close:hover { background: var(--surface); color: var(--text); }
.legend-modal-body { flex: 1; overflow-y: auto; padding: 14px 20px 8px; }
.legend-modal-footer { padding: 10px 20px 14px; border-top: 1px solid var(--border-light); }
.legend-modal-footer p { font-size: 0.72rem; color: var(--text-muted); line-height: 1.4; }
.legend-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.legend-item:last-child { border-bottom: none; }
.legend-color {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 4px rgba(0,0,0,0.15);
}
.legend-color--online { background: #4CAF50; }
.legend-color--problem { background: #EAB308; }
.legend-color--stale { background: #FF9800; }
.legend-color--inactive { background: #EF4444; }
.legend-text { flex: 1; }
.legend-text strong { font-size: 0.85rem; color: var(--text); }
.legend-text p { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .detail-overview { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  #app { padding: 0 12px; }
  .header-inner h1 { font-size: 1.15rem; }
  .main-content { grid-template-columns: 1fr; min-height: 0; }
  #map { height: 300px; min-height: 300px; }
  #sidebar { max-height: none; min-height: auto; }
  .station-list { max-height: 380px; }
  .detail-overview { grid-template-columns: repeat(2, 1fr); }
  .detail-title-row h2 { font-size: 1.15rem; }
  .detail-ranges { flex-wrap: wrap; }
  .chart-body { height: 240px; }
  .hint-banner { font-size: 0.72rem; padding: 6px 10px; }
}
@media (max-width: 480px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 4px; }
  .filter-row { grid-template-columns: 1fr; }
  #map { height: 240px; min-height: 240px; }
  .detail-overview { grid-template-columns: 1fr 1fr; }
}
