/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --header-h: 52px;
  --sidebar-w: 280px;
  --detail-w: 340px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4F46E5;
  --primary-light: #EEF2FF;
  --red: #DC2626;
  --amber: #F59E0B;
  --green: #059669;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

html, body { height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); }

/* === Header === */
#header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 12px; gap: 12px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-title h1 { font-size: 16px; font-weight: 700; line-height: 1.2; }
.header-subtitle { font-size: 11px; color: var(--text-muted); }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

.header-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: none; border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--text);
  transition: all 0.15s;
}
.header-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.header-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* === Main Layout === */
#main {
  position: fixed; top: var(--header-h); left: 0; right: 0; bottom: 0;
  display: flex;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: margin-left 0.25s;
  z-index: 20;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-section { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-section h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 12px; }

/* Filters */
.filter-group { margin-bottom: 10px; }
.filter-group label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 3px; color: var(--text-muted); }
.filter-group input {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; background: var(--bg);
  transition: border-color 0.15s;
}
.filter-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,0.15); }

.btn {
  padding: 7px 14px; border: none; border-radius: 5px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all 0.15s;
}
.btn-clear { width: 100%; margin-top: 8px; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); }
.btn-clear:hover { background: #fee2e2; color: var(--red); border-color: var(--red); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338CA; }
.btn-secondary { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: #f1f5f9; }

.stats-text { font-size: 13px; color: var(--text-muted); font-weight: 500; }

/* Legend */
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,0.1); flex-shrink: 0; }

/* Infrastructure Toggles */
.infra-toggle-item { margin-bottom: 6px; }
.infra-toggle-item label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer;
}
.infra-toggle-item input[type="checkbox"] {
  width: 14px; height: 14px; cursor: pointer;
}
.infra-dot {
  width: 20px; height: 20px; border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0;
}

/* === Map === */
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* === InfoWindow === */
.iw-content { padding: 2px; min-width: 180px; }
.iw-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.iw-name { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.iw-row { font-size: 12px; display: flex; justify-content: space-between; padding: 2px 0; }
.iw-row span { color: var(--text-muted); }
.iw-status { display: inline-block; margin-top: 6px; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.iw-vulnerable { background: #FEE2E2; color: var(--red); }
.iw-semiVulnerable { background: #FEF3C7; color: #B45309; }
.iw-safe { background: #D1FAE5; color: var(--green); }

/* === Detail Panel === */
#detail-panel {
  position: absolute; top: 0; right: -360px; bottom: 0;
  width: var(--detail-w);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  transition: right 0.3s ease;
  z-index: 30;
}
#detail-panel.open { right: 0; }

.dp-header { padding: 16px; background: linear-gradient(135deg, #1e293b, #334155); color: #fff; }
.dp-title-row { display: flex; justify-content: space-between; align-items: flex-start; }
.dp-title-row h2 { font-size: 20px; }
.dp-close { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 24px; cursor: pointer; line-height: 1; }
.dp-close:hover { color: #fff; }
.dp-station-name { font-size: 13px; opacity: 0.85; margin: 4px 0 8px; }
.dp-badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.dp-vulnerable { background: var(--red); color: #fff; }
.dp-semiVulnerable { background: var(--amber); color: #000; }
.dp-safe { background: var(--green); color: #fff; }

.dp-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dp-section h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }
.dp-section h4 { font-size: 12px; font-weight: 500; color: var(--text-muted); margin: 10px 0 6px; }

.dp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dp-item { display: flex; flex-direction: column; }
.dp-item label { font-size: 11px; color: var(--text-muted); }
.dp-item span { font-size: 13px; font-weight: 500; }
.dp-margin { color: var(--primary); font-weight: 700; }

/* POI */
.dp-poi-loading { font-size: 13px; color: var(--text-muted); padding: 8px 0; }
.poi-category { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.poi-category:first-child { margin-top: 0; }
.poi-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; border-radius: 4px; }
.poi-item:hover { background: var(--bg); }
.poi-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.poi-info { flex: 1; }
.poi-name { font-size: 13px; font-weight: 500; }
.poi-dist { font-size: 11px; color: var(--text-muted); }
.poi-empty { font-size: 13px; color: var(--text-muted); padding: 8px 0; }

/* === Route Panel === */
#route-panel {
  position: absolute; bottom: -300px; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  max-height: 280px;
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: bottom 0.3s ease;
  z-index: 35;
  padding: 0;
}
#route-panel.open { bottom: 0; }

.route-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.route-header h3 { font-size: 14px; font-weight: 600; }
.route-actions { display: flex; gap: 6px; }

.route-body {
  flex: 1; overflow-y: auto; padding: 0 16px 12px;
}

.wp-empty { font-size: 13px; color: var(--text-muted); padding: 8px 0; }
.wp-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.wp-num { width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.wp-name { flex: 1; }
.wp-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 0 4px; }
.wp-remove:hover { color: var(--red); }

.route-total { padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 6px; font-size: 14px; }
.route-leg { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.leg-label { color: var(--text); }
.leg-detail { color: var(--text-muted); }

/* === Toast === */
#toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 20px; border-radius: 8px; font-size: 13px; color: #fff; box-shadow: var(--shadow-lg); transition: opacity 0.3s; }
.toast-info { background: #334155; }
.toast-warn { background: var(--amber); color: #000; }
.toast-error { background: var(--red); }
.toast-fade { opacity: 0; }

/* === Mobile === */
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; --detail-w: 100%; }

  #sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100%; height: auto; max-height: 60vh;
    border-right: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    z-index: 40;
    transform: translateY(calc(100% - 48px));
    transition: transform 0.3s ease;
    margin-left: 0 !important;
  }
  #sidebar.expanded { transform: translateY(0); }
  #sidebar.collapsed { transform: translateY(calc(100% - 48px)); }

  #sidebar::before {
    content: '';
    display: block; width: 36px; height: 4px;
    background: var(--border); border-radius: 2px;
    margin: 8px auto;
  }

  .btn-label { display: none; }

  #detail-panel {
    position: fixed; top: auto; bottom: -100%; left: 0; right: 0;
    width: 100%; height: 75vh;
    border-radius: 16px 16px 0 0;
    transition: bottom 0.3s ease;
  }
  #detail-panel.open { bottom: 0; right: 0; }

  #route-panel { left: 0; right: 0; }
}

@media (min-width: 769px) {
  #btn-sidebar-toggle { display: none; }
}
