/* public/css/style.css */
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Mono:ital,wght@0,300;0,400;0,500;1,400&display=swap');

:root {
  --bg:        #080d17;
  --surface:   #0f1624;
  --surface2:  #16202f;
  --surface3:  #1c2a3d;
  --border:    #1f2f45;
  --border2:   #263852;
  --accent:    #00d4ff;
  --accent2:   #ff6b35;
  --green:     #00c97b;
  --yellow:    #f5c842;
  --text:      #dce6f0;
  --text2:     #8a9bb5;
  --muted:     #3e5270;

  /* Operator colours */
  --op-kmb:    #d4820f;
  --op-ctb:    #1a6dcc;
  --op-mtr:    #e31837;

  /* MTR line colours */
  --mtr-AEL: #1C7670; --mtr-TCL: #F7943E; --mtr-TML: #923011;
  --mtr-TKL: #7D499A; --mtr-EAL: #53B7E8; --mtr-SIL: #BAC429;
  --mtr-TWL: #E2231A; --mtr-ISL: #007DC5; --mtr-KTL: #1AA94D;

  --font:      'Syne', sans-serif;
  --mono:      'DM Mono', monospace;
  --radius:    8px;
  --radius-lg: 14px;
  --sidebar-w: 360px;
  --header-h:  52px;
  --transition: 0.18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; }

/* ══════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════ */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
#header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 200;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 800; letter-spacing: -.3px;
  white-space: nowrap;
}
.logo-icon { font-size: 20px; }
.logo-pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.7)} }

.header-search {
  flex: 1; max-width: 380px; position: relative; margin-left: 8px;
}
.header-search input {
  width: 100%; padding: 7px 14px 7px 36px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 20px; color: var(--text); font-family: var(--font); font-size: 13px;
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.header-search input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,212,255,.1);
}
.header-search input::placeholder { color: var(--muted); }
.search-icon-prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}

#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); z-index: 1000;
  max-height: 360px; overflow-y: auto;
  display: none; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
#search-results.open { display: block; }

.search-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 13px;
  transition: background var(--transition);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--surface3); }
.search-icon { font-size: 15px; flex-shrink: 0; }
.search-type {
  font-size: 9px; font-weight: 700; letter-spacing: .6px;
  padding: 2px 5px; border-radius: 3px; flex-shrink: 0;
}
.type-kmb { background: rgba(212,130,15,.2); color: var(--op-kmb); }
.type-ctb { background: rgba(26,109,204,.2); color: var(--op-ctb); }
.type-mtr { background: rgba(227,24,55,.2); color: var(--op-mtr); }
.search-label { font-weight: 700; }
.search-sub { color: var(--text2); font-size: 11px; font-family: var(--mono); margin-left: auto; text-align: right; }
.search-loading, .search-empty, .search-error {
  padding: 14px; text-align: center; color: var(--text2); font-size: 13px;
}

#clock {
  font-family: var(--mono); font-size: 12px; color: var(--accent);
  background: rgba(0,212,255,.07); padding: 4px 10px;
  border: 1px solid rgba(0,212,255,.15); border-radius: 4px;
  margin-left: auto; white-space: nowrap;
}

.btn-icon {
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 6px 10px; cursor: pointer;
  color: var(--text2); font-size: 14px; transition: all var(--transition);
  display: flex; align-items: center; gap: 5px; white-space: nowrap; font-family: var(--font);
}
.btn-icon:hover { background: var(--surface3); border-color: var(--accent); color: var(--accent); }

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden; z-index: 100;
}

