/* ================================================================
   MRT Go – 台北捷運載客率視覺化  (site.css)
   ================================================================ */

/* ── Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
  background: #0f1420;
  color: #d0d8ee;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Light Theme ──────────────────────────────────── */
[data-theme="light"] {
  background: #f5f7fa;
  color: #1a2332;
}

[data-theme="light"] body {
  background: #f5f7fa;
  color: #1a2332;
}

/* ── Header ────────────────────────────────────────── */
.mrt-header {
  background: #141929;
  border-bottom: 1px solid #1e2840;
  position: sticky;
  top: 0;
  z-index: 200;
}

[data-theme="light"] .mrt-header {
  background: #ffffff;
  border-bottom: 1px solid #e1e8f0;
}

.mrt-logo { flex-shrink: 0; }

.mrt-header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #e8eeff;
  letter-spacing: 0.03em;
}

[data-theme="light"] .mrt-header-title {
  color: #1a2332;
}

/* ── Filter Bar ────────────────────────────────────── */
.filter-bar {
  background: #141929;
  border-bottom: 1px solid #1e2840;
  z-index: 100;
}

[data-theme="light"] .filter-bar {
  background: #ffffff;
  border-bottom: 1px solid #e1e8f0;
}

.filter-label {
  color: #7a8baa;
  font-size: 0.78rem;
  white-space: nowrap;
}

[data-theme="light"] .filter-label {
  color: #5a6a85;
}

/* Line buttons */
.btn-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1e2840;
  border: 1.5px solid #2a3655;
  border-radius: 20px;
  padding: 4px 12px 4px 6px;
  color: #c5cfea;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

[data-theme="light"] .btn-line {
  background: #f0f4f8;
  border-color: #d1dae6;
  color: #3a4a5f;
}

.btn-line:hover {
  background: #253050;
  border-color: var(--line-color);
  color: #fff;
}

[data-theme="light"] .btn-line:hover {
  background: #e6ecf3;
  border-color: var(--line-color);
  color: #1a2332;
}

