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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #4f8ef7;
  --accent2: #f7a24f;
  --text: #e2e8f0;
  --muted: #8892a4;
  --success: #48bb78;
  --warning: #f6ad55;
  --danger: #fc8181;
  --morning: #4f8ef7;
  --afternoon: #f7a24f;
  --sidebar-w: 300px;
}

body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

#app { display: flex; height: 100vh; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.logo {
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
}

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

.tab {
  flex: 1;
  padding: 10px 4px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color 0.15s, border-bottom 0.15s;
  border-bottom: 2px solid transparent;
}

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.tab-content { display: none; padding: 12px; flex-direction: column; gap: 10px; }
.tab-content.active { display: flex; }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.card h4 { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--muted);
}

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--border); color: var(--text); }
.btn:hover { opacity: 0.88; }

.stat { font-size: 0.82rem; color: var(--success); font-weight: 600; }

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

#map-legend {
  position: absolute;
  bottom: 40px;
  right: 12px;
  background: rgba(26,29,39,0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1000;
  font-size: 0.78rem;
}

.legend-item { display: flex; align-items: center; gap: 8px; }
.dot {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
}
.dot.zone { background: rgba(79,142,247,0.3); border: 2px solid var(--accent); }
.dot.cluster { background: var(--success); }
.dot.morning { background: var(--morning); }
.dot.afternoon { background: var(--afternoon); }

#status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(26,29,39,0.9);
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--muted);
  z-index: 1000;
  border-top: 1px solid var(--border);
}

/* ── Results ── */
.results-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.8rem;
  line-height: 1.7;
}

.results-panel .metric { display: flex; justify-content: space-between; }
.results-panel .metric span:last-child { color: var(--accent); font-weight: 700; }
.results-panel .section-title { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 8px 0 4px; }

/* ── Timeline ── */
#timeline-container { display: flex; flex-direction: column; gap: 8px; }

.timeline-vehicle { font-size: 0.78rem; }
.timeline-label { color: var(--muted); margin-bottom: 3px; font-size: 0.72rem; }
.timeline-bar-wrap { display: flex; gap: 3px; height: 20px; background: var(--border); border-radius: 4px; overflow: hidden; }
.timeline-bar {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 4px;
}
.timeline-bar.morning { background: var(--morning); }
.timeline-bar.afternoon { background: var(--afternoon); }

/* ── Scrollbar ── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Excel Import ── */
.divider {
  text-align: center; font-size: 0.72rem; color: var(--muted);
  position: relative; margin: 2px 0;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%; width: 38%; height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79,142,247,0.06);
}
.drop-icon { font-size: 1.4rem; }
.drop-text { font-size: 0.78rem; color: var(--muted); line-height: 1.5; }
.drop-text small { font-size: 0.7rem; }

.import-status {
  font-size: 0.78rem; padding: 6px 10px;
  border-radius: 6px; line-height: 1.5;
}
.import-status.success { background: rgba(72,187,120,0.12); color: var(--success); }
.import-status.error   { background: rgba(252,129,129,0.12); color: var(--danger); }
.import-status.loading { color: var(--muted); }

.excel-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.75rem;
  overflow: hidden;
}
.excel-preview table { width: 100%; border-collapse: collapse; }
.excel-preview th {
  background: var(--border); padding: 5px 8px;
  text-align: left; font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.excel-preview td { padding: 4px 8px; border-bottom: 1px solid var(--border); color: var(--text); }
.excel-preview tr:last-child td { border-bottom: none; }
.excel-preview .preview-more {
  text-align: center; padding: 5px; color: var(--muted);
  font-size: 0.72rem; border-top: 1px solid var(--border);
}
.excel-preview .err-row td { color: var(--danger); background: rgba(252,129,129,0.06); }

/* ── Auto Fleet ── */
.auto-fleet-result {
  background: rgba(79,142,247,0.08);
  border: 1px solid rgba(79,142,247,0.25);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.8;
}
.auto-fleet-result .afl-num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
  line-height: 1.2;
  margin-bottom: 4px;
}
.auto-fleet-result .afl-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}
.auto-fleet-result .afl-row b { color: var(--text); }
.auto-fleet-result .afl-warn {
  color: var(--warning);
  font-size: 0.72rem;
  margin-top: 4px;
}

