:root {
  --bg: #f7f8f8;
  --surface: #ffffff;
  --surface-2: #f1f4f3;
  --text: #17201f;
  --muted: #667370;
  --line: #dbe2e0;
  --line-strong: #b8c5c1;
  --teal: #047c73;
  --teal-dark: #035e58;
  --teal-soft: #e4f4f1;
  --amber: #b86e00;
  --amber-soft: #fff2d8;
  --red: #b42318;
  --red-soft: #fff0ee;
  --blue: #295d8f;
  --shadow: 0 18px 50px rgba(24, 38, 35, 0.08);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: white;
  font-weight: 800;
}

.brand-title {
  font-size: 15px;
  font-weight: 760;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-section {
  margin-top: 18px;
}

.nav-label {
  margin: 18px 8px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.nav-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 11px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 650;
}

.nav-button.active {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--line-strong);
}

.status-dot.ok {
  background: var(--teal);
}

.status-dot.warn {
  background: var(--amber);
}

.main {
  min-width: 0;
  padding: 22px 26px 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.page-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  min-height: 38px;
  padding: 9px 13px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
}

.btn.primary {
  background: var(--teal);
  color: #fff;
}

.btn.warning {
  background: var(--amber-soft);
  color: #7b4700;
}

.btn.danger {
  background: var(--red-soft);
  color: var(--red);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.15fr) minmax(330px, 0.85fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 16px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfdfd;
}

.metric-value {
  font-size: 22px;
  font-weight: 820;
}

.metric-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.tab {
  padding: 10px 12px;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 730;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--teal-dark);
  background: transparent;
  border-bottom-color: var(--teal);
  box-shadow: none;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 180ms ease;
}

.study-card {
  display: grid;
  gap: 14px;
}

.survey-list {
  display: grid;
  gap: 12px;
}

.choice-grid {
  display: grid;
  gap: 8px;
}

.option-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.option-group legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.required-mark {
  color: var(--red);
}

.option-list {
  display: grid;
  gap: 8px;
}

.option-choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.option-choice:has(input:checked) {
  border-color: #7fc8bf;
  background: var(--teal-soft);
}

.option-choice input {
  margin-top: 2px;
  accent-color: var(--teal);
}

.choice {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.discussion {
  overflow: hidden;
}

.thread-top {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.thread-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tag.teal {
  border-color: #b9dcd7;
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.tag.amber {
  border-color: #f1d49d;
  background: var(--amber-soft);
  color: #7b4700;
}

.community-summary {
  margin: 14px 16px 0;
  padding: 12px;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--teal-soft);
  font-size: 13px;
}

.comment-list {
  padding: 14px 16px 18px;
  max-height: 570px;
  overflow: auto;
  background: #fff;
}

.comment {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 6px;
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.comment.top {
  box-shadow: none;
}

.comment.reply {
  margin-top: 14px;
  margin-left: 30px;
  background: transparent;
}

.comment-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.comment-head strong {
  color: var(--text);
  font-size: 14px;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid #c7d4d0;
  background: #dfe8ff;
  color: #35446f;
  font-size: 12px;
  font-weight: 800;
}

.comment p {
  margin: 0;
  color: #24302f;
  font-size: 17px;
  line-height: 1.55;
}

.comment-main {
  min-width: 0;
  padding: 4px 0 12px;
}

.thread-rail {
  position: relative;
  display: flex;
  justify-content: center;
}

.thread-rail::before {
  content: "";
  position: absolute;
  top: 38px;
  bottom: 0;
  width: 1px;
  background: #d3dbd8;
}

.collapse-dot {
  z-index: 1;
  width: 24px;
  height: 24px;
  margin-top: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2px solid #94a3a0;
  border-radius: 999px;
  background: #fff;
  color: #2f3b39;
  font-size: 17px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

.collapse-dot.empty {
  width: 10px;
  height: 10px;
  margin-top: 48px;
  border-width: 1px;
  background: #fff;
}

.reply-toggle {
  margin-top: 10px;
  color: var(--blue);
  background: transparent;
  font-size: 12px;
  font-weight: 780;
}

.comment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  margin-top: 12px;
  color: #52615f;
  font-size: 14px;
  font-weight: 760;
}

.vote-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: #536664;
  line-height: 0;
}

.vote-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.vote-btn:hover:not(:disabled),
.vote-btn.active {
  background: #eef6f4;
  color: var(--teal-dark);
}

.vote-count {
  min-width: 34px;
  color: #465654;
  font-variant-numeric: tabular-nums;
}

.more-replies {
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 999px;
  background: transparent;
  color: #52615f;
  font-size: 14px;
  font-weight: 760;
}

.more-replies:hover {
  background: #eef2f1;
}

.reply-list {
  margin-top: 4px;
}

.bottom-lock {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #fbfcfc;
}

.lock-copy {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.log {
  max-height: 230px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1716;
  color: #d8e7e4;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.risk-list {
  display: grid;
  gap: 9px;
}

.risk {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.risk strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.risk span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.question-bank {
  display: grid;
  gap: 14px;
}

.login-panel {
  max-width: 460px;
  margin: 56px auto 0;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #f2b8b5;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
  font-weight: 720;
}

.completion-text {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 9px 13px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
}

.import-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.import-box summary {
  min-height: 42px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
  cursor: pointer;
}

.import-box[open] {
  padding-bottom: 14px;
}

.import-box[open] summary {
  border-bottom: 1px solid var(--line);
}

.import-box .field,
.import-box .btn {
  margin: 12px 14px 0;
}

.example-code {
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9f8;
  color: #273331;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.question-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfdfd;
}

.clean-panel {
  box-shadow: none;
}

.inline-header {
  padding: 8px 0;
  border-bottom: 0;
}

.question-editor-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(130px, 0.35fr) auto auto;
  gap: 10px;
  align-items: end;
}

.field.compact {
  margin-bottom: 0;
}

.required-toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
}

.required-toggle input {
  accent-color: var(--teal);
}

.choice-editor-list {
  display: grid;
  gap: 8px;
}

.choice-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.choice-editor input {
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.condition-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.open-question textarea[data-freeze-copy-paste="true"] {
  border-color: #e0b45d;
  background: #fffaf0;
}

.hidden {
  display: none !important;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .grid.two,
  .grid.three,
  .metric-row,
  .question-editor-head,
  .choice-editor {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 16px 14px 24px;
  }

  .topbar,
  .panel-header,
  .bottom-lock {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .btn {
    flex: 1 1 auto;
  }

  .comment.reply {
    margin-left: 12px;
  }
}