.btn-line.active {
  background: color-mix(in srgb, var(--line-color) 20%, #1e2840);
  border-color: var(--line-color);
  color: #fff;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--line-color) 35%, transparent);
}

[data-theme="light"] .btn-line.active {
  background: color-mix(in srgb, var(--line-color) 15%, #ffffff);
  border-color: var(--line-color);
  color: #1a2332;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--line-color) 25%, transparent);
}

.line-badge {
  display: inline-block;
  border-radius: 12px;
  padding: 1px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
}

.line-name-text { font-size: 0.8rem; }

/* Year / Month selects */
.filter-select {
  background: #1e2840;
  border: 1.5px solid #2a3655;
  color: #c5cfea;
  font-size: 0.78rem;
  padding: 3px 24px 3px 8px;
  min-width: 80px;
  border-radius: 6px;
}

[data-theme="light"] .filter-select {
  background: #ffffff;
  border-color: #d1dae6;
  color: #3a4a5f;
}

.filter-select:focus {
  border-color: #3a7bd5;
  outline: none;
  box-shadow: none;
  background: #1e2840;
  color: #fff;
}

[data-theme="light"] .filter-select:focus {
  background: #ffffff;
  color: #1a2332;
  border-color: #3a7bd5;
}

.filter-select option {
  background: #1e2840;
  color: #c5cfea;
}

[data-theme="light"] .filter-select option {
  background: #ffffff;
  color: #3a4a5f;
}

/* Direction / Day toggles */
.btn-check:checked + .btn-outline-secondary {
  background-color: #3a7bd5;
  border-color: #3a7bd5;
  color: #fff;
}

.btn-outline-secondary {
  border-color: #2a3655;
  color: #aab4cc;
  font-size: 0.78rem;
}

[data-theme="light"] .btn-outline-secondary {
  border-color: #d1dae6;
  color: #5a6a85;
  background: #ffffff;
}

.btn-outline-secondary:hover {
  background: #253050;
  color: #fff;
}

[data-theme="light"] .btn-outline-secondary:hover {
  background: #e6ecf3;
  color: #1a2332;
  border-color: #b8c5d6;
}

/* ── Legend ────────────────────────────────────────── */
.legend-bar {
  font-size: 0.76rem;
  color: #8a96b4;
  padding: 4px 0;
}

.legend-label {
  font-weight: 600;
  color: #b0bcd6;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-wrap {
    display: flex;
    gap: 0 3px;
    align-items: center;
}
.legend-swatch {
    width: 18px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.lv1 { background: rgb(144,238,144); }
.lv2 { background: rgb(255,210,60);  }
.lv3 { background: rgb(255,140,40);  }
.lv4 { background: rgb(210,40,40);   }

/* ── Section Title ─────────────────────────────────── */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #c8d4ef;
  background: #141929;
  border-bottom: 1px solid #1e2840;
}

.section-icon { font-size: 1rem; color: #4a7bd5; }
.section-sub  { color: #7a8baa; font-size: 0.78rem; font-weight: 400; }

[data-theme="light"] .section-title {
  color: #2a3a50;
  background: #f8fafb;
  border-bottom: 1px solid #e1e8f0;
}

[data-theme="light"] .section-sub {
  color: #5a6a85;
}

/* ── 2D Heatmap ─────────────────────────────────────── */
.heatmap-wrapper {
  position: relative;
  background: #10162a;
}

[data-theme="light"] .heatmap-wrapper {
  background: #ffffff;
}

.heatmap-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: #7a8baa;
}

[data-theme="light"] .heatmap-loading {
  color: #5a6a85;
}

.heatmap-scroll-outer {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
  -webkit-overflow-scrolling: touch;
}

.heatmap-scroll-inner {
  min-width: 0;   /* allow full RWD shrink */
}

.heatmap-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}

/* Sticky column + row headers */
.heatmap-table thead th {
  position: sticky;
  top: 0;
  background: #141929;
  z-index: 10;
  color: #8a96b4;
  font-size: 11px;    /* ≥ 8pt */
  font-weight: 600;
  text-align: center;
  padding: 4px 1px;
  border-bottom: 1px solid #1e2840;
  white-space: nowrap;
}

[data-theme="light"] .heatmap-table thead th {
  background: #f8fafb;
  color: #5a6a85;
  border-bottom: 1px solid #e1e8f0;
}

.hm-station-col {
  position: sticky !important;
  left: 0;
  width: 76px;
  min-width: 76px;
  z-index: 20 !important;
  background: #141929 !important;
  text-align: left !important;
  padding-left: 6px !important;
  font-size: 11px;
}

[data-theme="light"] .hm-station-col {
  background: #f8fafb !important;
}

.hm-time-col {
  width: 36px;
  min-width: 32px;
}

.hm-station-name {
  position: sticky;
  left: 0;
  background: #12182c;
  z-index: 5;
  font-size: 11px;
  color: #c0cce6;
  white-space: nowrap;
  padding: 2px 6px;
  border-right: 1px solid #1e2840;
  display: flex;
  align-items: center;
  gap: 4px;
}

[data-theme="light"] .hm-station-name {
  background: #fafbfc;
  color: #2a3a50;
  border-right: 1px solid #e1e8f0;
}

[data-theme="light"] .hm-station-name {
  background: #fafbfc;
  color: #2a3a50;
  border-right: 1px solid #e1e8f0;
}

.station-accent {
  width: 3px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.hm-cell {
  width: 36px;
  height: 22px;
  border: 1px solid #10162a;
  cursor: default;
  transition: opacity 0.1s;
}

[data-theme="light"] .hm-cell {
  border: 1px solid #f0f4f8;
}

.hm-cell:hover { opacity: 0.8; outline: 2px solid rgba(255,255,255,0.5); }
.hm-empty      { background: #1a2035 !important; cursor: default; }
.hm-empty:hover { outline: none; opacity: 1; }

[data-theme="light"] .hm-cell:hover { outline: 2px solid rgba(0,0,0,0.3); }
[data-theme="light"] .hm-empty { background: #f0f4f8 !important; }

/* Tooltip */
.heat-tip {
  position: fixed;
  background: rgba(15, 20, 40, 0.95);
  border: 1px solid #2a3655;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: #d4dff6;
  line-height: 1.6;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  white-space: nowrap;
}

[data-theme="light"] .heat-tip {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #c8d4e6;
  color: #1a2332;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* ── 3D Canvas ──────────────────────────────────────── */
.canvas3d-wrap {
  position: relative;
  width: 100%;
  height: 520px;
  background: #1a1f2e;
  border-top: 1px solid #1e2840;
  cursor: grab;
}

.canvas3d-wrap:active { cursor: grabbing; }

#canvas3d {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ── Footer ─────────────────────────────────────────── */
.mrt-footer {
  background: #0d1222;
  border-top: 1px solid #1e2840;
  margin-top: 16px;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 576px) {
  .mrt-header-title { font-size: 0.9rem; }
  .line-name-text   { display: none; }
  .btn-line         { padding: 4px 8px; }
  .canvas3d-wrap    { height: 360px; }
  .hm-station-col   { width: 58px; min-width: 58px; font-size: 10px; }
  .hm-station-name  { font-size: 10px; padding: 2px 4px; }
  .hm-time-col      { width: 26px; min-width: 24px; font-size: 10px; }
  .hm-cell          { width: 26px; height: 18px; }
  .heatmap-table thead th { font-size: 10px; padding: 3px 1px; }
}

@media (min-width: 768px) {
  html { font-size: 15px; }
}

/* Bootstrap overrides */
.btn:focus, .btn:active:focus { box-shadow: none; }

/* ── Debug Modal ─────────────────────────────────────────────── */
.dbg-modal-content {
  background: #0f1520;
  border: 1px solid #2a3655;
  color: #c8d4ef;
  font-size: 0.82rem;
}

.dbg-header {
  background: #141929;
  border-bottom: 1px solid #1e2840;
  padding: 10px 16px;
}

.dbg-title {
  font-size: 0.9rem;
  color: #d4dff6;
  display: flex;
  align-items: center;
  gap: 8px;
}

[data-theme="light"] .dbg-title {
  color: #2a3a50;
}

.dbg-icon { font-size: 1rem; }

.dbg-footer {
  background: #141929;
  border-top: 1px solid #1e2840;
}

[data-theme="light"] .dbg-footer {
  background: #f8fafb;
  border-top: 1px solid #e1e8f0;
}

.dbg-section {
  padding: 10px 16px;
  border-bottom: 1px solid #1a2236;
}

[data-theme="light"] .dbg-section {
  border-bottom: 1px solid #e8edf2;
}

.dbg-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5a7acc;
  margin-bottom: 6px;
}

.dbg-code {
  display: block;
  background: #0a0f1a;
  border: 1px solid #1e2840;
  border-radius: 5px;
  padding: 8px 12px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.78rem;
  color: #a8d8ff;
  word-break: break-all;
  white-space: pre-wrap;
}

[data-theme="light"] .dbg-code {
  background: #f5f8fb;
  border: 1px solid #d8e2ed;
  color: #2a5a8f;
}

.dbg-pre {
  background: #0a0f1a;
  border: 1px solid #1e2840;
  border-radius: 5px;
  padding: 10px 14px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.78rem;
  color: #b8e8c8;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  max-height: 260px;
  overflow-y: auto;
}

[data-theme="light"] .dbg-pre {
  background: #f5f8fb;
  border: 1px solid #d8e2ed;
  color: #2a6a4f;
}

.dbg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.dbg-table th {
  background: #141929;
  color: #7a8baa;
  padding: 5px 10px;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid #1e2840;
}

[data-theme="light"] .dbg-table th {
  background: #f8fafb;
  color: #5a6a85;
  border-bottom: 1px solid #e1e8f0;
}

.dbg-table td {
  padding: 4px 10px;
  border-bottom: 1px solid #141929;
  font-family: "Consolas", "Courier New", monospace;
  color: #c8d4ef;
}

[data-theme="light"] .dbg-table td {
  border-bottom: 1px solid #f0f4f8;
  color: #3a4a5f;
}

.dbg-param-key { color: #f0c06a; }

.dbg-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
}

.dbg-ok   { background: rgba(0,180,80,0.2);  color: #4ddf8a; border: 1px solid #00b450; }
.dbg-fail { background: rgba(220,50,50,0.2); color: #ff7070; border: 1px solid #dc3232; }

.dbg-err {
  color: #ff7070;
  font-size: 0.78rem;
  font-family: "Consolas", "Courier New", monospace;
  word-break: break-all;
}

/* ── Chart Resize Handle ─────────────────────────────── */
.chart-resize-handle {
  height: 10px;
  background: #0d1222;
  border-top: 1px solid #1a2236;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}
.chart-resize-handle:hover,
.chart-resize-handle.active { background: #131d38; }
.chart-resize-handle::after {
  content: '';
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: #2a3655;
}
.chart-resize-handle:hover::after,
.chart-resize-handle.active::after { background: #4a7bd5; }

/* ── 3D Legend (thermometer, top-right) ──────────────── */
.c3d-legend {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
.c3d-legend-title {
  font-size: 0.65rem;
  color: #8a96b4;
  font-weight: 600;
  letter-spacing: 0.03em;
}

[data-theme="light"] .c3d-legend-title {
  color: #5a6a85;
}

.c3d-legend-body {
  display: flex;
  align-items: stretch;
  gap: 5px;
}
.c3d-legend-ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 0.6rem;
  color: #7a8baa;
  height: 120px;
  padding: 1px 0;
}

[data-theme="light"] .c3d-legend-ticks {
  color: #6a7a95;
}
.c3d-legend-bar {
  width: 12px;
  height: 120px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(to bottom,
    rgb(130,0,0)          0%,
    rgb(210,30,10)        15%,
    rgb(230,110,0)        40%,
    rgb(195,195,0)        70%,
    rgb(70,195,70)        90%,
    rgba(70,195,70,0.3)  100%
  );
}

/* ── 3D Pan Controls (cross, bottom-right) ───────────── */
.c3d-pan {
  position: absolute;
  bottom: 14px;
  right: 10px;
  display: grid;
  grid-template-areas: ". up ." "left center right" ". down .";
  grid-template-columns: repeat(3, 26px);
  grid-template-rows:    repeat(3, 26px);
  gap: 2px;
  z-index: 10;
}
.c3d-pan-btn {
  padding: 0;
  background: rgba(12,18,36,0.82);
  border: 1px solid #2a3655;
  border-radius: 4px;
  color: #8a96b4;
  font-size: 0.68rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
  user-select: none;
  -webkit-user-select: none;
}

[data-theme="light"] .c3d-pan-btn {
  background: rgba(255,255,255,0.9);
  border: 1px solid #d1dae6;
  color: #5a6a85;
}

.c3d-pan-btn:hover  { background: rgba(42,64,120,0.92); color: #fff; border-color: #4a7bd5; }
.c3d-pan-btn:active { background: rgba(42,100,210,0.85); }

[data-theme="light"] .c3d-pan-btn:hover {
  background: rgba(58,123,213,0.15);
  color: #1a2332;
  border-color: #3a7bd5;
}

[data-theme="light"] .c3d-pan-btn:active {
  background: rgba(58,123,213,0.25);
}
.c3d-pan-up     { grid-area: up;     }
.c3d-pan-left   { grid-area: left;   }
.c3d-pan-center { grid-area: center; color: #c5cfea; font-size: 0.9rem; }
.c3d-pan-right  { grid-area: right;  }
.c3d-pan-down   { grid-area: down;   }

/* ── No-Data Modal ───────────────────────────────────── */
.nodata-modal-content {
  background: #141929;
  border: 1px solid #2a3655;
  border-radius: 10px;
  color: #c8d4ef;
}

[data-theme="light"] .nodata-modal-content {
  background: #ffffff;
  border: 1px solid #d1dae6;
  color: #2a3a50;
}

.nodata-icon  { font-size: 2rem; margin-bottom: 8px; }
.nodata-title { font-size: 1rem; font-weight: 700; color: #d4dff6; margin-bottom: 6px; }
.nodata-sub   { font-size: 0.8rem; color: #7a8baa; line-height: 1.6; }

[data-theme="light"] .nodata-title { color: #2a3a50; }
[data-theme="light"] .nodata-sub { color: #6a7a95; }

.nodata-footer { border-top: 1px solid #1e2840; background: transparent; }

[data-theme="light"] .nodata-footer { border-top: 1px solid #e1e8f0; }

/* ── Theme Toggle Button ───────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1e2840;
  border: 1.5px solid #2a3655;
  border-radius: 20px;
  padding: 4px 12px;
  color: #c5cfea;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.theme-toggle:hover {
  background: #253050;
  border-color: #4a7bd5;
  color: #fff;
}

[data-theme="light"] .theme-toggle {
  background: #f0f4f8;
  border-color: #d1dae6;
  color: #3a4a5f;
}

[data-theme="light"] .theme-toggle:hover {
  background: #e6ecf3;
  border-color: #3a7bd5;
  color: #1a2332;
}

.theme-toggle-icon {
  font-size: 1rem;
  line-height: 1;
}