/* ── Step Headers ── */
.step-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 2px;
}
.step-badge {
  width: 20px; height: 20px; flex-shrink: 0;
  background: var(--accent); color: #fff;
  border-radius: 50%; font-size: 0.7rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.step-header h3 { margin: 0; }

/* ── Stops Recommend Result ── */
.stops-result {
  background: rgba(72,187,120,0.08);
  border: 1px solid rgba(72,187,120,0.25);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.8;
}
.stops-result .sr-num {
  font-size: 1.4rem; font-weight: 800; color: var(--success);
  display: block; line-height: 1.2; margin-bottom: 4px;
}
.stops-result .sr-row {
  display: flex; justify-content: space-between; color: var(--muted);
}
.stops-result .sr-row b { color: var(--text); }
.stops-result .sr-limit {
  font-size: 0.72rem; color: var(--accent); margin-top: 4px;
}

/* ── Working Hours ── */
.wh-row {
  display: grid;
  grid-template-columns: 1fr 1fr 80px;
  gap: 6px;
}
.wh-row label { font-size: 0.72rem; }
.wh-row input[type="time"] { padding: 5px 6px; font-size: 0.78rem; }
.wh-summary {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  line-height: 1.6;
}
.wh-summary b { color: var(--text); }

/* ── Traffic Profile ── */
.traffic-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; margin-top: 4px;
}
.traffic-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); cursor: pointer; padding: 5px 4px;
  font-size: 0.7rem; font-weight: 600; line-height: 1.3;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: border-color .15s, color .15s, background .15s;
}
.traffic-btn small { font-size: 0.62rem; font-weight: 400; color: var(--muted); }
.traffic-btn.active { border-color: var(--accent); color: var(--text); background: rgba(79,142,247,.1); }
.traffic-btn.active small { color: var(--accent); }
.traffic-btn:hover:not(.active) { border-color: var(--muted); color: var(--text); }

/* ── Stops Histogram ── */
.hist-title {
  font-size: 0.7rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.06em; margin: 8px 0 4px;
}
.hist-container { display: flex; flex-direction: column; gap: 3px; }
.hist-row { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; }
.hist-label { width: 40px; color: var(--muted); flex-shrink: 0; text-align: right; }
.hist-bar-wrap { flex: 1; background: var(--border); border-radius: 2px; height: 10px; }
.hist-bar { height: 100%; background: var(--accent); border-radius: 2px; min-width: 2px; transition: width 0.3s; }
.hist-count { width: 24px; color: var(--muted); flex-shrink: 0; }

/* ── Histogram interactive ── */
.hist-row { cursor: pointer; border-radius: 4px; padding: 1px 2px; transition: background .15s; }
.hist-row:hover { background: rgba(79,142,247,.1); }
.hist-row.hist-active { background: rgba(79,142,247,.18); }
.hist-row.hist-active .hist-bar { background: var(--success); }
.hist-row.hist-active .hist-label,
.hist-row.hist-active .hist-count { color: var(--text); }

/* ── Timeline filter ── */
.timeline-vehicle { border-radius: 5px; padding: 2px 4px; transition: opacity .2s, background .15s; }
.timeline-vehicle:hover { background: rgba(255,255,255,.04); }
.timeline-vehicle.tl-active { background: rgba(79,142,247,.1); outline: 1px solid rgba(79,142,247,.3); }
.timeline-vehicle.tl-dim { opacity: 0.3; }

/* ── Plan Summary ── */
.plan-summary { font-size: 0.78rem; line-height: 1.7; }
.ps-row { display: flex; justify-content: space-between; align-items: center; }
.ps-row b { font-weight: 700; }
.ps-ok   { color: var(--success); }
.ps-warn { color: var(--warning); }
.ps-bad  { color: var(--danger); }
.ps-divider { border: none; border-top: 1px solid var(--border); margin: 5px 0; }
.ps-solver { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
