:root {
  --ink: #182026;
  --muted: #66737f;
  --line: #d9e0e6;
  --panel: #ffffff;
  --paper: #f6f8f8;
  --green: #1f7a62;
  --green-soft: #e8f4ef;
  --blue: #246aa6;
  --blue-soft: #e7f0f8;
  --amber: #ad6a00;
  --amber-soft: #fff3dc;
  --red: #b13d3d;
  --red-soft: #fae8e8;
  --shadow: 0 18px 45px rgba(27, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button,
a,
label.file-import {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  background: #fbfcfc;
  border-right: 1px solid var(--line);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand-block p,
.eyebrow,
.section-header p,
.template-preview p,
.privacy-note {
  color: var(--muted);
}

.brand-block p {
  font-size: 13px;
  margin-top: 3px;
}

.nav-tabs {
  display: grid;
  gap: 6px;
}

.nav-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 11px 12px;
  border-radius: 7px;
  text-align: left;
  cursor: pointer;
}

.nav-tab:hover,
.nav-tab.active {
  background: var(--green-soft);
  color: var(--green);
}

.privacy-note {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  font-size: 12px;
  line-height: 1.6;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 4px;
}

.topbar h2 {
  font-size: 26px;
}

.topbar-actions,
.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.section-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.user-badge {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 8px 11px;
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.secondary-button,
label.file-import {
  border: 1px solid transparent;
  min-height: 38px;
  border-radius: 7px;
  padding: 8px 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.primary-button:hover {
  background: #16654f;
}

.secondary-button,
label.file-import {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover,
label.file-import:hover {
  border-color: #b9c6cf;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.danger-button {
  color: var(--red);
}

.secondary-button.active {
  color: var(--green);
  border-color: var(--green);
  background: var(--green-soft);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 88px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 28px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-header,
.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.toolbar {
  align-items: stretch;
}

.section-header h3 {
  font-size: 18px;
  margin-bottom: 4px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 10px;
  min-height: 38px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 98, 0.12);
}

.toolbar input {
  flex: 1 1 280px;
}

.sync-status {
  min-height: 42px;
  margin: -2px 0 12px;
  padding: 10px 12px;
  border-left: 3px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.sync-status.success {
  border-left-color: var(--green);
}

.sync-status.warning,
.connection-result.error {
  border-left-color: var(--amber);
  color: var(--amber);
}

.wjx-status-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(0, 2fr);
  gap: 10px;
  padding: 3px 0;
}

.wjx-status-row span {
  min-width: 0;
  word-break: break-word;
}

label.file-import input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

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

.task-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.task-card.overdue {
  border-left-color: var(--red);
}

.task-card.today {
  border-left-color: var(--amber);
}

.task-title {
  font-weight: 700;
  margin-bottom: 6px;
}

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

.task-repeat-note {
  margin-top: 7px;
  color: #9a5b00;
  font-size: 13px;
  font-weight: 600;
}

.task-meta,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  white-space: nowrap;
  background: var(--blue-soft);
  color: var(--blue);
}

.pill.red {
  background: var(--red-soft);
  color: var(--red);
}

.pill.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.green {
  background: var(--green-soft);
  color: var(--green);
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.psg-copy-table-wrap {
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.psg-copy-table {
  min-width: 900px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfc;
}

.table-sort-button {
  appearance: none;
  width: 100%;
  min-height: 30px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  padding: 4px 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  font-weight: 700;
  cursor: pointer;
}

.table-sort-button:hover,
.table-sort-button:focus-visible,
.table-sort-button.active {
  color: var(--green);
}

.table-sort-button:focus-visible {
  outline: 2px solid rgba(31, 122, 98, 0.28);
  outline-offset: 2px;
}

.sort-indicator {
  min-width: 13px;
  font-size: 13px;
  line-height: 1;
}

tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f9fbfb;
}

.subject-name {
  font-weight: 700;
  margin-bottom: 4px;
}

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

.template-list,
.template-preview,
.audit-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.template-list {
  padding: 8px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.template-button {
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 11px;
  text-align: left;
  cursor: pointer;
}

.template-button:hover,
.template-button.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.template-preview {
  padding: 14px;
}

.template-subject-search {
  width: min(310px, 100%);
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.template-subject-search input {
  width: 100%;
}

.template-preview textarea {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  line-height: 1.6;
  margin-bottom: 12px;
}

.audit-list {
  overflow: hidden;
}

.audit-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

dialog {
  width: min(960px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

.compact-dialog {
  width: min(720px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(17, 24, 31, 0.42);
}

.subject-form {
  padding: 20px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label,
.check-grid label {
  color: var(--muted);
  font-size: 12px;
  display: grid;
  gap: 6px;
}

.form-grid .wide {
  grid-column: span 2;
}

.form-grid textarea {
  min-height: 86px;
  resize: vertical;
}

.application-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin-bottom: 2px;
}

.detail-section {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px -20px 0;
  padding: 16px 20px 0;
}

.form-grid label.screening-alert-field {
  color: var(--red);
  font-weight: 700;
  border-left: 3px solid var(--red);
  padding-left: 10px;
}

.form-grid label.screening-alert-field select {
  font-weight: 600;
}

.form-grid label.screening-alert-field.positive {
  background: var(--red-soft);
  border-radius: 6px;
  padding: 8px 8px 8px 10px;
}

.screening-risk-text {
  color: var(--red);
  font-weight: 700;
  margin-top: 4px;
}

.detail-section h4 {
  margin: 0 0 12px;
  font-size: 15px;
}

.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.detail-title-row h4 {
  margin: 0;
}

.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-group {
  margin-top: 14px;
}

.choice-group > span,
.standalone-label {
  color: var(--muted);
  font-size: 12px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.choice-grid label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.45;
  background: #fff;
}

.choice-grid input {
  min-height: auto;
  margin: 2px 0 0;
}

.compact-choices {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.standalone-label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.standalone-label textarea {
  min-height: 76px;
  resize: vertical;
}

.medication-section {
  background: var(--red-soft);
  border-top-color: #e3a9a9;
  border-bottom: 1px solid #e3a9a9;
  padding-bottom: 16px;
}

.medication-section h4,
.medication-text {
  color: var(--red);
}

.medication-choice-grid label {
  border-color: #e3a9a9;
}

.scale-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scale-summary-grid > div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fff;
}

.scale-summary-grid span {
  color: var(--muted);
  font-size: 12px;
}

.scale-summary-grid strong {
  display: block;
  font-size: 24px;
  margin-top: 5px;
}

.risk-alert {
  border-left: 4px solid var(--red);
  background: var(--red-soft);
  color: var(--red);
  padding: 11px 12px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.55;
}

.booking-form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.booking-calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.booking-month-inline {
  min-width: 112px;
  padding: 0 4px;
  color: var(--ink);
  font-size: 18px;
  text-align: center;
}

.booking-help {
  margin: 0;
  text-align: right;
}

.resource-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.resource-band {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  background: #fff;
  border-radius: 8px;
  padding: 13px 14px;
}

.resource-band.mri {
  border-left-color: var(--green);
}

.resource-band strong {
  display: block;
  font-size: 22px;
  margin-top: 5px;
}

.booking-calendar-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.booking-calendar {
  min-width: 1050px;
  display: grid;
  grid-template-columns: repeat(7, minmax(140px, 1fr));
}

.booking-weekday {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f3f6f6;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.booking-day {
  min-height: 210px;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.booking-day.outside {
  background: #f7f8f8;
  color: #9aa4ac;
}

.booking-day.today {
  box-shadow: inset 0 0 0 2px var(--green);
}

.booking-day-number {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
}

.booking-day-slots {
  display: grid;
  gap: 6px;
}

.calendar-slot {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 2px 7px;
  align-items: center;
  border: 1px solid #b9d4e9;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-soft);
  color: var(--ink);
  padding: 6px 7px;
  text-align: left;
  cursor: pointer;
}

.calendar-slot > button {
  min-width: 0;
  min-height: auto;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.calendar-slot > .calendar-slot-book:first-child {
  color: var(--muted);
  font-size: 11px;
}

.calendar-participant-link,
.calendar-application-link,
.calendar-slot > .calendar-slot-book:nth-child(2) {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-participant-link:hover,
.calendar-participant-link:focus-visible,
.calendar-application-link:hover,
.calendar-application-link:focus-visible {
  color: var(--green);
  text-decoration: underline;
}

.calendar-slot.mri {
  border-color: #b7d9cd;
  border-left-color: var(--green);
  background: var(--green-soft);
}

.calendar-slot.available {
  background: #fff;
  border-style: dashed;
}

.calendar-slot.released {
  background: var(--amber-soft);
  border-color: #e0ba78;
  border-left-color: var(--amber);
  border-style: dashed;
}

.calendar-slot small {
  color: var(--muted);
  font-size: 11px;
}

.template-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.archive-panel {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.inline-checkbox,
.copy-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.copy-checkbox {
  font-weight: 700;
}

.psg-copy-completed {
  background: var(--green-soft);
}

.psg-copy-completed:hover {
  background: #dcefe7;
}

.psg-copy-subject-link {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
  font-weight: 800;
  cursor: pointer;
}

.psg-copy-subject-link:hover,
.psg-copy-subject-link:focus-visible {
  text-decoration: underline;
}

.psg-copy-operation {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.psg-copy-operation .secondary-button {
  min-height: 32px;
  padding: 6px 10px;
  white-space: nowrap;
}

.resource-sync-help {
  background: var(--green-soft);
  border-radius: 7px;
  padding: 10px 12px;
}

.calendar-slot small {
  grid-column: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-grid {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.check-grid label {
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  background: #f9fbfb;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--ink);
}

.check-grid input {
  min-height: auto;
}

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

.settings-section-header h4 {
  margin: 0 0 4px;
  font-size: 15px;
}

.settings-section-header p {
  color: var(--muted);
  font-size: 12px;
}

.wjx-sources-editor {
  display: grid;
  gap: 10px;
}

.wjx-source-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfc;
}

.wjx-source-card.disabled {
  opacity: 0.72;
}

.wjx-source-header,
.wjx-source-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.wjx-source-header {
  margin-bottom: 10px;
}

.wjx-source-title {
  font-weight: 700;
}

.wjx-source-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(180px, 1fr) minmax(260px, 1.8fr);
  gap: 10px;
}

.wjx-source-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.wjx-source-actions {
  margin-top: 10px;
}

.wjx-source-toggle {
  display: inline-grid;
  grid-template-columns: 16px auto;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.wjx-source-toggle input {
  min-height: auto;
}

.wjx-source-message {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.settings-check-grid {
  grid-template-columns: minmax(260px, 1fr);
}

.connection-result {
  min-height: 38px;
  margin: 0 0 14px;
  padding: 9px 11px;
  border-left: 3px solid var(--line);
  background: #f9fbfb;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.connection-result.success {
  border-left-color: var(--green);
  color: var(--green);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--ink);
  color: #fff;
  padding: 11px 14px;
  border-radius: 7px;
  opacity: 0;
  transform: translateY(12px);
  transition: 160ms ease;
  pointer-events: none;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  background: var(--panel);
  border: 1px dashed #b9c6cf;
  border-radius: 8px;
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

.login-page,
.register-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.register-page {
  font-size: 17px;
  line-height: 1.6;
}

.login-shell,
.register-shell {
  width: min(760px, 100%);
}

.login-panel,
.register-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-shell {
  width: min(420px, 100%);
}

.login-form,
.register-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.register-form {
  grid-template-columns: 1fr;
}

.login-form label,
.register-form label {
  color: var(--muted);
  font-size: 14px;
  display: grid;
  gap: 6px;
}

.register-form label,
.register-form input,
.register-form select,
.register-form textarea,
.register-form button {
  font-size: 17px;
}

.register-form .wide {
  grid-column: span 1;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

fieldset.question-card {
  display: grid;
  gap: 10px;
  margin: 0;
}

fieldset.question-card legend {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.5;
  padding: 0 0 8px;
}

.question-card label,
.option-row label,
.matrix-options label {
  color: var(--ink);
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  line-height: 1.5;
}

.register-page .brand-block h1 {
  font-size: 22px;
}

.register-page .brand-block p {
  font-size: 15px;
}

.question-card label input[type="text"],
.question-card label input:not([type]),
.question-card label textarea {
  grid-column: 2;
}

.scale-item,
.matrix-question {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

.scale-item:first-child,
.matrix-question:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.scale-item p,
.matrix-question p {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 8px;
}

.option-row,
.matrix-options {
  display: grid;
  gap: 8px;
}

.consent-line {
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  color: var(--ink) !important;
}

.consent-line input {
  min-height: auto;
}

.register-form button {
  grid-column: span 1;
}

.register-message {
  grid-column: span 1;
}

.login-error,
.register-message {
  min-height: 20px;
  font-size: 13px;
}

.login-error,
.register-message.error {
  color: var(--red);
}

.register-message.success {
  color: var(--green);
}

.register-success-page {
  background: #fff;
  place-items: center;
}

.register-success-page .register-shell {
  width: min(520px, calc(100% - 32px));
}

.submit-success {
  min-height: 70vh;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  color: var(--ink);
}

.submit-success h1 {
  font-size: 28px;
  margin-bottom: 12px;
}

.submit-success p {
  color: var(--muted);
  font-size: 18px;
}

.application-summary {
  border: 1px solid var(--line);
  background: #fbfcfc;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

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

.summary-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-tab {
    text-align: center;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .form-grid,
  .check-grid,
  .summary-grid,
  .choice-grid,
  .compact-choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .booking-calendar-toolbar {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 12px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    padding: 10px 12px;
    gap: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 18px rgba(27, 39, 51, 0.06);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-block h1 {
    font-size: 16px;
  }

  .privacy-note {
    display: none;
  }

  .nav-tabs {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-tab {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 9px 12px;
  }

  .topbar,
  .section-header,
  .toolbar,
  .task-card {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }

  .task-actions {
    justify-content: flex-start;
  }

  .stats-grid,
  .form-grid,
  .check-grid,
  .summary-grid,
  .resource-summary,
  .choice-grid,
  .compact-choices {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body[data-view]:not([data-view="dashboard"]) .stats-grid {
    display: none;
  }

  .metric {
    min-height: 76px;
    padding: 12px;
  }

  .metric strong {
    font-size: 24px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions .user-badge {
    grid-column: 1 / -1;
  }

  .topbar-actions > * {
    width: 100%;
  }

  .wjx-status-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .detail-grid,
  .booking-form-grid,
  .scale-summary-grid,
  .wjx-source-form {
    grid-template-columns: 1fr;
  }

  .settings-section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .booking-calendar-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .calendar-nav {
    display: flex;
  }

  .booking-month-inline {
    order: -1;
    width: 100%;
    text-align: left;
    padding: 0 0 4px;
  }

  .booking-help {
    text-align: left;
  }

  .booking-calendar-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .booking-calendar {
    min-width: 700px;
    display: grid;
    grid-template-columns: repeat(7, minmax(100px, 1fr));
  }

  .booking-weekday {
    display: block;
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 5px;
  }

  .booking-day {
    min-height: 150px;
    display: block;
    padding: 5px;
  }

  .booking-day-number {
    margin: 0 0 5px;
    display: block;
    padding: 0;
    font-size: 12px;
  }

  .booking-day-slots {
    gap: 4px;
  }

  .calendar-slot {
    min-height: 34px;
    grid-template-columns: 1fr;
    gap: 1px;
    padding: 4px 5px;
  }

  .calendar-slot > button {
    font-size: 10px;
  }

  .calendar-slot small {
    display: none;
  }

  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 12px;
  }

  tbody td {
    border-bottom: 1px solid #edf1f3;
    padding: 10px 0;
  }

  tbody td:last-child {
    border-bottom: 0;
  }

  tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 5px;
  }

  .psg-copy-table-wrap {
    overflow-x: auto;
    background: var(--panel);
    border: 1px solid var(--line);
  }

  .psg-copy-table {
    display: table;
    width: 100%;
    min-width: 900px;
  }

  .psg-copy-table thead {
    display: table-header-group;
  }

  .psg-copy-table tbody {
    display: table-row-group;
  }

  .psg-copy-table tr {
    display: table-row;
    width: auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .psg-copy-table th,
  .psg-copy-table td {
    display: table-cell;
    width: auto;
    padding: 10px 12px;
    white-space: nowrap;
  }

  .psg-copy-table td[data-label]::before {
    display: none;
    content: none;
  }

  .template-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid .wide,
  .register-form .wide,
  .register-form button,
  .register-message {
    grid-column: span 1;
  }
}

.site-footer {
  align-items: center;
  color: #6b7280;
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 8px 16px;
  justify-content: center;
  line-height: 1.6;
  padding: 18px 12px;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  color: #176b57;
  text-decoration: underline;
}

.dashboard-footer {
  margin-top: 24px;
  padding-bottom: 4px;
}

.form-help {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}