/* Tabs */
.tabs {
  display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.tab-btn {
  flex: 1; padding: 11px 6px; background: none; border: none;
  color: var(--text2); font-family: var(--font); font-size: 12px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all var(--transition); letter-spacing: .2px;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Panels */
.tab-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.tab-panel.active { display: flex; }

.panel-scroll { flex: 1; overflow-y: auto; padding: 14px; }
.panel-scroll::-webkit-scrollbar { width: 4px; }
.panel-scroll::-webkit-scrollbar-track { background: transparent; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ══════════════════════════════════════════
   PLANNER PANEL
══════════════════════════════════════════ */
.plan-section { margin-bottom: 14px; }
.plan-label {
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  color: var(--text2); text-transform: uppercase; margin-bottom: 6px;
}

.plan-input-row {
  display: flex; gap: 6px; align-items: center; margin-bottom: 6px;
}
.plan-input-row input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 8px 10px;
  color: var(--text); font-family: var(--font); font-size: 13px; outline: none;
  transition: border-color var(--transition);
}
.plan-input-row input:focus { border-color: var(--accent); }
.plan-input-row input::placeholder { color: var(--muted); }

.btn-small {
  background: var(--surface3); border: 1px solid var(--border2);
  color: var(--text2); border-radius: var(--radius); padding: 7px 9px;
  cursor: pointer; font-size: 14px; transition: all var(--transition); flex-shrink: 0;
}
.btn-small:hover { border-color: var(--accent); color: var(--accent); }

.btn-swap {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 50%; width: 28px; height: 28px;
  cursor: pointer; color: var(--text2); font-size: 16px; margin: 0 auto;
  transition: all var(--transition);
}
.btn-swap:hover { border-color: var(--accent2); color: var(--accent2); transform: rotate(180deg); }

.btn-plan {
  width: 100%; padding: 10px; background: var(--accent); color: #000;
  border: none; border-radius: var(--radius); font-family: var(--font);
  font-weight: 700; font-size: 14px; cursor: pointer;
  transition: all var(--transition); letter-spacing: .3px;
}
.btn-plan:hover { background: #33ddff; transform: translateY(-1px); }
.btn-plan:active { transform: translateY(0); }

/* Plan results */
.plan-hint {
  font-size: 12px; color: var(--yellow); background: rgba(245,200,66,.07);
  border: 1px solid rgba(245,200,66,.2); border-radius: var(--radius);
  padding: 8px 10px; margin-bottom: 10px;
}
.plan-options { display: flex; flex-direction: column; gap: 8px; }
.plan-option {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 10px 12px; cursor: pointer;
  transition: all var(--transition);
}
.plan-option:hover { border-color: var(--accent); }
.plan-option.selected { border-color: var(--accent); background: rgba(0,212,255,.05); }
.plan-opt-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.plan-mode { font-weight: 700; font-size: 13px; }
.plan-time { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--green); }
.plan-opt-detail { font-size: 11px; color: var(--text2); font-family: var(--mono); line-height: 1.6; }
.plan-loading {
  display: flex; align-items: center; gap: 10px;
  color: var(--text2); font-size: 13px; padding: 10px;
}
.plan-error { color: #ff5f5f; font-size: 13px; padding: 10px; }
.plan-empty { color: var(--text2); font-size: 12px; padding: 8px; }

.plan-nearby { margin-top: 14px; }
.plan-section-title {
  font-size: 10px; font-weight: 700; letter-spacing: .7px;
  color: var(--text2); text-transform: uppercase; margin-bottom: 6px;
}
.nearby-stop {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px;
}
.nearby-stop:last-child { border-bottom: none; }
.nearby-name { flex: 1; }
.nearby-dist { font-family: var(--mono); color: var(--text2); font-size: 11px; }
.nearby-op { font-size: 10px; font-weight: 700; color: var(--accent2); }

/* ══════════════════════════════════════════
   ROUTES PANEL
══════════════════════════════════════════ */
.route-header {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.route-badge {
  padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 700;
}
.op-kmb { background: rgba(212,130,15,.2); color: var(--op-kmb); }
.op-ctb { background: rgba(26,109,204,.2); color: var(--op-ctb); }
.op-mtr { background: rgba(227,24,55,.2); color: var(--op-mtr); }

.route-number { font-size: 18px; font-weight: 800; }
.route-dir { font-size: 11px; color: var(--text2); font-family: var(--mono); }

.stop-list { display: flex; flex-direction: column; }
.stop-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 6px; cursor: pointer;
  transition: background var(--transition); font-size: 12px;
}
.stop-row:hover { background: var(--surface2); }
.stop-row.selected { background: rgba(0,212,255,.07); }
.stop-seq {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface3); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--text2); flex-shrink: 0;
}
.stop-name { flex: 1; }
.stop-eta-inline { font-family: var(--mono); font-size: 11px; }

/* ══════════════════════════════════════════
   MTR PANEL
══════════════════════════════════════════ */
.mtr-controls {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;
}
.mtr-select {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 8px 10px;
  color: var(--text); font-family: var(--font); font-size: 13px; outline: none;
  cursor: pointer; transition: border-color var(--transition);
}
.mtr-select:focus { border-color: var(--accent); }
.mtr-select option { background: var(--surface2); }

.mtr-station-info { margin-bottom: 10px; }
#mtr-station-name { font-size: 16px; font-weight: 800; }
#mtr-station-lines { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.line-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 3px; color: #fff; letter-spacing: .3px;
}

