:root {
  --navy: #17356b;
  --navy-700: #102a58;
  --navy-500: #2b5aa8;
  --navy-050: #eef3fb;
  --accent: #e58316;
  --accent-050: #fff5e8;
  --accent-200: #f7d5a4;
  --ink: #111a2e;
  --ink-soft: #33405c;
  --muted: #64708c;
  --line: #e4e9f2;
  --line-soft: #eef1f7;
  --bg: #f5f7fc;
  --paper: #ffffff;
  --teal: #0f766e;
  --rose: #b42318;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 10px 28px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.011em; }
p { margin: 0; }
a { color: var(--navy-500); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--navy-500);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Header ---------- */

.topbar {
  background: linear-gradient(120deg, var(--navy-700) 0%, var(--navy) 58%, #24488a 100%);
  color: #fff;
}
.topbar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px 28px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.brand { display: flex; gap: 14px; align-items: flex-start; }
.brand-mark {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  color: #ffd9a8;
}
.topbar h1 { font-size: 1.32rem; font-weight: 600; }
.topbar-lead {
  margin-top: 4px;
  max-width: 56ch;
  color: #c3d5ef;
  font-size: 0.875rem;
}
.nav-link {
  flex: none;
  color: #dbe7f7;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.nav-link:hover { background: rgba(255, 255, 255, 0.12); text-decoration: none; }

/* ---------- Dataset bar ---------- */

.databar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.databar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 14px 28px 15px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}
.databar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.chip:hover { border-color: var(--navy-500); background: var(--navy-050); }
.chip .chip-n { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.chip[aria-pressed="true"] {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.chip[aria-pressed="true"] .chip-n { color: #b9cdec; }
.chip-upload { position: relative; overflow: hidden; border-style: dashed; }
.chip-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.note {
  flex: 1 1 100%;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}
.note svg { flex: none; margin-top: 2px; color: var(--accent); }
.note:empty { display: none; }

/* ---------- Workspace ---------- */

.workspace {
  max-width: 1560px;
  margin: 0 auto;
  padding: 22px 28px 40px;
  display: grid;
  grid-template-columns: 396px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.rail {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
}
.results { display: grid; gap: 16px; min-width: 0; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: 1rem; }
.card-meta { color: var(--muted); font-size: 0.8rem; }
.card-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 18px 8px;
}

/* ---------- Analysis picker ---------- */

.analysis-list { padding: 0 10px 12px; display: grid; gap: 3px; }
.analysis-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.analysis-btn .a-icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--navy-050);
  color: var(--navy-500);
}
.analysis-btn:hover { background: var(--bg); }
.analysis-btn[aria-pressed="true"] {
  background: var(--navy-050);
  color: var(--navy-700);
  font-weight: 600;
}
.analysis-btn[aria-pressed="true"] .a-icon { background: var(--navy); color: #fff; }

/* ---------- Dialog ---------- */

.dialog-head { padding: 15px 18px 12px; border-bottom: 1px solid var(--line-soft); }
.dialog-head h2 { font-size: 1rem; }
.hint {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}
.dialog-body { padding: 14px 18px 18px; }

.list-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.list-label .list-note { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 0.72rem; }

.varlist {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  padding: 4px;
  overflow-y: auto;
  display: grid;
  gap: 2px;
  align-content: start;
}
.varlist--source { height: 232px; }
.varlist--target { min-height: 62px; max-height: 148px; }
.varlist--single { min-height: 46px; }
.varlist:focus-within { border-color: var(--navy-500); }

.var-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  min-width: 0;
}
.var-row:hover { background: #f1f4fa; }
.var-row[aria-selected="true"] {
  background: var(--navy-050);
  border-color: #c9d8ef;
}
.var-icon {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #eef1f7;
  color: var(--muted);
}
.var-icon--scale { background: #e7f0fb; color: #2b5aa8; }
.var-icon--nominal { background: #fdf0e3; color: #b3670c; }
.var-icon--ordinal { background: #e6f4f1; color: var(--teal); }
.var-text { min-width: 0; display: grid; }
.var-name {
  font-size: 0.845rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.var-label {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.var-remove {
  margin-left: auto;
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #9aa6bd;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.var-row:hover .var-remove, .var-remove:focus-visible { color: var(--muted); }
.var-remove:hover { background: #fdeceb; color: var(--rose); }
.varlist-empty {
  padding: 12px 10px;
  color: #93a0ba;
  font-size: 0.78rem;
  text-align: center;
}

.arrows {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
}
.arrow-btn {
  width: 38px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.arrow-btn:hover { background: var(--navy-050); border-color: var(--navy-500); color: var(--navy-700); }

.targets { display: grid; gap: 12px; }

.options { display: grid; gap: 7px; margin-top: 14px; }
.options:empty { margin: 0; }
.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.check input { width: 15px; height: 15px; accent-color: var(--navy); cursor: pointer; }

.catbox {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}
.catbox:empty { display: none; }
.catbox-title { font-size: 0.75rem; font-weight: 600; color: var(--ink-soft); }
.catbox-note { font-size: 0.72rem; color: var(--muted); }

.dialog-actions {
  display: flex;
  gap: 9px;
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid var(--line-soft);
}
.btn {
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  padding: 9px 17px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--bg); border-color: #d4dce9; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  padding-inline: 26px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}
.btn-primary:hover { background: var(--navy-700); border-color: var(--navy-700); }
.btn-sm { padding: 7px 13px; font-size: 0.82rem; }

/* ---------- Output ---------- */

.output { padding: 18px; overflow-x: auto; }

.empty-state { padding: 26px 20px 30px; text-align: center; color: var(--muted); }
.empty-state .empty-art { color: #c6d1e5; margin-bottom: 12px; }
.empty-state h3 { font-size: 0.95rem; color: var(--ink); margin-bottom: 6px; }
.empty-state p { font-size: 0.86rem; max-width: 46ch; margin: 0 auto; }
.empty-steps {
  list-style: none;
  padding: 0;
  margin: 18px auto 0;
  display: grid;
  gap: 8px;
  max-width: 30rem;
  text-align: left;
}
.empty-steps li {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.84rem;
  color: var(--ink-soft);
  background: var(--bg);
  border-radius: 9px;
  padding: 9px 12px;
}
.empty-steps span {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--navy-050);
  color: var(--navy-700);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.76rem;
  font-weight: 600;
}
.result-sub { color: var(--muted); font-size: 0.8rem; }

.keycards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.keycard {
  flex: 1 1 200px;
  max-width: 268px;
  border: 1px solid var(--accent-200);
  background: linear-gradient(180deg, var(--accent-050) 0%, #fffdfa 100%);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.keycard-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: #8a5108;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.keycard-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.keycard-grid dt { color: var(--muted); font-size: 0.76rem; }
.keycard-grid dd {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
}

.spss-caption {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  margin: 18px 0 7px;
}
.spss-caption:first-of-type { margin-top: 0; }

.table-scroll { overflow-x: auto; }

table.spss {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  max-width: 100%;
  font-size: 0.82rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
table.spss th, table.spss td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}
table.spss th:last-child, table.spss td:last-child { border-right: 0; }
table.spss tbody tr:last-child td { border-bottom: 0; }
table.spss th {
  background: #f7f9fd;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}
table.spss td { color: var(--ink-soft); }
table.spss td.num, table.spss th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.spss td.lbl { color: var(--ink); font-weight: 500; }
table.spss th.hl { background: var(--accent-050); color: #8a5108; }
table.spss td.hl { background: #fffaf2; color: var(--ink); font-weight: 600; }
table.spss tr.total td { font-weight: 600; color: var(--ink); background: #fafbfe; }
table.spss tbody tr:hover td { background: #f7f9fd; }
table.spss tbody tr:hover td.hl { background: #fdf3e4; }

.footnote { color: var(--muted); font-size: 0.75rem; margin-top: 7px; }
.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend i {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--accent-050);
  border: 1px solid var(--accent-200);
  display: inline-block;
}
.formula {
  margin-top: 14px;
  background: var(--navy-700);
  color: #dce7f8;
  border-radius: 9px;
  padding: 11px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  overflow-x: auto;
}
.formula b { color: #ffd9a8; font-weight: 600; }

.error {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #fef4f3;
  color: #8f2318;
  border: 1px solid #f6d3cf;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.86rem;
}
.error svg { flex: none; margin-top: 1px; }

/* ---------- Data preview ---------- */

.table-wrap { overflow-x: auto; padding: 0 4px 6px; }
table.data {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.8rem;
}
table.data th, table.data td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  text-align: left;
}
table.data th {
  position: sticky;
  top: 0;
  background: var(--paper);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}
table.data td { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: #f7f9fd; }
table.data .col-pred { color: var(--teal); font-weight: 600; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .rail { position: static; }
  .varlist--source { height: 200px; }
}

@media (max-width: 640px) {
  .topbar-inner, .databar-inner, .workspace { padding-inline: 16px; }
  .topbar-inner { flex-direction: column; gap: 12px; }
  .workspace { padding-top: 16px; }
  .output { padding: 14px; }
  .keycards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
