/* ═══════════════════════════════════════════════════════════════════════════
   CSS Variables
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --bg-dark: #0f1117;
  --panel-bg: #181b24;
  --panel-border: #2a2e3a;
  --group-a: #ff4d6a;
  --group-b: #00d4ff;
  --group-c: #34d399;
  --facility: #fbbf24;
  --text-primary: #e8eaf0;
  --text-secondary: #8b90a0;
  --accent: #a78bfa;
  --danger: #ef4444;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family:'DM Sans',sans-serif;
  background:var(--bg-dark);
  color:var(--text-primary);
  height:100vh;
  display:flex;
  overflow:hidden;
}

/* Sidebar */
.sidebar {
  width:420px; min-width:420px; background:var(--panel-bg);
  border-right:1px solid var(--panel-border);
  display:flex; flex-direction:column; z-index:1000; overflow:hidden;
}

.sidebar-header { padding:20px 24px 16px; border-bottom:1px solid var(--panel-border); }

.sidebar-header h1 {
  font-family:'Space Mono',monospace; font-size:18px; font-weight:700;
  letter-spacing:-0.5px;
  background:linear-gradient(135deg,var(--group-a),var(--facility),var(--group-c),var(--group-b));
  -webkit-background-clip:text; -webkit-text-fill-color:transparent; margin-bottom:4px;
}

.sidebar-header p { font-size:12px; color:var(--text-secondary); }

/* Map Location Bar */
.map-location-bar {
  padding:8px 24px; border-bottom:1px solid var(--panel-border);
  background:rgba(139,144,160,0.05);
}

.location-row { display:flex; gap:8px; align-items:center; }

.location-row input {
  flex:1; background:var(--bg-dark); border:1px solid var(--panel-border);
  border-radius:6px; padding:7px 10px; color:var(--text-primary);
  font-family:'DM Sans',sans-serif; font-size:12px; outline:none;
}

.location-row input:focus { border-color:var(--text-secondary); }
.location-row input::placeholder { color:var(--text-secondary); opacity:0.6; }

/* Tabs */
.tabs { display:flex; border-bottom:1px solid var(--panel-border); }

.tab {
  flex:1; padding:10px; text-align:center;
  font-family:'Space Mono',monospace; font-size:9px; font-weight:700;
  text-transform:uppercase; letter-spacing:0.5px; cursor:pointer;
  background:transparent; border:none; color:var(--text-secondary);
  border-bottom:2px solid transparent; transition:all 0.2s;
}

.tab:hover { color:var(--text-primary); }
.tab.active { color:var(--text-primary); }
.tab.c-f { border-bottom-color:var(--facility); color:var(--facility); }
.tab.c-a { border-bottom-color:var(--group-a); color:var(--group-a); }
.tab.c-b { border-bottom-color:var(--group-b); color:var(--group-b); }
.tab.c-c { border-bottom-color:var(--group-c); color:var(--group-c); }
.tab.c-d { border-bottom-color:var(--accent); color:var(--accent); }

/* Tab Panels */
.tab-panel { display:none; flex:1; overflow-y:auto; padding:16px 24px; }
.tab-panel.active { display:block; }
.tab-panel::-webkit-scrollbar { width:4px; }
.tab-panel::-webkit-scrollbar-thumb { background:var(--panel-border); border-radius:4px; }

/* Group Labels */
.group-label {
  font-family:'Space Mono',monospace; font-size:11px; font-weight:700;
  text-transform:uppercase; letter-spacing:1.5px; margin-bottom:10px;
  display:flex; align-items:center; gap:8px;
}

.group-label .dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.label-a { color:var(--group-a); } .label-a .dot { background:var(--group-a); }
.label-b { color:var(--group-b); } .label-b .dot { background:var(--group-b); }
.label-c { color:var(--group-c); } .label-c .dot { background:var(--group-c); }
.label-f { color:var(--facility); } .label-f .dot { background:var(--facility); }

/* Group Name Input */
.group-name-input {
  background:transparent; border:none; border-bottom:1px dashed currentColor;
  color:inherit; font-family:'Space Mono',monospace; font-size:11px;
  font-weight:700; text-transform:uppercase; letter-spacing:1.5px;
  outline:none; width:160px; padding:2px 0;
}

