:root {
  color-scheme: light;
  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;
  --surface: #ffffff;
  --canvas: #f8fafc;
  --blue-50: #f0f9ff;
  --blue-200: #bae6fd;
  --blue-700: #0369a1;
  --blue-800: #075985;
  --green-50: #ecfdf5;
  --green-700: #047857;
  --red-50: #fef2f2;
  --red-200: #fecaca;
  --red-700: #b91c1c;
  --shadow-card: 0 12px 32px rgba(15, 23, 42, .07);
  --shadow-dialog: 0 28px 80px rgba(15, 23, 42, .28);
  --radius-xl: 24px;
  --z-header: 40;
  --z-dialog: 70;
  --z-toast: 90;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--canvas);
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink-900);
  background: var(--canvas);
  line-height: 1.5;
}

body.dialog-open { overflow: hidden; }

button,
input,
select { font: inherit; }

button,
a,
select { touch-action: manipulation; }

button { cursor: pointer; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(2, 132, 199, .42);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink-900);
  border-radius: 8px;
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.app-header {
  position: sticky;
  z-index: var(--z-header);
  top: 0;
  color: #fff;
  background: rgba(15, 23, 42, .96);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(14px);
}

.header-inner {
  width: min(100%, 1440px);
  min-height: 76px;
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block,
.header-actions,
.header-navigation,
.header-nav-link,
.live-badge,
.field-label,
.history-helper,
.loading-heading,
.refresh-button,
.action-card,
.dialog-head,
.dialog-actions,
.record-action,
.toast { display: flex; align-items: center; }

.brand-block { gap: 12px; min-width: 0; }
.header-actions { justify-content: flex-end; gap: 10px; }
.header-navigation { gap: 8px; }

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #38bdf8;
  background: rgba(14, 165, 233, .12);
  border: 1px solid rgba(125, 211, 252, .24);
  border-radius: 12px;
}

.brand-mark svg { width: 27px; height: 27px; }

.eyebrow,
.section-kicker {
  margin: 0 0 1px;
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.brand-block .eyebrow { color: #7dd3fc; }
.brand-block h1 { margin: 0; font-size: clamp(18px, 2.5vw, 22px); line-height: 1.2; letter-spacing: -.02em; }

.header-nav-link {
  min-height: 44px;
  padding: 8px 12px;
  justify-content: center;
  gap: 6px;
  color: #e0f2fe;
  background: rgba(3, 105, 161, .3);
  border: 1px solid rgba(125, 211, 252, .34);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  transition: background-color 180ms ease, border-color 180ms ease;
}

.header-nav-link svg { width: 19px; height: 19px; flex: 0 0 auto; }
.header-nav-link:hover { color: #fff; background: rgba(3, 105, 161, .5); border-color: rgba(125, 211, 252, .56); }
.header-nav-link:active { background: rgba(7, 89, 133, .7); }

.live-badge {
  min-height: 36px;
  padding: 7px 12px;
  gap: 8px;
  color: #dbeafe;
  background: rgba(30, 41, 59, .88);
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--ink-400);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, .12);
}

.live-badge[data-ready="true"] .status-dot {
  background: #38bdf8;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, .12);
}

.page-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 36px);
}

.action-panel,
.history-section {
  padding: clamp(18px, 3vw, 28px);
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
}

