:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-muted: #eef2ed;
  --ink: #1f2933;
  --muted: #65727d;
  --line: #dbe2dd;
  --accent: #176b5f;
  --accent-dark: #0f4d45;
  --warn: #b7791f;
  --bad: #b42318;
  --ok: #16794f;
  --observe: #3569a8;
  --shadow: 0 12px 34px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.header-actions,
.toolbar-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.mobile-tabs {
  display: none;
}

.header-actions button:last-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(330px, 0.95fr) minmax(420px, 1.25fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.question-list-area,
.detail {
  min-height: calc(100vh - 112px);
}

.panel,
.toolbar,
.detail-card,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  margin-bottom: 14px;
}

.panel label,
.panel-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chapter-list {
  display: grid;
  gap: 8px;
}

.mobile-chapter-select {
  display: none;
}

.chapter-group-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chapter-group-label:first-of-type {
  margin-top: 0;
}

.chapter-btn {
  display: flex;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  background: #fff;
}

.chapter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.status-panel {
  position: sticky;
  top: 14px;
}

.progress-ring {
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress, 0deg), var(--surface-muted) 0);
}

.progress-ring strong,
.progress-ring span {
  grid-area: 1 / 1;
}

.progress-ring strong {
  transform: translateY(-9px);
  font-size: 28px;
}

.progress-ring span {
  transform: translateY(22px);
  color: var(--muted);
  font-size: 13px;
}

.breakdown {
  display: grid;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.toolbar strong {
  display: block;
}

.toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.question-list {
  display: grid;
  gap: 10px;
}

.question-card {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(31, 41, 51, 0.05);
  text-align: left;
}

.question-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(23, 107, 95, 0.16);
}

.question-card h3 {
  margin: 8px 0;
  font-size: 16px;
  line-height: 1.35;
}

.question-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.tag {
  display: inline-flex;
  max-width: 74%;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill[data-status="符合"] {
  background: #dff3e8;
  color: var(--ok);
}

.status-pill[data-status="觀察事項"] {
  background: #e2edf8;
  color: var(--observe);
}

.status-pill[data-status="不符合"] {
  background: #fde3df;
  color: var(--bad);
}

.status-pill[data-status="不適用"] {
  background: #eee9df;
  color: #6f5e43;
}

.detail {
  position: sticky;
  top: 18px;
  height: calc(100vh - 112px);
  overflow: auto;
}

.detail-card,
.empty-state {
  padding: 22px;
}

.hidden {
  display: none;
}

.empty-state {
  display: grid;
  min-height: 280px;
  place-content: center;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
}

.empty-state p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.detail-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-back {
  display: none;
}

.detail-head h2 {
  margin: 5px 0 0;
  font-size: 24px;
  line-height: 1.3;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.meta-grid div {
  padding: 12px;
  background: var(--surface-muted);
  border-radius: 8px;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dd {
  margin: 6px 0 0;
  line-height: 1.55;
}

.audit-block {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.audit-block h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.audit-block p,
.form-list {
  margin: 0;
  color: #35424d;
  line-height: 1.7;
}

.form-list {
  padding-left: 20px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title-row h3 {
  margin: 0;
}

.mini-label {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
}

.assessment-matches {
  display: grid;
  gap: 10px;
}

.assessment-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 12px;
}

.assessment-item strong {
  display: block;
  margin-bottom: 7px;
  line-height: 1.55;
}

.assessment-item p {
  margin: 0 0 8px;
  color: #35424d;
  line-height: 1.65;
}

.assessment-item details {
  margin-top: 8px;
}

.assessment-item summary {
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 700;
}

.evidence-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.full-answer p {
  margin-top: 8px;
  white-space: pre-line;
}

.audit-form {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.audit-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 260px 1fr;
  }

  .detail {
    grid-column: 1 / -1;
    position: static;
    height: auto;
  }
}

@media (max-width: 760px) {
  .app-header,
  .toolbar,
  .header-actions,
  .toolbar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px 10px 76px;
  }

  .app-header {
    gap: 12px;
    padding: 12px 14px;
  }

  .app-header h1 {
    font-size: 21px;
  }

  .app-header .eyebrow {
    font-size: 12px;
  }

  .mobile-tabs {
    position: sticky;
    top: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 9px 10px;
    background: rgba(245, 246, 244, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }

  .mobile-tabs button {
    min-height: 42px;
    border-radius: 999px;
    font-weight: 700;
  }

  .mobile-tabs button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  .mobile-tabs button:disabled {
    opacity: 0.45;
  }

  .sidebar,
  .question-list-area,
  .detail {
    min-height: auto;
  }

  body.mobile-detail-view .sidebar,
  body.mobile-detail-view .question-list-area {
    display: none;
  }

  body.mobile-list-view .detail {
    display: none;
  }

  .status-panel,
  .toolbar {
    position: static;
  }

  .status-panel {
    display: none;
  }

  .panel {
    margin-bottom: 10px;
    padding: 12px;
  }

  .mobile-chapter-select {
    display: block;
  }

  .chapter-list {
    display: none;
  }

  .toolbar {
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px;
  }

  .toolbar-controls {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .question-list {
    gap: 8px;
  }

  .question-card {
    min-height: 84px;
    padding: 12px;
  }

  .question-card h3 {
    font-size: 15px;
  }

  .question-card p {
    font-size: 12px;
  }

  .detail-card,
  .empty-state,
  .panel,
  .toolbar {
    box-shadow: none;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .detail {
    position: static;
    height: auto;
    overflow: visible;
  }

  .detail-card {
    padding: 14px;
  }

  .detail-head {
    display: grid;
    gap: 12px;
  }

  .detail-head h2 {
    font-size: 20px;
  }

  .detail-head-actions {
    justify-content: space-between;
  }

  .mobile-back {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 10px;
  }

  .audit-block {
    padding: 13px 0;
  }

  .audit-form {
    padding-bottom: 14px;
  }

  .assessment-item p {
    line-height: 1.7;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .toolbar,
  .header-actions,
  .question-list-area {
    display: none;
  }

  .app-header {
    border-bottom: 2px solid #111;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .detail {
    height: auto;
    overflow: visible;
  }

  .detail-card {
    border: 0;
    box-shadow: none;
  }
}