.group-name-input:focus {
  border-bottom-style:solid; background:rgba(255,255,255,0.05);
  border-radius:2px; padding:2px 4px;
}

.edit-hint {
  font-size:9px; color:var(--text-secondary); font-weight:400;
  text-transform:none; letter-spacing:0; margin-left:auto; opacity:0.6;
}

/* Input Rows */
.input-row { display:flex; gap:8px; margin-bottom:8px; }

.input-row input {
  flex:1; background:var(--bg-dark); border:1px solid var(--panel-border);
  border-radius:8px; padding:10px 14px; color:var(--text-primary);
  font-family:'DM Sans',sans-serif; font-size:13px; outline:none;
  transition:border-color 0.2s;
}

.input-row input:focus { border-color:var(--accent); }
.input-row input::placeholder { color:var(--text-secondary); opacity:0.6; }

/* Buttons */
.btn {
  border:none; border-radius:8px; padding:10px 16px;
  font-family:'DM Sans',sans-serif; font-size:13px; font-weight:600;
  cursor:pointer; transition:all 0.2s; white-space:nowrap;
}

.btn-a { background:var(--group-a); color:#fff; } .btn-a:hover { background:#e8415d; }
.btn-b { background:var(--group-b); color:#0f1117; } .btn-b:hover { background:#00bde6; }
.btn-c { background:var(--group-c); color:#0f1117; } .btn-c:hover { background:#2ab882; }
.btn-f { background:var(--facility); color:#0f1117; } .btn-f:hover { background:#e5ab1a; }

.btn-clear-all { background:rgba(239,68,68,0.1); border:1px solid rgba(239,68,68,0.3); color:var(--danger); font-size:11px; padding:8px 12px; }
.btn-clear-all:hover { background:rgba(239,68,68,0.2); }

.btn-calc { background:rgba(167,139,250,0.15); border:1px solid rgba(167,139,250,0.3); color:var(--accent); font-size:11px; padding:8px 12px; }
.btn-calc:hover { background:rgba(167,139,250,0.25); }

/* Address Lists */
.address-list { list-style:none; margin-top:8px; }

.address-list li {
  display:flex; align-items:center; justify-content:space-between;
  padding:8px 12px; background:rgba(255,255,255,0.03);
  border-radius:6px; margin-bottom:4px; font-size:12px;
  color:var(--text-secondary); transition:background 0.15s;
}

.address-list li:hover { background:rgba(255,255,255,0.06); }

.addr-text { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-right:8px; }

.remove-btn {
  background:none; border:none; color:var(--danger); cursor:pointer;
  font-size:14px; padding:2px 6px; opacity:0.5; transition:opacity 0.15s;
}

.remove-btn:hover { opacity:1; }

.facility-count { font-size:11px; color:var(--text-secondary); margin-bottom:12px; }
.facility-count strong { color:var(--facility); }

/* Bulk Input */
.bulk-section { margin-top:8px; }

.bulk-toggle {
  background:none; border:none; color:var(--text-secondary); font-size:11px;
  cursor:pointer; padding:4px 0; font-family:'DM Sans',sans-serif;
}

.bulk-toggle:hover { color:var(--text-primary); }

.bulk-area { display:none; margin-top:8px; }
.bulk-area.open { display:block; }

.bulk-area textarea {
  width:100%; background:var(--bg-dark); border:1px solid var(--panel-border);
  border-radius:8px; padding:10px 14px; color:var(--text-primary);
  font-family:'DM Sans',sans-serif; font-size:12px; resize:vertical;
  min-height:80px; outline:none;
}

.bulk-area textarea:focus { border-color:var(--accent); }
.bulk-area .btn { margin-top:8px; width:100%; }

/* Distance Analysis */
.dist-header { font-family:'Space Mono',monospace; font-size:13px; font-weight:700; color:var(--accent); margin-bottom:16px; }

.summary-cards { display:grid; grid-template-columns:1fr 1fr 1fr; gap:10px; margin-bottom:20px; }

.summary-card {
  background:var(--bg-dark); border:1px solid var(--panel-border);
  border-radius:10px; padding:14px; text-align:center;
}

.card-label { font-size:9px; font-family:'Space Mono',monospace; text-transform:uppercase; letter-spacing:1px; color:var(--text-secondary); margin-bottom:6px; }
.card-value { font-family:'Space Mono',monospace; font-size:16px; font-weight:700; }
.card-sub { font-family:'Space Mono',monospace; font-size:11px; color:var(--text-secondary); margin-top:2px; }
.cv-a { color:var(--group-a); } .cv-b { color:var(--group-b); } .cv-c { color:var(--group-c); }

.dist-group-hdr {
  font-family:'Space Mono',monospace; font-size:11px; font-weight:700;
  text-transform:uppercase; letter-spacing:1.5px; padding:10px 0 6px;
  display:flex; align-items:center; gap:8px;
}

.dist-table { width:100%; border-collapse:collapse; margin-bottom:20px; font-size:11px; }

.dist-table th {
  text-align:left; font-family:'Space Mono',monospace; font-size:8px;
  text-transform:uppercase; letter-spacing:0.8px; color:var(--text-secondary);
  padding:6px 4px; border-bottom:1px solid var(--panel-border);
  position:sticky; top:0; background:var(--panel-bg);
}

.dist-table td { padding:5px 4px; border-bottom:1px solid rgba(255,255,255,0.04); color:var(--text-secondary); font-size:11px; }
.dist-table tr:hover td { background:rgba(255,255,255,0.03); }
.addr-col { max-width:90px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.dv { font-family:'Space Mono',monospace; font-size:10px; text-align:right; }
.dv-bold { font-weight:700; }
.avg-row td { border-top:2px solid var(--panel-border); padding-top:8px; font-weight:700; }
.avg-label { color:var(--text-primary); font-size:11px; }

.no-data { color:var(--text-secondary); font-size:12px; font-style:italic; padding:20px 0; }
.hint { margin-top:16px; font-size:11px; color:var(--text-secondary); line-height:1.6; }
.hint strong { color:var(--accent); }

/* Controls Section */
.controls-section {
  padding:12px 24px; border-top:1px solid var(--panel-border);
  display:flex; flex-direction:column; gap:8px;
}

.control-actions { display:flex; gap:8px; margin-bottom:8px; }
.control-actions .btn { flex:1; }

.control-panel { border-top:1px solid var(--panel-border); }

.control-panel-header {
  display:flex; align-items:center; gap:8px; padding:10px 0;
  cursor:pointer; transition:opacity 0.15s;
}

.control-panel-header:hover { opacity:0.8; }

.panel-title {
  font-family:'Space Mono',monospace; font-size:10px; font-weight:700;
  text-transform:uppercase; letter-spacing:1px; color:var(--text-secondary);
}

.panel-toggle { font-size:10px; color:var(--text-secondary); transition:transform 0.2s; }
.control-panel.collapsed .panel-toggle { transform:rotate(-90deg); }
.control-panel-content { padding:0 0 12px; display:block; }
.control-panel.collapsed .control-panel-content { display:none; }

.legend { display:flex; gap:12px; flex-wrap:wrap; }
.legend-item { display:flex; align-items:center; gap:5px; font-size:10px; color:var(--text-secondary); }
.legend-swatch { width:18px; height:7px; border-radius:3px; }
.sw-a { background:linear-gradient(90deg,rgba(255,77,106,0.3),var(--group-a)); }
.sw-b { background:linear-gradient(90deg,rgba(0,212,255,0.3),var(--group-b)); }
.sw-c { background:linear-gradient(90deg,rgba(52,211,153,0.3),var(--group-c)); }
.sw-f { background:var(--facility); border-radius:50%; width:7px; height:7px; }

.slider-row { display:flex; align-items:center; gap:10px; }
.slider-row label { font-size:10px; color:var(--text-secondary); font-family:'Space Mono',monospace; text-transform:uppercase; letter-spacing:1px; min-width:50px; }
.slider-row input[type="range"] { flex:1; accent-color:var(--accent); }

.toggle-row { display:flex; align-items:center; gap:8px; font-size:11px; color:var(--text-secondary); }
.toggle-row input { accent-color:var(--accent); }

/* Map */
#map { flex:1; height:100vh; }

/* Status Messages */
.geocode-status {
  position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
  background:var(--panel-bg); border:1px solid var(--panel-border);
  padding:10px 20px; border-radius:10px; font-size:13px;
  color:var(--text-secondary); z-index:2000; display:none;
  box-shadow:0 8px 32px rgba(0,0,0,0.4);
}

.geocode-status.show { display:block; }

.mobile-status {
  display:none; position:fixed; top:0; left:0; right:0;
  background:rgba(15,17,23,0.92); backdrop-filter:blur(10px);
  border-bottom:1px solid var(--panel-border);
  padding:12px 20px; z-index:3500;
  font-family:'Space Mono',monospace; font-size:12px;
  color:var(--accent); text-align:center;
  transform:translateY(-100%); transition:transform 0.3s ease;
}

.mobile-status.show { transform:translateY(0); }

.mobile-status-text { display:flex; align-items:center; justify-content:center; gap:10px; }

.mobile-status-spinner {
  width:14px; height:14px; border:2px solid var(--panel-border);
  border-top-color:var(--accent); border-radius:50%;
  animation:spin 0.8s linear infinite;
}

@keyframes spin { to { transform:rotate(360deg); } }

/* Route Tooltips */
.leaflet-tooltip.route-tip {
  background:rgba(24,27,36,0.95) !important; border:1px solid rgba(42,46,58,0.8) !important;
  color:#e8eaf0 !important; font-family:'DM Sans',sans-serif !important;
  font-size:12px !important; padding:10px 14px !important;
  border-radius:8px !important; box-shadow:0 4px 20px rgba(0,0,0,0.5) !important;
  white-space:nowrap;
}

.leaflet-tooltip.route-tip::before { border-right-color:rgba(24,27,36,0.95) !important; }

/* Mobile Navigation */
.mobile-nav {
  display:none; position:fixed; bottom:0; left:0; right:0;
  background:var(--panel-bg); border-top:1px solid var(--panel-border);
  padding:8px 0; padding-bottom:calc(8px + env(safe-area-inset-bottom));
  z-index:3000; justify-content:space-around;
}

.mobile-nav-btn {
  display:flex; flex-direction:column; align-items:center; gap:4px;
  background:none; border:none; color:var(--text-secondary);
  font-family:'Space Mono',monospace; font-size:9px; font-weight:700;
  text-transform:uppercase; letter-spacing:0.5px;
  padding:8px 20px; cursor:pointer; transition:all 0.2s;
}

.mobile-nav-btn.active { color:var(--accent); }
.mobile-nav-btn:hover { color:var(--text-primary); }
.mobile-nav-icon { width:22px; height:22px; stroke:currentColor; transition:all 0.2s; }
.mobile-nav-btn.active .mobile-nav-icon { filter:drop-shadow(0 0 6px var(--accent)); }

.mobile-data-view, .mobile-map-view, .mobile-results-view { display:none; }

/* Mobile Responsive */
@media (max-width:768px) {
  body { flex-direction:column; padding-bottom:70px; }
  .mobile-nav { display:flex; }
  .mobile-status { display:block; }
  .geocode-status { display:none !important; }
  .sidebar { display:none; }
  #map { display:none; }

  .mobile-data-view, .mobile-map-view, .mobile-results-view {
    position:fixed; top:0; left:0; right:0; bottom:70px;
    background:var(--bg-dark); overflow:hidden;
  }

  .mobile-data-view.active, .mobile-map-view.active, .mobile-results-view.active {
    display:flex; flex-direction:column;
  }

  .mobile-header {
    padding:16px 20px 12px; border-bottom:1px solid var(--panel-border);
    background:var(--panel-bg);
  }

  .mobile-header h1 {
    font-family:'Space Mono',monospace; font-size:16px; font-weight:700;
    background:linear-gradient(135deg,var(--group-a),var(--facility),var(--group-c),var(--group-b));
    -webkit-background-clip:text; -webkit-text-fill-color:transparent;
    margin-bottom:2px;
  }

  .mobile-header p { font-size:11px; color:var(--text-secondary); }

  .mobile-location-bar {
    padding:8px 16px; border-bottom:1px solid var(--panel-border);
    background:rgba(139,144,160,0.05);
  }

  .mobile-location-bar .location-row { display:flex; gap:8px; }

  .mobile-location-bar input {
    flex:1; background:var(--bg-dark); border:1px solid var(--panel-border);
    border-radius:6px; padding:10px 12px; color:var(--text-primary);
    font-family:'DM Sans',sans-serif; font-size:14px; outline:none;
  }

  .mobile-tabs {
    display:flex; border-bottom:1px solid var(--panel-border);
    background:var(--panel-bg); overflow-x:auto; -webkit-overflow-scrolling:touch;
  }

  .mobile-tabs::-webkit-scrollbar { display:none; }
  .mobile-tabs .tab { flex:none; padding:12px 16px; font-size:11px; }

  .mobile-content { flex:1; overflow-y:auto; padding:16px; -webkit-overflow-scrolling:touch; }

  .mobile-map-view #mobileMap { flex:1; width:100%; height:100%; }

  .mobile-results-content { flex:1; overflow-y:auto; padding:16px; -webkit-overflow-scrolling:touch; }

  .mobile-controls {
    padding:12px 16px; border-top:1px solid var(--panel-border);
    background:var(--panel-bg);
  }

  .mobile-controls .control-actions { display:flex; gap:8px; }
  .mobile-controls .btn { flex:1; padding:12px; font-size:13px; }

  .input-row input { padding:12px 14px; font-size:14px; }
  .input-row .btn { padding:12px 16px; }
  .address-list li { padding:12px; font-size:13px; }
  .remove-btn { font-size:18px; padding:4px 10px; }

  .summary-cards { grid-template-columns:1fr; gap:8px; }
  .summary-card { padding:16px; }
  .card-value { font-size:20px; }

  .dist-table { font-size:10px; }
  .dist-table th { font-size:7px; padding:4px 2px; }
  .dist-table td { padding:4px 2px; }
  .addr-col { max-width:60px; }
  .dv { font-size:9px; }

  .mobile-results-group { margin-bottom:20px; }

  .mobile-results-group-header {
    font-family:'Space Mono',monospace; font-size:11px; font-weight:700;
    text-transform:uppercase; letter-spacing:1.5px; padding:12px 0 8px;
    display:flex; align-items:center; gap:8px;
  }

  .mobile-result-card {
    background:var(--bg-dark); border:1px solid var(--panel-border);
    border-radius:10px; margin-bottom:8px; overflow:hidden;
    cursor:pointer; transition:border-color 0.2s;
  }

  .mobile-result-card:active { border-color:var(--accent); }

  .mobile-result-card-header {
    display:flex; align-items:center; justify-content:space-between;
    padding:12px 14px 4px;
  }

  .mobile-result-addr {
    font-size:12px; color:var(--text-secondary);
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
    flex:1; margin-right:8px;
  }

  .mobile-result-expand { font-size:10px; color:var(--text-secondary); transition:transform 0.2s; }
  .mobile-result-card.expanded .mobile-result-expand { transform:rotate(180deg); }

  .mobile-result-summary { display:flex; align-items:baseline; gap:10px; padding:0 14px 12px; }
  .mobile-result-avg { font-family:'Space Mono',monospace; font-size:16px; font-weight:700; }
  .mobile-result-avg-dist { font-family:'Space Mono',monospace; font-size:11px; color:var(--text-secondary); }

  .mobile-result-details { display:none; border-top:1px solid var(--panel-border); padding:10px 14px; }
  .mobile-result-card.expanded .mobile-result-details { display:block; }

  .mobile-result-detail-row {
    display:flex; align-items:center; padding:6px 0;
    border-bottom:1px solid rgba(255,255,255,0.04);
  }

  .mobile-result-detail-row:last-child { border-bottom:none; }
  .mobile-result-facility { font-family:'Space Mono',monospace; font-size:10px; font-weight:700; color:var(--facility); width:28px; }
  .mobile-result-time { font-family:'Space Mono',monospace; font-size:12px; font-weight:600; color:var(--text-primary); flex:1; }
  .mobile-result-dist { font-family:'Space Mono',monospace; font-size:11px; color:var(--text-secondary); }

  .mobile-result-avg-card { background:rgba(167,139,250,0.08); border-color:rgba(167,139,250,0.2); cursor:default; }
  .mobile-result-avg-card:active { border-color:rgba(167,139,250,0.2); }
}

@media (min-width:769px) {
  .mobile-nav, .mobile-data-view, .mobile-map-view, .mobile-results-view { display:none !important; }
}
