:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #101828;
  --text-soft: #344054;
  --muted: #667085;
  --muted-soft: #98a2b3;
  --accent: #1d4ed8;
  --accent-hover: #1a45bd;
  --accent-soft: #eef3ff;
  --accent-line: #dbe4ff;
  --ok: #0f766e;
  --ok-soft: #ecfdf5;
  --ok-line: #b7ebdd;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-line: #fde9b8;
  --bad: #b42318;
  --bad-soft: #fef3f2;
  --bad-line: #fecdca;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-pane: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-raise: 0 1px 2px rgba(16, 24, 40, 0.08);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", "PingFang SC", "Microsoft YaHei UI",
    "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.icon {
  flex: none;
  display: block;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.brand-text p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}

.pill {
  color: #3538cd;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  font-family: var(--mono);
}

.status {
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-soft);
}

.status.is-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-line);
}

.status.is-ok .dot {
  background: #12b76a;
}

.status.is-bad {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: var(--bad-line);
}

.status.is-bad .dot {
  background: #f04438;
}

/* ---------- layout ---------- */

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 16px 20px;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pane);
}

.pane-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 45px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.pane-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.pane-head-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pane-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pane-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

/* ---------- form ---------- */

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.field-head label,
.field-label {
  font-size: 13px;
  font-weight: 600;
}

.counter {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}

textarea,
input[type="text"] {
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
}

textarea:focus,
input[type="text"]:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

textarea.is-invalid,
input[type="text"].is-invalid {
  background: #fff;
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

textarea.is-invalid:focus-visible,
input[type="text"].is-invalid:focus-visible {
  outline-color: var(--bad);
}

.field-error {
  margin: 2px 0 4px;
  color: var(--bad);
  font-size: 12px;
  line-height: 1.5;
}

::placeholder {
  color: var(--muted-soft);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.questions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-card {
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.question-card:focus-within {
  border-color: var(--line-strong);
}

.question-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.q-index {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  flex: none;
  color: var(--muted);
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
}

.question-head .seg {
  margin-right: auto;
}

.seg {
  display: inline-flex;
  padding: 2px;
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.seg button {
  padding: 3px 10px;
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.seg button:hover {
  color: var(--text);
}

.seg button.is-active {
  background: #fff;
  box-shadow: var(--shadow-raise);
  font-weight: 600;
}

.seg button[data-type="noul"].is-active {
  color: #3538cd;
}

.seg button[data-type="choice"].is-active {
  color: var(--ok);
}

.seg button[data-type="score"].is-active {
  color: var(--warn);
}

.question-card .instructions {
  min-height: 62px;
}

.criteria {
  margin-top: 12px;
}

.criteria-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.criteria-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.criteria-grid label {
  display: block;
  min-width: 0;
}

.criteria-grid label span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row .row-key {
  flex: 0 1 34%;
  min-width: 0;
}

.row .row-desc,
.row .row-level {
  flex: 1 1 auto;
  min-width: 0;
}

.level-index {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  color: var(--muted);
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn[hidden] {
  display: none;
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-raise);
}

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

.btn-ghost {
  color: var(--text-soft);
  background: #fff;
  border-color: var(--line-strong);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--muted-soft);
}

.btn-ghost.is-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-line);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  background: #f2f4f7;
  border-color: var(--line);
}

.icon-btn.danger:hover:not(:disabled) {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: var(--bad-line);
}

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

.pane-foot .btn-primary {
  min-width: 132px;
}

.is-loading .icon {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- results ---------- */

.result-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.meta-chip {
  padding: 2px 7px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: auto;
  padding: 32px 0;
  color: var(--muted-soft);
}

.empty-mark {
  width: 30px;
  height: 30px;
}

.empty p {
  margin: 0;
  font-size: 13px;
}

.empty[hidden] {
  display: none;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: none;
}

.result-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.result-card-head .q-text {
  margin: 1px 0 0;
  min-width: 0;
  color: var(--text-soft);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.type-badge {
  padding: 2px 7px;
  flex: none;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: lowercase;
}

.type-badge.noul {
  color: #3538cd;
  background: var(--accent-soft);
}

.type-badge.choice {
  color: var(--ok);
  background: var(--ok-soft);
}

.type-badge.score {
  color: var(--warn);
  background: var(--warn-soft);
}

.verdict {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.verdict-value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.verdict-label {
  color: var(--muted);
  font-size: 13px;
}

.conf {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.conf.high {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-line);
}

.conf.mid {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: var(--warn-line);
}

.conf.low {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: var(--bad-line);
}

.bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  background: #eef0f4;
  border-radius: 999px;
}

.bar > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.results.is-ready .bar > span {
  width: var(--w, 0%);
}

.bar.tone-ok > span {
  background: var(--ok);
}

.bar.tone-bad > span {
  background: #d92d20;
}

.bar-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(16, 24, 40, 0.25);
}

.scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted-soft);
  font-size: 11px;
}

.noul-note {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
}

.noul-note span {
  padding: 2px 8px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.noul-note.is-plain {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.prob-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 12px;
}

.prob-row {
  display: grid;
  grid-template-columns: minmax(88px, 1.1fr) minmax(80px, 2fr) 56px;
  align-items: center;
  gap: 10px;
  margin: 0 -8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.prob-row .bar > span {
  background: #a9c2f8;
}

.prob-row.is-chosen {
  background: var(--accent-soft);
}

.prob-row.is-chosen .bar > span {
  background: var(--accent);
}

.prob-key {
  min-width: 0;
  color: var(--text-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.prob-row.is-chosen .prob-key {
  color: #1d4ed8;
  font-weight: 600;
}

.prob-pct {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
}

.raw {
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.raw summary {
  padding: 9px 12px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.raw-body {
  position: relative;
  padding: 0 12px 12px;
}

.raw-body .btn {
  position: absolute;
  top: 0;
  right: 12px;
}

.raw pre {
  max-height: 320px;
  margin: 0;
  padding: 10px;
  overflow: auto;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

.error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: none;
  margin-bottom: 12px;
  padding: 10px 12px;
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid var(--bad-line);
  border-radius: var(--radius);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.error[hidden] {
  display: none;
}

/* ---------- skeleton ---------- */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.skeleton-line {
  height: 10px;
  background: #eef0f4;
  border-radius: 999px;
  animation: pulse 1.4s ease-in-out infinite;
}

.skeleton-line.w-40 {
  width: 40%;
}

.skeleton-line.w-70 {
  width: 70%;
}

.skeleton-line.tall {
  height: 26px;
  border-radius: var(--radius-sm);
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

/* ---------- responsive ---------- */

@media (max-width: 1020px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
  }

  .pane {
    overflow: visible;
  }

  .pane-body {
    overflow: visible;
  }

  .pane-foot {
    position: sticky;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(16, 24, 40, 0.04);
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .topbar-meta {
    justify-content: flex-start;
  }

  .pane-head,
  .pane-body,
  .pane-foot {
    padding-right: 12px;
    padding-left: 12px;
  }

  .pane-foot .btn-primary {
    flex: 1 1 auto;
    min-width: 0;
  }

  .prob-row {
    grid-template-columns: minmax(70px, 1fr) minmax(60px, 1.4fr) 48px;
    gap: 8px;
  }

  .row {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .row .row-key {
    flex: 1 1 100%;
  }

  .row .row-desc,
  .row .row-level {
    flex: 1 1 0;
    min-width: 0;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .row > .icon-btn:last-child {
    margin-left: auto;
  }
}

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