:root {
  --primary: #4f6ef7;
  --primary-dark: #3b57d9;
  --primary-soft: #eef1ff;
  --success: #16a34a;
  --success-soft: #e8f7ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #d97706;
  --warning-soft: #fef3e2;
  --text: #1f2937;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --border: #e5e7eb;
  --bg: #f4f6fb;
  --card: #ffffff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.06), 0 4px 16px rgba(17, 24, 39, 0.04);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-height: 76px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* ---------- 布局 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-row,
.topbar-side {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.topbar-row,
.tabs {
  width: 100%;
  max-width: 560px;
  margin-right: auto;
  margin-left: auto;
}

.topbar-side {
  justify-content: flex-end;
  gap: 2px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar-user,
.topbar-class {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.topbar-class {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  margin-top: 10px;
  margin-bottom: -12px;
}

.tab {
  flex: 1;
  min-height: 40px;
  padding: 8px 4px 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--bar-height) + var(--safe-bottom) + 24px);
}

.page-intro {
  margin: 4px 4px 16px;
  color: var(--text-2);
  font-size: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 14px;
}

/* ---------- 表单 ---------- */

.field {
  display: block;
  margin-bottom: 18px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
}

.field-label .required {
  color: var(--danger);
  margin-left: 2px;
}

.input,
.textarea {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  background: #f9fafb;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.input {
  min-height: 48px;
}

.input:focus,
.textarea:focus {
  border-color: var(--primary);
  background: #fff;
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.field-hint {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-3);
}

.field-hint span:first-child {
  min-width: 0;
}

.field.invalid .input,
.field.invalid .textarea {
  border-color: var(--danger);
}

.field.invalid .choice span {
  border-color: #f5b5b5;
}

/* 单选按钮组（用原生 radio 实现） */
.choice-group {
  display: grid;
  gap: 10px;
}

.choice-group.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.choice-group.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.choice {
  position: relative;
  display: block;
}

.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 4px;
  font-size: 15px;
  text-align: center;
  background: #f9fafb;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  user-select: none;
}

.choice.pill span {
  min-height: 42px;
  border-radius: 999px;
}

.choice input:checked + span {
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-soft);
  border-color: var(--primary);
}

.choice input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  color: #fff;
  background: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  color: var(--primary);
  background: var(--primary-soft);
}

.btn-ghost {
  color: var(--text-2);
  background: transparent;
  border: 1.5px solid var(--border);
}

.btn-danger-text {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--danger);
  background: var(--danger-soft);
}

.btn-small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.link-btn {
  padding: 6px 4px;
  font-size: 15px;
  color: var(--primary);
  background: none;
  border: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 20px;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}

/* 底部固定操作栏 */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border);
}

.bottom-bar-inner {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.bottom-bar-inner .btn {
  flex: 1;
}

/* ---------- 徽标 ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  white-space: nowrap;
}

.badge-morning { color: #0e7490; background: #e0f5fa; }
.badge-evening { color: #6d28d9; background: #f1ebfe; }
.badge-full_day { color: var(--warning); background: var(--warning-soft); }
.badge-type { color: var(--text-2); background: #f1f2f4; }
.badge-cancelled { color: var(--text-3); background: #f1f2f4; }

/* ---------- 记录卡片 ---------- */

.record-list {
  display: grid;
  gap: 12px;
}

.record {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.record-title {
  font-size: 16px;
  font-weight: 600;
}

.record-title small {
  margin-left: 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-2);
}

.record-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.record-reason {
  margin: 0;
  font-size: 15px;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

.record-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-3);
}

.record.is-cancelled {
  opacity: 0.6;
}

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-3);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

/* ---------- 提交成功 ---------- */

.success {
  padding: 32px 16px 24px;
  text-align: center;
}

.success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin-bottom: 12px;
  font-size: 38px;
  color: #fff;
  background: var(--success);
  border-radius: 50%;
}

.success h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.success p {
  margin: 0;
  color: var(--text-2);
}

.summary {
  margin: 0;
  padding: 0;
  list-style: none;
}

.summary li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.summary li:last-child {
  border-bottom: none;
}

.summary li span:first-child {
  flex-shrink: 0;
  color: var(--text-2);
}

.summary li span:last-child {
  text-align: right;
  word-break: break-word;
}

.stack {
  display: grid;
  gap: 10px;
}

/* ---------- 管理端 ---------- */

.login-wrap {
  max-width: 420px;
  margin: 8vh auto 0;
}

.login-wrap h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-wrap p {
  margin: 0 0 20px;
  color: var(--text-2);
  font-size: 14px;
}

.date-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.date-picker {
  position: relative;
  flex: 1;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}

.date-picker strong {
  font-size: 16px;
}

.date-picker small {
  font-size: 12px;
  color: var(--text-2);
}

.date-picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.segments {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: 8px 4px;
  background: var(--card);
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: all 0.15s;
}

.segment .num {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.segment .label {
  font-size: 13px;
  color: var(--text-2);
}

.segment.active {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: var(--primary);
}

.segment.active .label {
  color: var(--primary);
}

.list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 4px 10px;
  font-size: 13px;
  color: var(--text-2);
}

.loading {
  padding: 40px 0;
  text-align: center;
  color: var(--text-3);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 100;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  font-size: 15px;
  text-align: center;
  color: #fff;
  background: rgba(31, 41, 55, 0.94);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-type="error"] {
  background: var(--danger);
}

.toast[data-type="success"] {
  background: var(--success);
}

/* ---------- 花名册 ---------- */

.card-title {
  margin: 0 0 4px;
  font-size: 18px;
}

.card-desc {
  margin: 0 0 14px;
  color: var(--text-2);
  font-size: 14px;
}

.roster-summary .card-desc {
  margin: 6px 0 0;
}

.roster-summary strong {
  font-size: 18px;
}

.roster-count {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
}

.search-wrap {
  margin-bottom: 12px;
}

.search-wrap .input {
  background: #fff;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 12px 12px 16px;
}

.roster-main {
  flex: 1;
  min-width: 0;
}

.roster-name {
  font-size: 16px;
  font-weight: 600;
  word-break: break-all;
}

.roster-no {
  font-size: 13px;
  color: var(--text-2);
  word-break: break-all;
}

.roster-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.inline-actions {
  display: flex;
  gap: 10px;
}

.inline-actions .btn {
  flex: 1;
}

.import-actions {
  flex-wrap: wrap;
}

.import-actions .btn {
  flex: 1 1 9em;
}

#importForm.is-dragover {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
}

.file-name {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-2);
  word-break: break-all;
}

.shot-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
}

.shot-thumbs img {
  height: 72px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.preview-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) auto;
  gap: 8px;
  padding: 0 2px;
  font-size: 13px;
  color: var(--text-2);
}

.preview-head span:last-child {
  width: 52px;
}

.preview-item {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.preview-item .input {
  min-height: 40px;
  padding: 8px 10px;
  background: #fff;
}

.preview-item.is-invalid {
  padding: 8px;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

.preview-error {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  color: var(--danger);
}

.mode-list {
  display: grid;
  gap: 8px;
}

.mode-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  background: #f9fafb;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}

.mode-option:has(input:checked) {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.mode-option input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
}

.mode-option span {
  font-size: 14px;
}

.warn-text {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--warning);
}

.skipped {
  margin: 4px 4px 12px;
  color: var(--text-2);
  font-size: 13px;
}

.skipped summary {
  cursor: pointer;
}

.skipped ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.skipped li {
  margin: 4px 0;
  word-break: break-all;
}

@media (min-width: 600px) {
  .container {
    padding-top: 24px;
  }
}