/* ══════════════════════════════════════════
   ETA DISPLAY
══════════════════════════════════════════ */
.eta-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px;
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.eta-row:last-child { border-bottom: none; }
.eta-row.mtr-row { padding: 7px 10px; }
.eta-op { font-size: 9px; font-weight: 700; padding: 1px 4px; border-radius: 3px; }
.op-kmb { background: rgba(212,130,15,.2); color: var(--op-kmb); }
.op-ctb { background: rgba(26,109,204,.2); color: var(--op-ctb); }
.eta-route { font-weight: 700; font-size: 13px; }
.eta-dest { flex: 1; color: var(--text2); }
.eta-time { font-family: var(--mono); margin-left: auto; font-weight: 500; }
.eta-remark { font-size: 10px; color: var(--text2); font-family: var(--mono); }
.eta-plat { font-size: 10px; color: var(--muted); font-family: var(--mono); }
.eta-dir-label {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  color: var(--accent); text-transform: uppercase;
  padding: 6px 10px 2px;
}
.eta-due  { color: var(--accent2); font-weight: 700; }
.eta-soon { color: var(--yellow); font-weight: 700; }
.eta-ok   { color: var(--green); }
.eta-loading, .eta-empty, .eta-error, .eta-info {
  padding: 12px 10px; color: var(--text2); font-size: 12px; text-align: center;
}
.eta-error { color: #ff5f5f; }

#eta-panel {
  margin-top: 10px; background: var(--surface2);
  border: 1px solid var(--border2); border-radius: var(--radius);
  min-height: 48px; overflow: hidden;
}

/* ══════════════════════════════════════════
   MAP
══════════════════════════════════════════ */
#map-container { position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; }

/* Map pin buttons overlay */
.map-controls {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; flex-direction: column; gap: 6px;
}
.map-btn {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 7px 11px;
  color: var(--text2); font-family: var(--font); font-size: 12px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  transition: all var(--transition); box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.map-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Map hint overlay */
.map-hint {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(0,212,255,.15); border: 1px solid var(--accent);
  border-radius: 20px; padding: 8px 18px;
  color: var(--accent); font-size: 13px; font-weight: 600;
  pointer-events: none; z-index: 500;
  animation: fadeInUp .3s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

body.placing-pin #map { cursor: crosshair; }

/* ══════════════════════════════════════════
   LEAFLET CUSTOM MARKERS
══════════════════════════════════════════ */
.stop-marker { width: 14px; height: 14px; position: relative; }
.stop-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c, var(--accent));
  border: 2px solid rgba(255,255,255,.5);
  box-shadow: 0 0 6px var(--c, var(--accent));
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
}

.pin-marker { width: 24px; height: 32px; position: relative; }
.pin-body {
  width: 20px; height: 20px; border-radius: 50% 50% 50% 0;
  background: var(--c, var(--green));
  border: 2px solid rgba(255,255,255,.7);
  transform: rotate(-45deg);
  position: absolute; top: 0; left: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.pin-tip {
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 8px solid var(--c, var(--green));
  position: absolute; bottom: 0; left: 8px;
}

/* Leaflet popup dark style */
.leaflet-popup-content-wrapper {
  background: var(--surface2) !important; color: var(--text) !important;
  border: 1px solid var(--border2) !important; border-radius: var(--radius) !important;
  font-family: var(--font) !important; font-size: 13px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,.5) !important;
}
.leaflet-popup-tip { background: var(--surface2) !important; }
.leaflet-popup-close-button { color: var(--text2) !important; }

/* ══════════════════════════════════════════
   SPINNER
══════════════════════════════════════════ */
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border2); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinning { animation: spin .7s linear infinite !important; }

/* Stop card */
.stop-card { padding: 4px; }
.stop-card-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.stop-card-id, .stop-card-coords { font-family: var(--mono); font-size: 11px; color: var(--text2); }

/* Route info placeholder */
.route-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 200px; color: var(--muted); font-size: 13px; text-align: center; gap: 8px;
}
.route-placeholder span { font-size: 32px; }

/* ══════════════════════════════════════════
   MOBILE
══════════════════════════════════════════ */
@media (max-width: 700px) {
  :root { --sidebar-w: 100vw; }
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
  }
  #sidebar {
    position: fixed; left: -100vw; top: var(--header-h);
    width: 100vw; height: calc(100vh - var(--header-h));
    transition: left .25s ease; z-index: 300;
  }
  #sidebar.open { left: 0; }
  #map-container { grid-column: 1; grid-row: 2; }
  #clock { display: none; }
}
