/* Theme variables live in shared/variables.css — loaded before this file. */

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

html { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg, #0f1117);
  color: var(--text, #e2e8f0);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Page header ────────────────────────────────────── */
.page-header {
  text-align: center;
  padding: 1.5rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border, #2d3148);
  flex-shrink: 0;
}

.page-header h1 { font-size: 1.65rem; font-weight: 700; margin-bottom: 0.3rem; }
.page-header h1 .accent { color: var(--accent-4); }
.page-header p { color: var(--muted, #8892a4); font-size: 0.875rem; max-width: 640px; margin: 0 auto; }

.back-link {
  display: inline-block;
  margin-bottom: 0.6rem;
  color: var(--muted, #8892a4);
  text-decoration: none;
  font-size: 0.8rem;
}
.back-link:hover { color: var(--accent-4); }

.ai-disclaimer {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  margin-top: 0.4rem;
  opacity: 0.7;
}

/* ── Theme toggle ───────────────────────────────────── */
.theme-toggle {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 100;
  background: var(--surface, #1a1d27);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text, #e2e8f0);
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface-2, #22253a); }

/* ── Main layout: 3 columns ─────────────────────────── */
.sampling-layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left: Controls ─────────────────────────────────── */
.ctrl-panel {
  border-right: 1px solid var(--border, #2d3148);
  overflow-y: auto;
  background: var(--surface, #1a1d27);
  padding: 0.75rem 1rem;
}

.panel-header {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

/* ── Preset selector ────────────────────────────────── */
.preset-section { margin-bottom: 1.25rem; }

.ctrl-label {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  margin-bottom: 0.3rem;
  display: block;
}

.preset-select {
  width: 100%;
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  border-radius: 5px;
  color: var(--text, #e2e8f0);
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  font-family: inherit;
}
.preset-select:focus { outline: none; border-color: var(--accent-4); }

.preset-desc {
  font-size: 0.72rem;
  color: var(--accent-4);
  margin-top: 0.35rem;
  line-height: 1.4;
  min-height: 2rem;
}

/* ── Parameter sliders ──────────────────────────────── */
.param-section { margin-bottom: 1.25rem; }

.param-row {
  margin-bottom: 0.85rem;
}

.param-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}

.param-name  { font-size: 0.78rem; font-weight: 600; }
.param-value {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent-4);
  font-weight: 600;
  font-family: "SF Mono", "Fira Code", monospace;
}

.param-slider {
  width: 100%;
  accent-color: var(--accent-4);
  cursor: pointer;
  height: 4px;
}

.param-hint {
  font-size: 0.68rem;
  color: var(--muted, #8892a4);
  margin-top: 0.2rem;
  line-height: 1.35;
}

/* ── Action buttons ─────────────────────────────────── */
.action-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.btn {
  padding: 0.45rem 0.75rem;
  border-radius: 5px;
  border: 1px solid var(--border, #2d3148);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  text-align: left;
}

.btn-primary {
  background: var(--accent-4);
  border-color: var(--accent-4);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: var(--surface-2, #22253a);
  color: var(--text, #e2e8f0);
}
.btn-secondary:hover { background: var(--highlight); border-color: var(--accent-4); }

.btn-ghost {
  background: transparent;
  color: var(--muted, #8892a4);
  font-size: 0.75rem;
}
.btn-ghost:hover { color: var(--text, #e2e8f0); background: var(--surface-2, #22253a); }

/* ── Sampled tokens history ─────────────────────────── */
.history-section { margin-bottom: 0.5rem; }

.history-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-height: 2rem;
  padding: 0.3rem;
  background: var(--surface-2, #22253a);
  border-radius: 5px;
  border: 1px solid var(--border, #2d3148);
}

.history-chip {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.72rem;
  background: var(--highlight);
  border: 1px solid var(--border, #2d3148);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  color: var(--text, #e2e8f0);
  animation: pop-in 0.15s ease;
}

.history-chip.latest {
  background: var(--accent-4);
  color: #fff;
  border-color: var(--accent-4);
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Centre: Bar chart ──────────────────────────────── */
.chart-panel {
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chart-header {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  border-bottom: 1px solid var(--border, #2d3148);
  padding-bottom: 0.4rem;
  flex-shrink: 0;
}

/* ── Bar chart rows ─────────────────────────────────── */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  min-height: 24px;
  position: relative;
}

.bar-token {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.75rem;
  width: 100px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text, #e2e8f0);
}

.bar-track {
  flex: 1;
  height: 18px;
  background: var(--surface-2, #22253a);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: var(--accent-4);
  border-radius: 3px;
  transition: width 0.25s ease;
  opacity: 0.85;
}

/* Zeroed by top-k/top-p */
.bar-fill.masked {
  background: var(--border, #2d3148);
  opacity: 0.4;
}

/* Currently sampled token */
.bar-row.sampled .bar-fill {
  background: var(--success);
  opacity: 1;
}
.bar-row.sampled .bar-token { color: var(--success); font-weight: 700; }

.bar-pct {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted, #8892a4);
  width: 42px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Pipeline diagram ───────────────────────────────── */
.pipeline-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface-2, #22253a);
  border-radius: 5px;
  border: 1px solid var(--border, #2d3148);
  font-size: 0.7rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  color: var(--muted, #8892a4);
}

.pipeline-step.active { color: var(--text, #e2e8f0); }
.pipeline-step.active .step-label { color: var(--accent-4); font-weight: 600; }

.step-label {
  background: var(--surface, #1a1d27);
  border: 1px solid var(--border, #2d3148);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
}

.pipeline-arrow { color: var(--border, #2d3148); }

/* ── Right: Histogram panel ─────────────────────────── */
.hist-panel {
  border-left: 1px solid var(--border, #2d3148);
  overflow-y: auto;
  background: var(--surface, #1a1d27);
  padding: 0.75rem 1rem;
}

.hist-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  border-bottom: 1px solid var(--border, #2d3148);
  padding-bottom: 0.4rem;
  margin-bottom: 0.6rem;
}

.hist-controls {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.hist-btn {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border, #2d3148);
  background: var(--surface-2, #22253a);
  color: var(--text, #e2e8f0);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}
.hist-btn:hover { background: var(--highlight); border-color: var(--accent-4); }

.hist-summary {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  margin-bottom: 0.5rem;
}

.hist-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hist-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
}

.hist-token {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.72rem;
  width: 90px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text, #e2e8f0);
}

.hist-track {
  flex: 1;
  height: 14px;
  background: var(--surface-2, #22253a);
  border-radius: 3px;
  overflow: hidden;
}

.hist-fill {
  height: 100%;
  background: var(--accent-2);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.hist-count {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted, #8892a4);
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}

.hist-empty {
  color: var(--muted, #8892a4);
  font-style: italic;
  font-size: 0.8rem;
  padding: 0.5rem 0;
}

/* ── Custom prompt section ───────────────────────────── */
.custom-section {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.1rem;
}

.custom-input {
  width: 100%;
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  border-radius: 5px;
  color: var(--text, #e2e8f0);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8rem;
  padding: 0.5rem 0.6rem;
  resize: vertical;
  line-height: 1.5;
}
.custom-input:focus {
  outline: none;
  border-color: var(--accent-4);
}
.custom-input::placeholder { color: var(--muted, #8892a4); }

.infer-status {
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  min-height: 1.2em;
  line-height: 1.4;
  word-break: break-word;
}
.infer-status.ready  { color: var(--success); }
.infer-status.error  { color: var(--danger, #f87171); }
.infer-status.loading { color: var(--accent-4); }

/* ── Mobile tab bar ──────────────────────────────────── */
.mobile-tab-bar {
  display: none;
  background: var(--surface, #1a1d27);
  border-bottom: 1px solid var(--border, #2d3148);
}
.mobile-tab {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted, #8892a4);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}
.mobile-tab.active { color: var(--accent-4); border-bottom-color: var(--accent-4); }

@media (max-width: 800px) {
  .mobile-tab-bar { display: flex; }

  .sampling-layout {
    grid-template-columns: 1fr;
  }

  .ctrl-panel  { display: none; }
  .chart-panel { display: none; }
  .hist-panel  { display: none; }

  .ctrl-panel.panel-active  { display: block; }
  .chart-panel.panel-active { display: flex; }
  .hist-panel.panel-active  { display: block; }
}
