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

:root {
  --bg:           #09090f;
  --bg-2:         #0f0f18;
  --bg-card:      #13131e;
  --bg-card-h:    #181827;
  --bg-input:     #0d0d16;
  --border:       #1e1e30;
  --border-sub:   #161622;

  --text:         #dde1f0;
  --text-2:       #8080a8;
  --text-muted:   #4a4a6a;

  --blue:         #4f8ef7;
  --blue-dark:    #2563eb;
  --blue-dim:     #1e3a6e;

  --green:        #22c55e;
  --green-dim:    #14532d;
  --green-bg:     #0a2818;

  --yellow:       #f59e0b;
  --yellow-dim:   #78350f;
  --yellow-bg:    #2d1a04;

  --red:          #ef4444;
  --red-dim:      #7f1d1d;
  --red-bg:       #200a0a;

  --gray:         #6b7280;
  --gray-dim:     #374151;
  --gray-bg:      #111118;

  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 4px 24px rgba(0,0,0,.5);
}

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand { display: flex; align-items: baseline; gap: 10px; }
.brand-logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--blue);
  font-family: monospace;
}
.brand-sub { font-size: .75rem; color: var(--text-2); letter-spacing: .05em; text-transform: uppercase; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .72rem;
  color: var(--text-2);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}
.sync-dot.ok   { background: var(--green); box-shadow: 0 0 6px var(--green); }
.sync-dot.err  { background: var(--red); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--blue-dark);
  color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover { background: var(--blue); }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: .75rem; }
.btn-icon { font-size: 1rem; line-height: 1; }

/* ── Main ────────────────────────────────────────────────────────────────── */
.main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
  transition: border-color .2s;
}
.stat-card:hover { border-color: var(--border-sub); }
.stat-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-2); margin-top: 2px; }

.stat-feasible .stat-value { color: var(--green); }
.stat-critical .stat-value  { color: var(--yellow); }
.stat-nogo .stat-value      { color: var(--red); }
.stat-total .stat-value     { color: var(--blue); }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 12px;
  font-size: .8125rem;
  outline: none;
  transition: border-color .15s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--blue-dim); }

.filter-group { display: flex; gap: 4px; }
.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover  { color: var(--text); border-color: var(--gray-dim); }
.filter-btn.active { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }

/* ── Request Cards ───────────────────────────────────────────────────────── */
.requests-container { display: flex; flex-direction: column; gap: 8px; }

.req-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  transition: all .15s;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 16px;
}
.req-card:hover { background: var(--bg-card-h); border-color: var(--blue-dim); }

.req-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-feasible  { background: var(--green);  box-shadow: 0 0 6px var(--green); }
.dot-critical  { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot-not_feasible { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-unknown   { background: var(--gray);  box-shadow: 0 0 6px var(--gray); }

.req-main { min-width: 0; }
.req-route {
  font-size: .9375rem;
  font-weight: 600;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  margin-bottom: 3px;
}
.req-route .arrow { color: var(--text-muted); margin: 0 6px; }
.req-meta {
  font-size: .75rem;
  color: var(--text-2);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.req-meta span { white-space: nowrap; }

.req-distances { text-align: right; font-size: .75rem; }
.req-dist-main { color: var(--text); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.req-dist-sub  { color: var(--text-muted); }

.req-badge {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 3px 9px;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-feasible   { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-dim); }
.badge-critical   { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-dim); }
.badge-not_feasible { background: var(--red-bg);  color: var(--red);    border: 1px solid var(--red-dim); }
.badge-unknown    { background: var(--gray-bg);   color: var(--gray);   border: 1px solid var(--gray-dim); }

/* ── Detail Panel ────────────────────────────────────────────────────────── */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.panel-backdrop.hidden { display: none; }

.detail-panel {
  position: fixed;
  top: 0; right: 0;
  width: min(520px, 100vw);
  height: 100vh;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,.6);
  transition: transform .25s ease;
}
.detail-panel.hidden { transform: translateX(100%); display: flex; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title { font-size: 1rem; font-weight: 600; }
.panel-close {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.panel-close:hover { background: var(--bg-card); color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Panel sections ──────────────────────────────────────────────────────── */
.pane-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pane-section-head {
  padding: 10px 16px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-sub);
  background: rgba(255,255,255,.02);
}
.pane-section-body { padding: 14px 16px; }

.kv-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: .8125rem;
}
.kv-key   { color: var(--text-2); white-space: nowrap; }
.kv-val   { color: var(--text); word-break: break-all; }
.kv-mono  { font-family: 'SF Mono', 'Fira Code', monospace; }

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-sub);
}
.status-row:last-child { border-bottom: none; }
.status-row-label { flex: 1; font-size: .8rem; color: var(--text-2); }
.status-row-val   { font-size: .8rem; }

.analysis-text {
  font-size: .8125rem;
  color: var(--text-2);
  line-height: 1.7;
  white-space: pre-wrap;
}

.open-questions { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.open-q {
  font-size: .8rem;
  color: var(--yellow);
  padding: 4px 0;
  padding-left: 12px;
  border-left: 2px solid var(--yellow-dim);
}

.recommendation {
  background: var(--blue-dim);
  border: 1px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .8125rem;
  color: var(--text);
  margin-top: 8px;
}

.analyze-btn {
  width: 100%;
  padding: 10px;
  background: var(--blue-dark);
  border: 1px solid var(--blue);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.analyze-btn:hover { background: var(--blue); }
.analyze-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Loading / Empty ─────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-2);
  font-size: .875rem;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .3; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 500;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: .8125rem;
  max-width: 340px;
  animation: slideIn .2s ease;
  box-shadow: var(--shadow);
}
.toast-ok    { border-color: var(--green-dim); color: var(--green); }
.toast-error { border-color: var(--red-dim);   color: var(--red); }
.toast-info  { border-color: var(--blue-dim);  color: var(--blue); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } }

/* ── Override & Priority ─────────────────────────────────────────────────── */
.priority-banner {
  padding: 6px 14px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  text-align: center;
}
.priority-high { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-dim); }
.priority-vip  { background: #1a0a2e; color: #c084fc; border: 1px solid #6b21a8; }
.priority-low  { background: var(--gray-bg); color: var(--gray); border: 1px solid var(--gray-dim); }

.override-active-note {
  font-size: .74rem;
  color: var(--blue);
  background: var(--blue-dim);
  border: 1px solid #1e3a6e;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  margin-bottom: 12px;
}

.kv-missing { color: var(--yellow); font-style: italic; }

.analysis-block {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.analysis-block-feasible { border-left-color: var(--green); }
.analysis-block-critical  { border-left-color: var(--yellow); }
.analysis-block-not_feasible { border-left-color: var(--red); }
.analysis-block-unknown   { border-left-color: var(--gray); }
.analysis-block-ok        { border-left-color: var(--green); }
.analysis-block-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.analysis-block-value { font-size: .9rem; color: var(--text); font-family: monospace; margin-top: 2px; }
.analysis-block-msg   { font-size: .78rem; color: var(--text-2); margin-top: 6px; line-height: 1.5; }

.override-form { display: flex; flex-direction: column; gap: 10px; }
.override-row  { display: flex; flex-direction: column; gap: 4px; }
.override-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.override-input, .override-select, .override-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .85rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
}
.override-input:focus, .override-select:focus, .override-textarea:focus {
  border-color: var(--blue);
}
.override-input { text-transform: uppercase; }
.override-textarea { resize: vertical; min-height: 64px; font-family: inherit; }
.override-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Debug Section ───────────────────────────────────────────────────────── */
.debug-section {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.debug-summary {
  padding: 10px 14px;
  font-size: .75rem;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-2);
  list-style: none;
  user-select: none;
}
.debug-summary:hover { color: var(--text-2); }
.debug-body { padding: 12px 14px; background: var(--bg); }
.debug-row {
  display: flex;
  gap: 10px;
  font-size: .74rem;
  padding: 3px 0;
  border-bottom: 1px solid var(--border-sub);
}
.debug-key  { color: var(--text-muted); min-width: 130px; flex-shrink: 0; }
.debug-val  { color: var(--text-2); font-family: monospace; word-break: break-all; }
.debug-missing { color: var(--yellow); }
.debug-pre {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: .72rem;
  color: var(--text-2);
  overflow-x: auto;
  white-space: pre;
  font-family: monospace;
  margin: 0;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-dim); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .req-card  { grid-template-columns: auto 1fr auto; }
  .req-distances { display: none; }
  .header { padding: 0 14px; }
  .main { padding: 14px; }
}