.history-section { margin-top: 28px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 { margin: 0; font-size: clamp(20px, 3vw, 26px); line-height: 1.25; letter-spacing: -.02em; }

.scope-badge,
.record-count {
  padding: 6px 10px;
  color: var(--ink-700);
  background: var(--ink-100);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

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

.action-card {
  min-width: 0;
  min-height: 112px;
  padding: 20px;
  gap: 14px;
  color: var(--ink-800);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.action-card:hover {
  background: #fbfdff;
  border-color: var(--blue-200);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .08);
}

.action-card:active { background: var(--blue-50); }
.action-card-primary { border-color: #7dd3fc; background: var(--blue-50); }

.action-icon {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--blue-700);
  background: #e0f2fe;
  border-radius: 14px;
}

.action-icon svg { width: 28px; height: 28px; }
.action-copy { min-width: 0; flex: 1; display: block; }
.action-copy strong { display: block; font-size: 19px; font-weight: 900; }
.action-copy small { display: block; margin-top: 4px; color: var(--ink-600); font-size: 14px; line-height: 1.45; }
.action-arrow { width: 22px; height: 22px; flex: 0 0 auto; color: var(--ink-400); }

.history-toolbar {
  margin-top: 20px;
  display: grid;
  grid-template-columns: minmax(240px, 520px) auto;
  align-items: end;
  gap: 12px;
}

.field-control { display: block; }
.field-label { margin-bottom: 8px; gap: 7px; color: var(--ink-700); font-size: 14px; font-weight: 700; }
.field-label svg,
.history-helper svg { width: 19px; height: 19px; flex: 0 0 auto; color: var(--blue-700); }

.select-wrap { position: relative; display: block; }
.select-wrap select {
  width: 100%;
  min-height: 50px;
  padding: 10px 44px 10px 14px;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  appearance: none;
}

.select-wrap select:not(:disabled) { cursor: pointer; }
.select-wrap select:disabled { color: var(--ink-500); background: var(--ink-100); cursor: wait; }
.select-wrap > svg { position: absolute; top: 50%; right: 14px; width: 20px; height: 20px; color: var(--ink-500); pointer-events: none; transform: translateY(-50%); }

.refresh-button,
.empty-action {
  min-height: 44px;
  padding: 8px 13px;
  justify-content: center;
  gap: 7px;
  color: var(--blue-800);
  background: #fff;
  border: 1px solid var(--blue-200);
  border-radius: 10px;
  font-weight: 800;
}

.refresh-button svg { width: 19px; height: 19px; }
.refresh-button:hover,
.empty-action:hover { background: var(--blue-50); }
.refresh-button:disabled { color: var(--ink-500); background: var(--ink-100); border-color: var(--ink-200); cursor: wait; }

.history-helper { margin: 14px 0 18px; gap: 8px; color: var(--ink-600); font-size: 14px; }

.loading-state,
.empty-state {
  padding: clamp(24px, 5vw, 44px);
  color: var(--ink-600);
  background: var(--canvas);
  border: 1px solid var(--ink-200);
  border-radius: 18px;
}

.loading-heading { justify-content: center; gap: 12px; text-align: left; }
.loading-heading strong,
.loading-heading span { display: block; }
.loading-heading strong { color: var(--ink-800); }
.loading-heading span { margin-top: 2px; font-size: 14px; }

.loading-spinner,
.button-spinner {
  display: inline-block;
  border: 3px solid var(--blue-200);
  border-top-color: var(--blue-700);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}

.loading-spinner { width: 28px; height: 28px; flex: 0 0 auto; }
.button-spinner { width: 18px; height: 18px; margin-right: 7px; vertical-align: -3px; }

.skeleton-list { margin-top: 24px; display: grid; gap: 10px; }
.skeleton-list div {
  height: 52px;
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
  background-size: 220% 100%;
  border-radius: 10px;
  animation: skeleton-sweep 1.3s linear infinite;
}

.empty-state { text-align: center; }
.empty-illustration { width: 64px; height: 64px; margin: 0 auto 12px; color: var(--ink-300); }
.empty-state h3 { margin: 0; color: var(--ink-800); font-size: 20px; }
.empty-state p { max-width: 560px; margin: 7px auto 0; }
.empty-action { margin-top: 16px; }

.attendance-table-wrap {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: 16px;
}

.attendance-table-wrap table { width: 100%; border-collapse: collapse; table-layout: auto; }
.attendance-table-wrap th { padding: 12px 14px; color: var(--ink-600); background: var(--ink-100); border-bottom: 1px solid var(--ink-200); font-size: 12px; font-weight: 800; text-align: left; white-space: nowrap; }
.attendance-table-wrap td { padding: 13px 14px; color: var(--ink-800); border-bottom: 1px solid var(--ink-200); font-size: 14px; vertical-align: middle; }
.attendance-table-wrap tbody tr:last-child td { border-bottom: 0; }
.attendance-table-wrap tbody tr:hover { background: #f8fafc; }
.attendance-table-wrap .number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.attendance-table-wrap td.number-cell { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 900; }

.record-action {
  min-height: 44px;
  padding: 8px 12px;
  justify-content: center;
  gap: 6px;
  color: var(--blue-800);
  background: var(--blue-50);
  border: 1px solid var(--blue-200);
  border-radius: 10px;
  font-weight: 800;
}

.record-action:hover { background: #e0f2fe; }
.record-action svg { width: 18px; height: 18px; }

.attendance-card-list { display: grid; grid-template-columns: 1fr; gap: 14px; }
.attendance-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
}

.attendance-card-head { padding: 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--ink-200); }
.attendance-card-head h3 { margin: 0; font-size: 18px; font-weight: 900; }
.group-badge { padding: 5px 9px; color: var(--blue-800); background: var(--blue-50); border: 1px solid var(--blue-200); border-radius: 999px; font-size: 13px; font-weight: 800; }
.attendance-metrics { margin: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.attendance-metrics > div { padding: 12px; background: var(--ink-100); border: 1px solid var(--ink-200); border-radius: 12px; }
.attendance-metrics dt { color: var(--ink-500); font-size: 12px; font-weight: 700; }
.attendance-metrics dd { margin: 4px 0 0; color: var(--ink-900); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.attendance-card .record-action { width: calc(100% - 32px); margin: 0 16px 16px; }

.dialog-layer {
  position: fixed;
  z-index: var(--z-dialog);
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.dialog-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: rgba(15, 23, 42, .58);
  border: 0;
  backdrop-filter: blur(4px);
}

.attendance-dialog {
  position: relative;
  width: min(100%, 720px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  padding: clamp(20px, 4vw, 28px);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 24px;
  box-shadow: var(--shadow-dialog);
  animation: dialog-in 220ms ease-out;
}

.dialog-head { justify-content: space-between; gap: 16px; }
.dialog-title-block h2 { margin: 0; font-size: clamp(22px, 4vw, 28px); }
.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--ink-600);
  background: var(--ink-100);
  border: 1px solid var(--ink-200);
  border-radius: 12px;
}
.icon-button svg { width: 22px; height: 22px; }
.icon-button:hover { color: var(--ink-900); background: var(--ink-200); }

.form-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-field { min-width: 0; display: block; }
.form-field > span:first-child { display: block; margin-bottom: 7px; color: var(--ink-700); font-size: 14px; font-weight: 800; }
.form-field input,
.form-field select {
  width: 100%;
  min-height: 50px;
  padding: 10px 13px;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
}

.form-field input:disabled,
.form-field select:disabled { color: var(--ink-500); background: var(--ink-100); cursor: wait; }
.form-field input[aria-invalid="true"],
.form-field select[aria-invalid="true"] { border-color: var(--red-700); box-shadow: 0 0 0 3px rgba(185, 28, 28, .1); }
.form-field small { display: block; margin-top: 6px; color: var(--ink-500); font-size: 12px; line-height: 1.45; }

.input-suffix-wrap { position: relative; display: block; }
.input-suffix-wrap input { padding-right: 58px; }
.input-suffix-wrap > span { position: absolute; top: 50%; right: 13px; color: var(--ink-500); font-size: 13px; font-weight: 700; transform: translateY(-50%); pointer-events: none; }

.field-error { min-height: 20px; display: block; margin-top: 4px; color: var(--red-700); font-size: 13px; font-weight: 700; }
.submit-status { margin: 18px 0 0; padding: 12px 14px; color: var(--blue-800); background: var(--blue-50); border: 1px solid var(--blue-200); border-radius: 12px; font-size: 14px; font-weight: 700; }
.submit-status[data-type="error"] { color: var(--red-700); background: var(--red-50); border-color: var(--red-200); }

.dialog-actions { margin-top: 22px; justify-content: flex-end; gap: 10px; }
.secondary-button,
.primary-button {
  min-width: 120px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 900;
}
.secondary-button { color: var(--ink-700); background: var(--surface); border: 1px solid var(--ink-300); }
.secondary-button:hover { background: var(--ink-100); }
.primary-button { color: #fff; background: var(--blue-700); border: 1px solid var(--blue-700); }
.primary-button:hover { background: var(--blue-800); border-color: var(--blue-800); }
.primary-button:disabled,
.secondary-button:disabled,
.icon-button:disabled { opacity: .58; cursor: wait; }

.toast {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 620px);
  min-height: 50px;
  padding: 12px 15px;
  gap: 9px;
  color: #fff;
  background: var(--green-700);
  border-radius: 13px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .24);
  font-weight: 800;
  transform: translateX(-50%);
}
.toast[data-type="error"] { background: var(--red-700); }
.toast svg { width: 22px; height: 22px; flex: 0 0 auto; }

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes skeleton-sweep { to { background-position: -120% 0; } }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 640px) and (max-width: 899px) {
  .attendance-card-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .attendance-card-list { display: none !important; }
  .attendance-table-wrap:not([hidden]) { display: block; }
}

@media (max-width: 899px) {
  .attendance-table-wrap { display: none !important; }
  .attendance-card-list:not([hidden]) { display: grid; }
}

@media (max-width: 760px) {
  .action-grid,
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .header-inner {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand badge" "nav nav";
    gap: 8px 12px;
  }
  .brand-block { grid-area: brand; }
  .header-actions { display: contents; }
  .header-navigation {
    grid-area: nav;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .header-nav-link { min-width: 0; padding: 8px 6px; }
  .brand-mark { width: 40px; height: 40px; }
  .live-badge { grid-area: badge; padding: 6px 9px; font-size: 11px; }
  .status-dot { display: none; }
  .page-shell { padding: 16px; }
  .action-panel,
  .history-section { padding: 17px; border-radius: 18px; }
  .section-heading { align-items: flex-start; }
  .history-toolbar { grid-template-columns: 1fr auto; }
  .dialog-layer { align-items: end; padding: 0; }
  .attendance-dialog { width: 100%; max-height: calc(100dvh - 12px); border-radius: 24px 24px 0 0; animation-name: sheet-in; }
}

@media (max-width: 500px) {
  .history-toolbar { grid-template-columns: 1fr; }
  .refresh-button { width: 100%; }
  .action-card { min-height: 104px; padding: 16px; }
  .action-icon { width: 46px; height: 46px; }
  .action-copy strong { font-size: 18px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1.25fr; }
  .secondary-button,
  .primary-button { min-width: 0; width: 100%; }
}

@media (max-width: 430px) {
  .eyebrow { font-size: 10px; letter-spacing: .09em; }
  .header-nav-link { padding-inline: 3px; font-size: 12px; gap: 4px; white-space: nowrap; }
  .header-nav-link svg { width: 17px; height: 17px; }
  .live-badge { white-space: normal; line-height: 1.15; text-align: center; }
  .scope-badge,
  .record-count { font-size: 12px; }
  .action-card { gap: 11px; }
  .action-copy small { font-size: 13px; }
  .action-arrow { display: none; }
  .attendance-metrics { margin: 14px; }
  .attendance-card .record-action { width: calc(100% - 28px); margin: 0 14px 14px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .dialog-layer { align-items: stretch; padding: 8px; }
  .attendance-dialog { max-height: calc(100dvh - 16px); border-radius: 18px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: translateY(0); }
}

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