:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --text: #18211d;
  --muted: #66716b;
  --line: #d8dfdb;
  --line-strong: #b8c3bd;
  --brand: #166447;
  --brand-dark: #0d4933;
  --brand-soft: #e9f3ee;
  --amber: #9a6613;
  --amber-soft: #fbf2df;
  --red: #a13b3b;
  --red-soft: #f9eaea;
  --blue: #315f86;
  --blue-soft: #eaf1f7;
  --shadow: 0 8px 24px rgba(29, 43, 35, 0.07);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.55;
}

a { color: inherit; }
button, input, select { font: inherit; }
button, a { letter-spacing: 0; }

.app-header {
  min-height: 66px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background: #17382c;
  border-bottom: 3px solid #ba7a24;
}

.compact-header { position: sticky; top: 0; z-index: 30; }

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.app-brand > span,
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #fff;
  background: var(--brand);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  font-weight: 800;
}

.header-actions { display: flex; align-items: center; gap: 16px; }
.header-actions a { color: #e8f0ec; text-decoration: none; font-size: 14px; }
.header-actions a:hover { color: #fff; text-decoration: underline; }
.user-chip { padding: 5px 9px; border: 1px solid rgba(255,255,255,.24); border-radius: 4px; font-size: 13px; }

.eyebrow,
.section-label {
  margin: 0;
  color: var(--brand);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.muted { color: var(--muted); }

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 15px;
  color: #fff;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 5px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover { background: var(--brand-dark); }
.full-width { width: 100%; margin-top: 22px; }

.flash {
  max-width: 1240px;
  margin: 14px auto;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
}
.flash.ok { color: var(--brand-dark); background: var(--brand-soft); border-color: #bdd8ca; }
.flash.error { color: #752929; background: var(--red-soft); border-color: #e2bcbc; }

/* Authentication */
.login-page { min-height: 100vh; background: #edf1ef; }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, .9fr) minmax(460px, 1.1fr); }
.auth-intro {
  padding: 9vh 8vw;
  color: #eef5f1;
  background: #17382c;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-intro .brand-mark { width: 48px; height: 48px; margin-bottom: 34px; }
.auth-intro .eyebrow { color: #c4d9ce; }
.auth-intro h1 { margin: 16px 0; font-size: 46px; line-height: 1.18; font-weight: 720; }
.intro-copy { max-width: 560px; color: #cbd8d1; font-size: 16px; }
.protocol-strip { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 30px; }
.protocol-strip span { padding: 7px 10px; border: 1px solid rgba(255,255,255,.2); border-radius: 4px; font-size: 12px; }
.auth-card { align-self: center; width: min(480px, calc(100% - 48px)); margin: 40px auto; padding: 30px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.auth-tab { padding: 11px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; cursor: pointer; }
.auth-tab.active { color: var(--brand); border-color: var(--brand); font-weight: 700; }
.auth-panel h2 { margin: 0 0 2px; }
.auth-panel label { display: block; margin: 15px 0 5px; font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 43px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}
input:focus, select:focus { outline: 2px solid rgba(22,100,71,.18); border-color: var(--brand); }
.field-hint { min-height: 18px; margin: 4px 0 0; font-size: 12px; }
.field-hint.success { color: var(--brand); }
.field-hint.danger { color: var(--red); }

/* Dashboard */
.dashboard-shell { max-width: 1240px; margin: 0 auto; padding: 34px 24px 60px; }
.dashboard-summary {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  padding: 28px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.dashboard-summary h1 { margin: 7px 0 5px; font-size: 28px; }
.dashboard-summary p { margin: 0; color: var(--muted); }
.progress-summary { width: 260px; flex: 0 0 auto; }
.progress-summary strong { display: block; font-size: 28px; }
.progress-summary span { color: var(--muted); font-size: 13px; }
.progress-track { height: 6px; margin-top: 10px; overflow: hidden; background: #dce4e0; border-radius: 2px; }
.progress-track i { display: block; height: 100%; background: #3c8b67; }
.task-list { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.task-row { display: grid; grid-template-columns: 46px minmax(0,1fr) 72px 70px; align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: 0; }
.task-row.completed { background: #f7faf8; }
.task-index { color: var(--muted); font-variant-numeric: tabular-nums; }
.task-copy h2 { margin: 4px 0 0; font-size: 15px; line-height: 1.4; font-weight: 650; }
.task-meta { display: flex; gap: 10px; color: var(--muted); font-size: 11px; }
.task-meta code { overflow: hidden; text-overflow: ellipsis; }
.task-status { font-size: 12px; color: var(--amber); }
.task-row.completed .task-status { color: var(--brand); }
.pagination-bar { display: flex; justify-content: center; align-items: center; gap: 22px; margin-top: 20px; }
.pagination-bar a { color: var(--brand); font-weight: 700; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* Review */
.review-progress { width: min(330px, 30vw); }
.review-progress > span { color: #c7d7cf; font-size: 11px; }
.review-progress strong { float: right; font-size: 12px; }
.review-progress .progress-track { clear: both; margin-top: 6px; background: rgba(255,255,255,.18); }
.review-progress .progress-track i { background: #d4a354; }
.review-shell { max-width: 1880px; margin: 0 auto; padding: 20px 22px 48px; }
.claim-banner { padding: 17px 20px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 5px; }
.claim-banner > div { display: flex; justify-content: space-between; gap: 20px; }
.claim-banner code { color: var(--muted); font-size: 11px; }
.claim-banner h1 { margin: 8px 0 4px; font-size: 19px; line-height: 1.4; }
.claim-banner p { margin: 0; color: var(--muted); font-size: 12px; }
.review-layout { display: grid; grid-template-columns: minmax(360px,1fr) minmax(360px,1fr) 330px; gap: 14px; align-items: start; }
.artifact-panel, .rating-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.artifact-panel { min-width: 0; overflow: hidden; }
.artifact-header { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 15px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.artifact-header > div:first-child { display: flex; align-items: center; gap: 10px; }
.artifact-letter { display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: #37453e; border-radius: 4px; font-weight: 800; }
.artifact-header h2 { margin: 0; font-size: 17px; }
.verdict-chip { text-align: right; }
.verdict-chip span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.verdict-chip strong { font-size: 14px; color: var(--brand-dark); }
.verdict-chip em { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-style: normal; }
.artifact-scroll { height: calc(100vh - 203px); min-height: 620px; overflow-y: auto; padding: 12px; scrollbar-gutter: stable; }
.artifact-section { margin-bottom: 9px; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: 4px; background: #fff; }
.artifact-section.summary, .artifact-section.result { border-left-color: var(--brand); }
.artifact-section.evidence { border-left-color: var(--blue); }
.artifact-section.reasoning { border-left-color: var(--amber); }
.artifact-section summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 11px; cursor: pointer; font-size: 13px; font-weight: 720; background: #fafbfa; }
.artifact-section summary small { color: var(--muted); font-size: 9px; text-transform: uppercase; font-weight: 700; }
.artifact-content { min-width: 0; max-width: 100%; padding: 11px 12px 13px; overflow-wrap: anywhere; word-break: break-word; font-size: 12px; color: #2e3833; }
.artifact-content > :first-child { margin-top: 0; }
.artifact-content > :last-child { margin-bottom: 0; }
.artifact-content p, .artifact-content ul, .artifact-content ol { margin: 7px 0; }
.artifact-content h3 { margin: 14px 0 6px; font-size: 13px; }
.artifact-content pre, .artifact-content code { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.artifact-content pre { padding: 10px; overflow-x: auto; white-space: pre-wrap; background: #f4f6f5; border: 1px solid var(--line); border-radius: 4px; }
.artifact-content table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 10px; }
.artifact-content th, .artifact-content td { padding: 6px; vertical-align: top; border: 1px solid var(--line); overflow-wrap: anywhere; }
.artifact-content th { background: #f1f4f2; text-align: left; }
.artifact-content th:first-child, .artifact-content td:first-child { width: 44px; }
.bilingual-content { display: grid; gap: 11px; }
.lang-block { position: relative; min-width: 0; padding: 10px 11px 10px 36px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.lang-block > :nth-child(2) { margin-top: 0; }
.lang-block > :last-child { margin-bottom: 0; }
.lang-zh { background: #fbfcfb; border-color: #d9e2dd; }
.lang-label { position: absolute; top: 10px; left: 9px; width: 20px; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.rating-panel { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; }
.rating-head { padding: 17px 17px 13px; border-bottom: 1px solid var(--line); }
.rating-head h2 { margin: 7px 0 4px; font-size: 19px; }
.rating-head p { margin: 0; color: var(--muted); font-size: 12px; }
.rating-panel form { padding: 13px; }
.rating-item { margin: 0 0 12px; padding: 0; border: 0; }
.rating-item legend { margin-bottom: 2px; font-size: 13px; font-weight: 760; }
.rating-item p { min-height: 34px; margin: 0 0 7px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.segmented-choice { display: grid; grid-template-columns: 1fr .72fr 1fr; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; }
.segmented-choice label { margin: 0; }
.segmented-choice input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-choice span { display: grid; place-items: center; min-height: 34px; padding: 5px; color: #56605b; background: #fff; border-right: 1px solid var(--line); font-size: 10px; cursor: pointer; }
.segmented-choice label:last-child span { border-right: 0; }
.segmented-choice input:checked + span { color: #fff; background: #31433a; font-weight: 760; }
.segmented-choice input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }
.submit-review { width: 100%; margin-top: 5px; }
.save-note { margin: 8px 0 0; color: var(--muted); text-align: center; font-size: 10px; }

/* Legacy admin templates */
.page-header { padding: 20px 26px; color: #fff; background: #17382c; }
.page-header h1 { margin: 5px 0; }
.top-nav { display: flex; gap: 12px; }
.top-nav a { color: #fff; }
main.page-shell, main.wide { max-width: 1240px; margin: 24px auto; padding: 0 24px 50px; }
.card, .hero-card { padding: 20px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.survey-table { width: 100%; border-collapse: collapse; }
.survey-table th, .survey-table td { padding: 9px; border-bottom: 1px solid var(--line); text-align: left; }
.danger { color: var(--red); }

@media (max-width: 1180px) {
  .review-layout { grid-template-columns: 1fr 1fr; }
  .rating-panel { grid-column: 1 / -1; position: static; max-height: none; }
  .rating-panel form { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 10px 18px; }
  .submit-review, .save-note { grid-column: 1 / -1; }
}

@media (max-width: 850px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-intro { min-height: auto; padding: 48px 28px; }
  .auth-intro h1 { font-size: 34px; }
  .app-header { padding: 12px 16px; flex-wrap: wrap; }
  .review-progress { order: 3; width: 100%; }
  .review-layout { grid-template-columns: 1fr; }
  .artifact-scroll { height: auto; max-height: 75vh; min-height: 520px; }
  .rating-panel { grid-column: auto; }
  .rating-panel form { display: block; }
  .task-row { grid-template-columns: 36px minmax(0,1fr) 66px; }
  .task-row .task-status { display: none; }
  .dashboard-summary { display: block; }
  .progress-summary { width: 100%; margin-top: 20px; }
}

.admin-shell { display: grid; gap: 18px; }
.admin-panel { padding: 20px; }
.admin-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.admin-panel-head h2 { margin: 2px 0 0; font-size: 20px; }
.admin-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(130px, 1fr)); gap: 10px; }
.admin-stat-card { padding: 14px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 5px; }
.admin-stat-card span { display: block; color: var(--muted); font-size: 12px; }
.admin-stat-card strong { display: block; margin-top: 3px; font-size: 24px; }
.admin-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 13px; }
.admin-field { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.admin-field input, .admin-field select, .admin-field textarea, .admin-inline-form input { width: 100%; padding: 9px 10px; color: var(--text); background: white; border: 1px solid var(--line-strong); border-radius: 4px; }
.admin-create-form > button, .admin-maintenance-form > button { margin-top: 14px; }
.admin-maintenance-toggle { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.admin-maintenance-toggle input { width: 17px; height: 17px; accent-color: var(--brand); }
.admin-table-wrap { overflow-x: auto; }
.survey-table { font-size: 13px; }
.survey-table th { color: var(--muted); background: var(--surface-soft); font-weight: 700; }
.survey-table td { vertical-align: top; }
.survey-table small { color: var(--muted); }
.admin-inline-form { display: flex; gap: 6px; min-width: 190px; }
.admin-inline-form button, .danger-button { padding: 7px 10px; white-space: nowrap; border: 1px solid var(--line-strong); border-radius: 4px; background: white; cursor: pointer; }
.danger-button { color: var(--red); border-color: #dfb4b4; }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .admin-grid, .compact-stats { grid-template-columns: 1fr; }
  .admin-panel { padding: 14px; }
}
