:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dfe6ee;
  --border-strong: #c8d3df;
  --text: #152033;
  --muted: #657286;
  --brand: #2156d8;
  --brand-strong: #1744b3;
  --brand-soft: #eaf0ff;
  --success: #13865f;
  --danger: #c33c54;
  --warning: #ad6a0b;
  --shadow: 0 10px 30px rgba(29, 51, 84, 0.07);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
code, pre, textarea { font-family: var(--mono); }
.hidden { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(33, 86, 216, 0.13), transparent 34%),
    radial-gradient(circle at 85% 88%, rgba(28, 161, 126, 0.10), transparent 34%),
    var(--bg);
}
.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 22px;
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -0.03em; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #5237c7);
  color: white; font-weight: 800; letter-spacing: -0.05em;
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .11em; }
.muted { color: var(--muted); }
.form-error { min-height: 20px; color: var(--danger); margin: -8px 0 0; font-size: 13px; }

.app { min-height: 100vh; }
.topbar {
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  background: #111827;
  color: white;
  border-bottom: 1px solid #1f2937;
  position: sticky; top: 0; z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 11px; }
.topbar-brand strong { display: block; font-size: 15px; }
.topbar-brand span { display: block; margin-top: 2px; color: #9ca3af; font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.status-dot { display: inline-flex; align-items: center; gap: 7px; color: #cbd5e1; font-size: 12px; }
.status-dot i { width: 7px; height: 7px; background: #36c691; border-radius: 50%; box-shadow: 0 0 0 4px rgba(54,198,145,.12); }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar {
  background: #f8fafc;
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex; flex-direction: column; gap: 22px;
}
.sidebar-section { display: grid; gap: 12px; }
.history-section { min-height: 0; flex: 1; }
.section-heading, .panel-heading, .results-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading h2, .panel-heading h2, .results-header h2 { margin: 2px 0 0; font-size: 16px; letter-spacing: -.02em; }
.sidebar-help { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.history-list { display: grid; gap: 7px; overflow: auto; max-height: calc(100vh - 290px); padding-right: 2px; }
.history-item {
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
  border-radius: 10px; padding: 10px; color: var(--text);
}
.history-item:hover, .history-item.active { background: white; border-color: var(--border); }
.history-item strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

.workspace { padding: 22px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 1px 2px rgba(15,23,42,.02); }
.control-strip {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) 110px 110px minmax(180px, 1fr) auto;
  gap: 12px; align-items: end; padding: 15px;
}
.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 700; }
.field input, .select {
  width: 100%; min-height: 38px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: white; padding: 8px 10px; color: var(--text); outline: none;
}
.field input:focus, .select:focus, textarea:focus { border-color: #8eabf4; box-shadow: 0 0 0 3px rgba(33,86,216,.09); }
.button {
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 9px 14px;
  background: white; color: var(--text); font-weight: 700; font-size: 12px;
}
.button:hover { border-color: #9aabbf; }
.button.primary { background: var(--brand); border-color: var(--brand); color: white; box-shadow: 0 4px 12px rgba(33,86,216,.18); }
.button.primary:hover { background: var(--brand-strong); }
.button:disabled { cursor: wait; opacity: .65; }
.button.ghost { background: transparent; }
.topbar .button.ghost { color: #dbe4f0; border-color: #374151; }
.button.compact { padding: 6px 9px; font-size: 11px; }
.run-button { min-height: 39px; padding-inline: 18px; }
.run-icon { margin-right: 6px; font-size: 10px; }
.icon-button { width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 8px; background: white; color: var(--muted); }

.editors-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.editor-panel { overflow: hidden; }
.editor-panel .panel-heading { padding: 14px 15px 10px; }
.code-editor {
  width: 100%; min-height: 360px; resize: vertical; border: 0; border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border); border-radius: 0; background: #fbfcfe;
  color: #243247; padding: 14px 15px; outline: none; font-size: 12px; line-height: 1.55;
  tab-size: 2;
}
.editor-status { padding: 8px 14px; color: var(--success); background: #fbfefd; font-size: 10px; }
.editor-status.invalid { color: var(--danger); background: #fffafb; }

.empty-results { margin-top: 16px; min-height: 220px; display: grid; place-items: center; align-content: center; text-align: center; padding: 30px; }
.empty-results h2 { margin: 8px 0 5px; font-size: 18px; }
.empty-results p { max-width: 620px; color: var(--muted); margin: 0; line-height: 1.6; font-size: 13px; }
.empty-icon { font-size: 32px; color: var(--brand); }
.results { margin-top: 20px; }
.results-header { margin-bottom: 12px; }
.results-header h2 { font-size: 20px; }
.results-header .muted { margin: 5px 0 0; font-size: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi-card { padding: 14px; }
.kpi-card span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.kpi-card strong { display: block; margin-top: 5px; font-size: 21px; letter-spacing: -.03em; }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.answer-card { padding: 16px; overflow: hidden; }
.answer-card-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.answer-card h3 { margin: 0; font-size: 14px; }
.type-pill { padding: 4px 7px; border-radius: 99px; background: var(--brand-soft); color: var(--brand-strong); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.big-value { font-size: 32px; font-weight: 800; letter-spacing: -.04em; margin-bottom: 4px; }
.metric-note { color: var(--muted); font-size: 11px; }
.prob-list { display: grid; gap: 8px; margin-top: 14px; }
.prob-row { display: grid; grid-template-columns: minmax(0, 1fr) 54px; gap: 9px; align-items: center; }
.prob-label { display: grid; gap: 4px; min-width: 0; }
.prob-label span:first-child { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 5px; background: #edf1f6; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.prob-value { text-align: right; color: var(--muted); font: 10px var(--mono); }
.raw-panel { margin-top: 14px; overflow: hidden; }
.raw-panel summary { padding: 13px 15px; font-size: 12px; font-weight: 700; cursor: pointer; }
.raw-panel pre { margin: 0; border-top: 1px solid var(--border); background: #0f172a; color: #dbeafe; padding: 16px; max-height: 520px; overflow: auto; font-size: 11px; line-height: 1.55; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; background: #111827; color: white; border-radius: 10px; padding: 11px 14px; font-size: 12px; box-shadow: var(--shadow); }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .control-strip { grid-template-columns: 1fr 100px 100px; }
  .label-field { grid-column: 1 / 3; }
  .run-button { grid-column: 3; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 780px) {
  .topbar { padding: 0 14px; }
  .layout { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .history-section { display: none; }
  .workspace { padding: 14px; }
  .control-strip, .editors-grid, .answer-grid { grid-template-columns: 1fr; }
  .label-field, .run-button { grid-column: auto; }
  .code-editor { min-height: 280px; }
}
