:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #e9edf3;
  --ink: #0f2744;
  --ink-secondary: #475569;
  --ink-muted: #64748b;
  --border: #dce3ec;
  --accent: #b45309;
  --accent-bg: #fef3c7;
  --accent-border: #f59e0b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-bg: #fee2e2;
  --shadow-sm: 0 1px 3px rgba(15, 39, 68, 0.08);
  --shadow-md: 0 6px 18px rgba(15, 39, 68, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ====== Top Header ====== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, #0f2744 0%, #1b3b64 100%);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(15, 39, 68, 0.2);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
}

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

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

.app-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(254, 243, 199, 0.2);
  color: #fde68a;
  border: 1px solid rgba(253, 230, 138, 0.4);
}

.role-badge.admin {
  background: rgba(219, 234, 254, 0.2);
  color: #bfdbfe;
  border-color: rgba(191, 219, 254, 0.4);
}

.sync-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #e2e8f0;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

.sync-dot.syncing {
  background: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.25);
}

.sync-dot.error {
  background: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.25);
}

.btn-header {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.15s ease;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ====== Layout Container ====== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 14px 48px;
}

/* ====== Principal View Toolbar ====== */
.view-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--surface-muted);
  color: var(--ink);
}

.stat-chip.pending {
  background: var(--accent-bg);
  color: #92400e;
}

.stat-chip.done {
  background: var(--success-bg);
  color: var(--success);
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  background: var(--surface-muted);
  padding: 3px;
  border-radius: 10px;
  gap: 2px;
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.control-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.btn-subtle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
}

.btn-subtle:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.tip-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #78350f;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.86rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ====== Principal Guest Reading Cards ====== */
.guest-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guest-card {
  width: 100%;
  text-align: left;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background-color 0.2s ease, opacity 0.2s ease, border-color 0.2s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.guest-card:active {
  transform: scale(0.992);
}

.guest-card.is-new {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
}

.guest-card.is-announced {
  background: #edf0f5;
  border-color: #d6dde7;
  opacity: 0.5;
  box-shadow: none;
}

.card-seq {
  flex-shrink: 0;
  min-width: 46px;
  height: 46px;
  padding: 0 8px;
  border-radius: 12px;
  background: #0f2744;
  color: #ffffff;
  font-weight: 800;
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.guest-card.is-announced .card-seq {
  background: #64748b;
}

.card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.card-name {
  font-weight: 800;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.25;
}

.guest-card.is-announced .card-name {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(71, 85, 105, 0.55);
}

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

.card-title-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 700;
  background: var(--primary-soft);
  color: #1e3a8a;
  border: 1px solid #bfdbfe;
  max-width: 100%;
  word-break: break-word;
}

.guest-card.is-announced .card-title-badge {
  background: #e2e8f0;
  color: #475569;
  border-color: #cbd5e1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.badge-announced {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #cbd5e1;
  color: #334155;
}

.badge-new {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  background: #f59e0b;
  color: #ffffff;
}

/* Font Size Scales for Principal Mobile View */
.font-sm .card-name { font-size: 1.25rem; }
.font-sm .card-title-badge { font-size: 0.96rem; }
.font-sm .card-seq { min-width: 40px; height: 40px; font-size: 1.1rem; }

.font-md .card-name { font-size: 1.6rem; }
.font-md .card-title-badge { font-size: 1.12rem; }
.font-md .card-seq { min-width: 48px; height: 48px; font-size: 1.3rem; }

.font-lg .card-name { font-size: 2rem; }
.font-lg .card-title-badge { font-size: 1.3rem; }
.font-lg .card-seq { min-width: 56px; height: 56px; font-size: 1.55rem; }

/* ====== Admin Panel ====== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-secondary);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--ink);
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.chips-section {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chips-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-muted);
  margin-right: 4px;
}

.title-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-secondary);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.title-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.title-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--ink);
}

.btn-secondary:hover:not(:disabled) {
  background: #dce3ec;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger-outline {
  background: #ffffff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-sm {
  padding: 7px 11px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
}

.admin-row-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 260px;
}

.admin-seq {
  flex-shrink: 0;
  min-width: 38px;
  height: 38px;
  padding: 0 6px;
  border-radius: 10px;
  background: #0f2744;
  color: #ffffff;
  font-weight: 800;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.admin-person {
  min-width: 0;
}

.admin-person-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.admin-name {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--ink);
  word-break: break-word;
}

.admin-title-pill {
  display: inline-flex;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: #1e3a8a;
}

.admin-time {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.admin-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.sort-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--border);
}

/* ====== Empty State ====== */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--ink-muted);
}

.empty-state strong {
  display: block;
  font-size: 1.08rem;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

/* ====== Modal Dialogs ====== */
dialog.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(460px, calc(100vw - 28px));
  box-shadow: 0 20px 50px rgba(15, 39, 68, 0.28);
  background: var(--surface);
  color: var(--ink);
}

dialog.modal::backdrop {
  background: rgba(15, 39, 68, 0.52);
  backdrop-filter: blur(2px);
}

.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink-muted);
  padding: 4px 8px;
}

.modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-note {
  margin: 0;
  font-size: 0.86rem;
  color: var(--ink-secondary);
  background: var(--bg);
  padding: 9px 12px;
  border-radius: 8px;
}

.delete-target-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 14px;
}

.delete-target-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: #991b1b;
}

.delete-target-meta {
  margin-top: 4px;
  font-size: 0.88rem;
  color: #7f1d1d;
}

.modal-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ====== Toast Notification ====== */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  background: #0f2744;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.toast.error {
  background: #991b1b;
}

.toast.success {
  background: #166534;
}

/* ====== Responsive ====== */
@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .admin-row-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .sort-group {
    border-right: none;
    padding-right: 0;
    margin-right: auto;
  }

  .guest-card {
    padding: 13px 14px;
    gap: 12px;
  }
}
