:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4fa;
  --surface-warm: #fffaf0;
  --text: #172033;
  --muted: #536273;
  --line: #d4dde8;
  --primary: #155f9c;
  --primary-hover: #0f4f84;
  --primary-soft: #eaf3fb;
  --success: #0b7551;
  --success-soft: #eaf7f1;
  --danger: #a7342b;
  --danger-soft: #fff0ee;
  --warning: #8a5a00;
  --warning-soft: #fff7df;
  --focus: #f2a900;
  --shadow: 0 14px 36px rgba(23, 32, 51, 0.08);
  --radius: 18px;
  --radius-small: 12px;
  --control: 58px;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 18px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}
body::selection { background: #cfe8fb; color: var(--text); }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 4px solid rgba(242, 169, 0, 0.34);
  outline-offset: 3px;
}

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 22px 0 52px; }
.narrow-shell { width: min(820px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 56px; }

.topbar {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.brand h1 { margin: 0; font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.02em; }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 0.98rem; }
.nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 7px 24px rgba(23, 32, 51, 0.05);
  padding: 24px;
  margin-bottom: 18px;
}
.panel.flat { box-shadow: none; }
.panel.soft { background: var(--surface-soft); border-color: #cbdceb; }
.panel.warning { background: var(--surface-warm); border-color: #ead8a6; }
.card h2, .panel h2 { margin: 0 0 12px; font-size: 1.4rem; line-height: 1.3; }
.card h3, .panel h3 { margin: 0 0 8px; font-size: 1.12rem; }

.hero { padding: clamp(30px, 5vw, 58px); }
.hero h2 { max-width: 900px; margin: 0 0 14px; font-size: clamp(2rem, 4.5vw, 3.7rem); line-height: 1.08; letter-spacing: -0.035em; }
.hero p { max-width: 760px; margin: 0 0 24px; color: var(--muted); font-size: 1.14rem; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.span12 { grid-column: span 12; }
.span8 { grid-column: span 8; }
.span6 { grid-column: span 6; }
.span4 { grid-column: span 4; }

.btn {
  display: inline-flex;
  min-height: var(--control);
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #c8d3df;
  border-radius: 14px;
  padding: 12px 20px;
  background: #f8fafc;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.btn:hover { background: #edf2f7; border-color: #b7c4d2; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ok { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.large { min-height: 66px; padding: 15px 28px; font-size: 1.14rem; border-radius: 16px; }
.btn.small { min-height: 44px; padding: 8px 13px; border-radius: 11px; font-size: 0.92rem; }
.btn.full { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.stacked { flex-direction: column; align-items: stretch; }

.field { display: grid; gap: 8px; min-width: 0; }
.field label { font-weight: 850; color: #263347; }
.field .hint, .help { color: var(--muted); font-size: 0.9rem; }
input, select, textarea {
  width: 100%;
  min-height: var(--control);
  border: 2px solid #cbd5e1;
  border-radius: 13px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
}
input:hover, select:hover, textarea:hover { border-color: #aebdcd; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21, 95, 156, 0.12); }
input::placeholder, textarea::placeholder { color: #7b8795; opacity: 1; }
textarea { min-height: 120px; resize: vertical; }
input[type="checkbox"] { width: 24px; height: 24px; min-height: 24px; accent-color: var(--primary); }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-weight: 700; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.form-grid .span12 { grid-column: span 12; }
.form-grid .span8 { grid-column: span 8; }
.form-grid .span6 { grid-column: span 6; }
.form-grid .span4 { grid-column: span 4; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 22px; }

.notice {
  padding: 16px 18px;
  border: 1px solid #bdd8ee;
  border-radius: 14px;
  background: #edf6fd;
  color: #174967;
  margin-bottom: 16px;
  font-weight: 650;
}
.notice.ok { background: var(--success-soft); border-color: #b7dfcd; color: #075d40; }
.notice.error { background: var(--danger-soft); border-color: #efc2bd; color: #8e2b24; }
.notice.warn { background: var(--warning-soft); border-color: #ead28e; color: #704900; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e9eef4;
  color: #344054;
  font-weight: 800;
  font-size: 0.86rem;
}
.badge.active { background: var(--success-soft); color: var(--success); }
.badge.pending { background: var(--warning-soft); color: var(--warning); }
.badge.suspended, .badge.rejected { background: var(--danger-soft); color: var(--danger); }

.muted { color: var(--muted); }
.stat { font-size: 2.35rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 7px; color: var(--muted); font-weight: 700; }

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

.primary-task {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  padding: clamp(24px, 4vw, 38px);
  background: var(--surface);
  border: 2px solid #bfd5e8;
  border-radius: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.primary-task h2 { margin: 0 0 8px; font-size: clamp(1.55rem, 3vw, 2.2rem); line-height: 1.2; }
.primary-task p { margin: 0; max-width: 62ch; color: var(--muted); }

.step {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.step-number {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.step-body h2 { margin: 4px 0 6px; }
.step-body > p { margin: 0 0 16px; color: var(--muted); }

.advanced {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 18px;
  overflow: clip;
}
.advanced > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 14px 18px;
  list-style: none;
  cursor: pointer;
  font-weight: 850;
  color: #2d3b4f;
  background: #f8fafc;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::after { content: "展開"; font-size: 0.82rem; color: var(--primary); }
.advanced[open] > summary::after { content: "收起"; }
.advanced-content { padding: 20px; border-top: 1px solid var(--line); }

.quick-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quick-link {
  display: block;
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}
.quick-link:hover { border-color: #9cbdd7; background: #f8fbfe; }
.quick-link strong { display: block; margin-bottom: 4px; font-size: 1.05rem; }
.quick-link span { color: var(--muted); font-size: 0.9rem; }

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 38px);
}
.login-card h1 { margin: 0 0 8px; font-size: 2rem; line-height: 1.2; }
.login-card > .muted { margin-top: 0; }
.login-card form { display: grid; gap: 18px; margin-top: 22px; }
.login-footer { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 9px; }
.password-row { position: relative; }
.password-row input { padding-right: 92px; }
.password-toggle { position: absolute; right: 8px; top: 8px; min-height: 42px; padding: 6px 12px; border: 0; border-radius: 10px; background: #edf2f7; color: #344054; font-weight: 800; cursor: pointer; }

.task-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.75fr); gap: 20px; align-items: start; }
.task-main, .task-side { min-width: 0; }
.task-side { position: sticky; top: 18px; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.student-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  max-height: 56vh;
  overflow: auto;
  padding: 3px 5px 3px 3px;
  scrollbar-color: #9fb1c4 #edf2f7;
}
.student {
  min-height: 96px;
  display: grid;
  gap: 6px;
  align-content: center;
  border: 2px solid #ccd6e2;
  background: #fff;
  color: var(--text);
  border-radius: 15px;
  padding: 15px;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}
.student:hover { border-color: #94b5cf; background: #fbfdff; }
.student.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.student strong { display: block; font-size: 1.14rem; line-height: 1.25; }
.student small { color: var(--muted); font-size: 0.9rem; }
.selection-state { color: var(--primary); font-weight: 850; font-size: 0.84rem; }
.empty-state { padding: 28px 18px; border: 1px dashed #b9c7d6; border-radius: 14px; color: var(--muted); text-align: center; background: #fbfcfe; }

.send-dock {
  position: sticky;
  bottom: 14px;
  z-index: 10;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #b8cfe3;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 14px 36px rgba(23, 32, 51, 0.14);
}
.send-dock .btn { width: 100%; }
.selected-summary { margin-bottom: 10px; color: #344054; font-weight: 800; }

.queue { display: grid; gap: 12px; }
.queue-item {
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 15px;
  display: grid;
  gap: 12px;
  background: #fff;
}
.queue-item strong { font-size: 1.2rem; line-height: 1.2; }
.queue-meta { color: var(--muted); font-size: 0.9rem; }
.queue-message { margin-top: 5px; font-weight: 800; color: #71322d; }
.queue-item .btn { width: 100%; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; scrollbar-color: #9fb1c4 #edf2f7; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; background: #fff; }
.data-table th, .data-table td { padding: 14px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th { background: #f3f6fa; color: #344054; font-size: 0.91rem; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fbfdff; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.88em; background: #eef2f6; border-radius: 6px; padding: 2px 5px; }

.display-body { overflow: hidden; background: #edf3f8; }
.display-shell { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; gap: 16px; padding: 20px; }
.display-top { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.display-title { font-weight: 900; font-size: clamp(1.25rem, 2.3vw, 1.8rem); }
.status-pill { min-height: 42px; display: inline-flex; align-items: center; padding: 7px 14px; border-radius: 999px; background: var(--success-soft); color: var(--success); font-weight: 850; }
.stage { display: grid; place-items: center; text-align: center; }
.board { width: min(1280px, 96vw); background: #fff; border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow); padding: clamp(28px, 5vw, 64px); }
.waiting { font-size: clamp(2rem, 5vw, 4rem); color: #506174; font-weight: 850; }
.queue-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 18px; text-align: left; }
.queue-card { border: 2px solid #bdcad8; border-radius: 22px; padding: 22px; background: #fff; }
.qname { font-size: clamp(2.1rem, 5vw, 4rem); font-weight: 950; line-height: 1.08; letter-spacing: -0.025em; }
.qmsg { margin-top: 12px; color: var(--danger); font-size: clamp(1.25rem, 2.6vw, 2.1rem); font-weight: 900; }
.qdetail { margin-top: 10px; color: var(--muted); font-size: 1.05rem; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 940px) {
  .span12, .span8, .span6, .span4 { grid-column: span 12; }
  .form-grid .span12, .form-grid .span8, .form-grid .span6, .form-grid .span4 { grid-column: span 12; }
  .task-layout { grid-template-columns: 1fr; }
  .task-side { position: static; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid .field:first-child { grid-column: span 2; }
  .quick-links { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body { font-size: 17px; }
  .shell, .narrow-shell { width: min(100% - 20px, 1180px); padding-top: 14px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .nav { width: 100%; }
  .nav .btn { flex: 1 1 auto; }
  .primary-task { grid-template-columns: 1fr; }
  .primary-task .btn { width: 100%; }
  .filter-grid { grid-template-columns: 1fr; }
  .filter-grid .field:first-child { grid-column: span 1; }
  .student-list { grid-template-columns: 1fr 1fr; max-height: none; }
  .display-shell { padding: 12px; }
  .display-top { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 460px) {
  :root { --control: 56px; }
  .student-list { grid-template-columns: 1fr; }
  .card, .panel { padding: 19px; }
  .login-wrap { padding: 12px; }
  .login-card { padding: 24px 20px; border-radius: 20px; }
  .btn.large { min-height: 62px; }
  .actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* v0.5 school-wide active notice overview */
.school-display-page { min-height: 100dvh; background: #edf3f8; }
.school-display-shell { width: min(1500px, calc(100% - 32px)); margin: 0 auto; padding: 22px 0 46px; }
.school-display-topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.school-display-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  padding: 22px 26px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 7px 24px rgba(23, 32, 51, 0.05);
}
.summary-label { display: block; color: var(--muted); font-weight: 750; }
.summary-count { display: block; margin-top: 2px; font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.05; font-weight: 950; font-variant-numeric: tabular-nums; }
.summary-status { display: grid; justify-items: end; gap: 6px; }
.status-pill.status-error { background: var(--danger-soft); color: var(--danger); }
.school-notice-groups { display: grid; gap: 20px; }
.school-room-group { background: #fff; border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 7px 24px rgba(23, 32, 51, 0.05); padding: 22px; }
.school-room-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.school-room-heading h2 { margin: 0; font-size: clamp(1.35rem, 2.4vw, 1.8rem); line-height: 1.25; }
.school-notice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.school-notice-card { min-width: 0; border: 2px solid #c6d2df; border-radius: 18px; background: #fff; padding: 18px; }
.school-notice-name { font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.12; font-weight: 950; letter-spacing: -0.02em; }
.school-notice-meta { margin-top: 6px; color: var(--muted); font-weight: 750; }
.school-notice-message { margin-top: 12px; color: var(--danger); font-size: 1.12rem; font-weight: 900; }
.school-notice-time { margin-top: 9px; color: var(--muted); font-size: 0.88rem; }
.school-display-empty { min-height: 280px; display: grid; place-items: center; align-content: center; gap: 8px; padding: 36px; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 22px; color: var(--muted); }
.school-display-empty strong { color: var(--text); font-size: clamp(1.5rem, 3vw, 2.2rem); }

@media (max-width: 720px) {
  .school-display-shell { width: min(100% - 20px, 1500px); padding-top: 14px; }
  .school-display-topbar { align-items: flex-start; flex-direction: column; }
  .school-display-topbar .nav { width: 100%; }
  .school-display-summary { align-items: flex-start; flex-direction: column; padding: 20px; }
  .summary-status { justify-items: start; }
  .school-room-group { padding: 18px; }
  .school-notice-grid { grid-template-columns: 1fr; }
}
