/* ── Variables ──────────────────────────────────────────────────── */
:root {
  --bg-0:      #0D1117;
  --bg-1:      #161B22;
  --bg-2:      #21262D;
  --bg-3:      #30363D;
  --border:    #30363D;
  --border-hi: #58A6FF;
  --text-0:    #E6EDF3;
  --text-1:    #8B949E;
  --text-2:    #6E7681;
  --accent:    #58A6FF;
  --accent-dim:#1F6FEB22;
  --green:     #3FB950;
  --red:       #F85149;
  --yellow:    #D29922;
  --radius:    6px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg-0); color: var(--text-0);
             font-family: var(--font-ui); font-size: 14px; line-height: 1.5; }

/* ── Shell ──────────────────────────────────────────────────────── */
.app-shell  { display: flex; flex-direction: column; min-height: 100vh; }
.app-header { background: var(--bg-1); border-bottom: 1px solid var(--border);
              position: sticky; top: 0; z-index: 100; }
.header-inner { display: flex; align-items: center; justify-content: space-between;
                max-width: 1600px; margin: 0 auto; padding: 0 20px; height: 48px; }
.logo       { display: flex; align-items: center; gap: 8px;
              font-weight: 700; font-size: 15px; color: var(--text-0); }
.logo-icon  { color: var(--accent); font-size: 18px; }
.header-badge { font-size: 11px; color: var(--text-1); background: var(--bg-2);
                border: 1px solid var(--border); border-radius: 20px;
                padding: 2px 10px; font-family: var(--font-mono); }
.app-main   { flex: 1; max-width: 1600px; width: 100%; margin: 0 auto;
              padding: 24px 20px; }

/* ── Layout ─────────────────────────────────────────────────────── */
.analyzer-layout { display: flex; flex-direction: column; gap: 20px; }

/* ── Upload Panel ────────────────────────────────────────────────── */
.upload-panel { transition: all 0.3s ease; }
.upload-panel.compact .upload-zone { padding: 16px; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-1);
  transition: all 0.2s ease;
  cursor: pointer;
}
.upload-zone:hover,
.upload-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-idle {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; padding: 60px 20px;
  text-align: center;
}
.upload-icon { font-size: 48px; opacity: 0.5; }
.upload-hint { font-size: 16px; font-weight: 600; color: var(--text-0); }
.upload-sub  { color: var(--text-1); font-size: 12px; }
.upload-limit{ color: var(--text-2); font-size: 11px; }

.upload-processing {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 40px 20px;
}
.status-text { color: var(--text-1); font-family: var(--font-mono);
               font-size: 13px; }
.progress-bar  { width: 320px; max-width: 100%; height: 4px;
                 background: var(--bg-3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent);
                 transition: width 0.3s ease; }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ──────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; margin-top: 10px;
  border-radius: var(--radius); font-size: 13px;
}
.alert-error  { background: #F8514922; border: 1px solid #F8514944;
                color: #FF7B72; }
.alert-close  { background: none; border: none; color: inherit;
                cursor: pointer; font-size: 18px; opacity: 0.7; padding: 0 4px; }
.alert-close:hover { opacity: 1; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; font-family: var(--font-ui);
  cursor: pointer; border: 1px solid transparent;
  transition: all 0.15s ease; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #79C0FF; border-color: #79C0FF; }
.btn-ghost  { background: var(--bg-2); color: var(--text-0);
              border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-3); border-color: var(--text-1); }
.btn-sm  { padding: 4px 10px; font-size: 12px; }
.btn-xs  { padding: 3px 8px;  font-size: 11px; }

/* ── Summary Bar ─────────────────────────────────────────────────── */
.summary-bar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
}
.summary-item { display: flex; flex-direction: column; gap: 1px; }
.summary-label { font-size: 10px; color: var(--text-2);
                 text-transform: uppercase; letter-spacing: 0.06em; }
.summary-value { font-size: 13px; font-weight: 600; color: var(--text-0);
                 font-family: var(--font-mono); }
.summary-actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Page Tabs ───────────────────────────────────────────────────── */
.page-tabs {
  display: flex; gap: 4px; overflow-x: auto;
  padding-bottom: 2px; margin-bottom: 2px;
}
.page-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg-1); border: 1px solid var(--border);
  border-bottom: none; color: var(--text-1); cursor: pointer;
  font-size: 12px; font-family: var(--font-ui); white-space: nowrap;
  transition: all 0.15s;
}
.page-tab:hover  { color: var(--text-0); background: var(--bg-2); }
.page-tab.active { color: var(--text-0); background: var(--bg-2);
                   border-color: var(--border-hi); color: var(--accent); }
.tab-badge {
  background: var(--accent-dim); color: var(--accent);
  border-radius: 10px; padding: 0 6px; font-size: 10px;
  font-weight: 700;
}

/* ── Page Content ────────────────────────────────────────────────── */
.page-content {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 16px;
  min-height: 600px;
}
@media (max-width: 1100px) {
  .page-content { grid-template-columns: 1fr; }
}

/* ── Viz Panel ───────────────────────────────────────────────────── */
.viz-panel, .data-panel {
  display: flex; flex-direction: column; gap: 10px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
}
.panel-header h3 { font-size: 13px; font-weight: 600; color: var(--text-0); }
.panel-meta { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }

.viz-image-wrap {
  background: #fff; border-radius: var(--radius);
  overflow: hidden; display: flex; justify-content: center;
  max-height: 700px; overflow-y: auto;
}
.viz-image { max-width: 100%; display: block; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.legend-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-1);
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 7px;
}
.legend-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}

/* ── Data Panel ──────────────────────────────────────────────────── */
.data-tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
}
.data-tab {
  padding: 6px 14px; background: none; border: none;
  color: var(--text-1); cursor: pointer; font-size: 12px;
  font-family: var(--font-ui); border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: all 0.15s;
}
.data-tab:hover  { color: var(--text-0); }
.data-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.data-content {
  flex: 1; overflow: hidden; display: flex; flex-direction: column;
}

/* ── Region Cards ────────────────────────────────────────────────── */
.regions-list {
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; max-height: 620px; padding-right: 4px;
}
.region-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  cursor: pointer; transition: all 0.15s;
}
.region-card:hover  { border-color: var(--text-1); }
.region-card.selected { border-color: var(--accent);
                        background: var(--accent-dim); }
.region-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.region-index {
  width: 22px; height: 22px; border-radius: 4px;
  background: var(--bg-3); color: var(--text-1);
  font-size: 11px; font-weight: 700; font-family: var(--font-mono);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.region-dot   { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.region-label { font-weight: 600; font-size: 12px; flex: 1; }
.region-score { font-size: 11px; color: var(--green);
                font-family: var(--font-mono); }
.region-coords {
  font-size: 10px; color: var(--text-2); font-family: var(--font-mono);
  margin-bottom: 4px;
}
.region-preview {
  font-size: 12px; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.region-no-words { font-size: 11px; color: var(--text-2); font-style: italic; }

/* ── ContextText / JSON ──────────────────────────────────────────── */
.context-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; margin-bottom: 6px;
}
.context-stats { font-size: 11px; color: var(--text-2);
                 font-family: var(--font-mono); }

.context-text {
  flex: 1; overflow: auto; background: var(--bg-1);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-family: var(--font-mono); font-size: 12px;
  color: var(--text-0); line-height: 1.7; white-space: pre-wrap;
  max-height: 580px;
}
.json-text { color: #79C0FF; }

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

/* ── Result panel container ──────────────────────────────────────── */
.result-panel { display: flex; flex-direction: column; gap: 10px; }
