:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #0b1120;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --type-a: #ef4444;
  --type-b: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875em;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.75rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.logo-mark {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.health-pills {
  display: flex;
  gap: 0.5rem;
}

.pill {
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-weight: 600;
}

.pill-ok {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.4);
}

.pill-err {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.4);
}

.pill-unknown {
  background: var(--surface);
  color: var(--muted);
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-badge {
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Settings Drawer */
.settings-drawer {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
}

.settings-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.field {
  flex: 1 1 280px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
}

/* Workspace Grid */
.workspace {
  max-width: 1440px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 1100px) {
  .workspace {
    grid-template-columns: 5fr 7fr;
    align-items: start;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
}

.step-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.card-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.15rem 0 0;
}

/* Inputs & Buttons */
input[type="text"],
input[type="url"],
select {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  outline: none;
}

input[type="text"]:focus,
input[type="url"]:focus,
select:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #082f49;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.05);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Dropzone */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1rem;
  text-align: center;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.5);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(56, 189, 248, 0.06);
}

.dropzone input[type="file"] {
  display: none;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.form-inline {
  display: flex;
  gap: 0.65rem;
}

.form-inline input {
  flex: 1;
}

.quick-samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.4rem;
}

.chip {
  background: var(--surface-alt);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}

.chip:hover {
  background: rgba(56, 189, 248, 0.15);
}

/* Alerts & Results */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  border: 1px solid var(--border);
}

.alert-info {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: #bae6fd;
}

.alert-ok {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

.alert-warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.alert-err {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.result-box,
.result-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-highlight {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(56, 189, 248, 0.08);
}

.stat-label {
  font-size: 0.73rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  word-break: break-all;
}

.math-banner {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.86rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Plot & Table */
.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.section-bar h3 {
  margin: 0;
  font-size: 0.95rem;
}

.plot-frame {
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: auto;
  max-height: 520px;
}

.plot-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.table-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 440px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface-alt);
  color: var(--muted);
  position: sticky;
  top: 0;
  font-weight: 600;
}

.badge-type {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.75rem;
}

.badge-type-A {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.badge-type-B {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.45);
}
