/* ============================================================
 *  Base Reset & Tokens
 * ============================================================ */

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

:root {
  /* Palette — warm, culturally grounded */
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-surface-offset: #f3f0ec;
  --color-border: #e0dcd6;
  --color-divider: #eae6e1;
  --color-text: #2c2820;
  --color-text-muted: #7a7670;
  --color-text-faint: #b5b1ab;
  --color-primary: #8b4c2a;
  --color-primary-hover: #713d20;
  --color-primary-active: #5c3018;
  --color-primary-light: #f5ebe3;
  --color-warning: #a13544;
  --color-warning-hover: #8a2c3a;
  --color-warning-light: #fdf0f0;
  --color-success: #437a22;
  --color-success-light: #e8f5e9;
  --color-error: #c0392b;
  --color-danger: #d32f2f;
  --color-danger-hover: #b71c1c;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Type */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1vw, 1.875rem);

  /* Transition */
  --transition: 200ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-display: 'Noto Serif SC', 'Songti SC', serif;
  --font-body: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(44, 40, 32, 0.06);
  --shadow-md: 0 4px 12px rgba(44, 40, 32, 0.08);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.65;
  min-height: 100dvh;
}

/* ============================================================
 *  Page Container (SPA routing)
 * ============================================================ */

.page {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.page.active {
  display: flex;
}

/* ============================================================
 *  Header
 * ============================================================ */

.page-header {
  padding: var(--space-10) 0 var(--space-6);
  text-align: center;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
  letter-spacing: 0.04em;
}

.header-subtitle {
  margin-top: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.header-ornament {
  width: 40px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 2px;
  margin: 0 auto var(--space-4);
}

.header-ornament.cancel {
  background: var(--color-warning);
}

.header-ornament.admin {
  background: linear-gradient(90deg, var(--color-primary), var(--color-success));
  width: 50px;
}

.success-icon {
  margin: 0 auto var(--space-4);
  width: 56px;
  height: 56px;
}

/* ============================================================
 *  Content
 * ============================================================ */

.page-content {
  flex: 1;
  padding-bottom: var(--space-8);
}

/* ============================================================
 *  Form
 * ============================================================ */

.form-group {
  margin-bottom: var(--space-5);
}

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.required {
  color: var(--color-error);
}

.optional {
  color: var(--color-text-faint);
  font-weight: 400;
}

input[type="text"],
input[type="tel"],
input[type="number"],
textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(139, 76, 42, 0.1);
}

input.has-error,
textarea.has-error {
  border-color: var(--color-error);
}

input.has-error:focus,
textarea.has-error:focus {
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.error-msg {
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-1);
  min-height: 1.2em;
}

::placeholder {
  color: var(--color-text-faint);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

/* ============================================================
 *  Disclaimer
 * ============================================================ */

.disclaimer-box {
  margin-bottom: var(--space-6);
  background: var(--color-surface-offset);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.disclaimer-text {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.7;
  margin-bottom: var(--space-4);
}

.disclaimer-text strong {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.disclaimer-text p {
  margin-bottom: var(--space-1);
  max-width: none;
}

/* Custom checkbox */
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.5;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-divider);
  -webkit-tap-highlight-color: transparent;
}

.checkbox-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-custom {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  transition: all var(--transition);
  position: relative;
  margin-top: 1px;
}

.checkbox-label input:checked + .checkbox-custom {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

/* ============================================================
 *  Buttons
 * ============================================================ */

.btn {
  display: block;
  width: 100%;
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
  font-weight: 600;
  font-family: var(--font-body);
  text-align: center;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 52px;
  position: relative;
}

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

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

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-active);
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: var(--color-border);
  color: var(--color-text-faint);
  cursor: not-allowed;
}

.btn-warning {
  background: var(--color-warning);
  color: #fff;
}

.btn-warning:hover {
  background: var(--color-warning-hover);
}

.btn-warning:active {
  transform: scale(0.98);
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn-outline:hover {
  background: var(--color-primary-light);
}

.btn-outline:active {
  transform: scale(0.98);
}

.btn.is-loading {
  pointer-events: none;
  opacity: 0.7;
}

/* ============================================================
 *  Small Buttons
 * ============================================================ */

.btn-small {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font-body);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

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

.btn-small-primary:hover {
  background: var(--color-primary-hover);
}

.btn-small-outline {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.btn-small-outline:hover {
  background: var(--color-surface-offset);
}

.btn-small-warning {
  background: var(--color-warning);
  color: #fff;
}

.btn-small-warning:hover {
  background: var(--color-warning-hover);
}

.btn-small-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.btn-small-danger:hover {
  background: #fdf0f0;
}

/* ============================================================
 *  Link Button (Cancel / Back)
 * ============================================================ */

.cancel-link-wrap {
  text-align: center;
  margin-top: var(--space-6);
  padding-bottom: var(--space-4);
}

.link-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: var(--space-2) var(--space-4);
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font-body);
  transition: color var(--transition);
}

.link-btn:hover {
  color: var(--color-primary);
}

/* ============================================================
 *  Event Cards (Admin List)
 * ============================================================ */

.event-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.event-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  transition: box-shadow var(--transition);
}

.event-card:hover {
  box-shadow: var(--shadow-md);
}

.event-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.event-card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  flex: 1;
}

.event-card-status {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-top: 3px;
}

.event-status-open {
  background: var(--color-success-light);
  color: var(--color-success);
}

.event-status-closed {
  background: var(--color-surface-offset);
  color: var(--color-text-faint);
}

.event-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.event-card-meta svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.event-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
}

.event-card-count {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}

.event-card-actions {
  display: flex;
  gap: var(--space-2);
}

/* ============================================================
 *  Empty State
 * ============================================================ */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--color-text-faint);
}

.empty-state svg {
  margin: 0 auto var(--space-4);
  opacity: 0.5;
}

.empty-state p {
  font-size: var(--text-base);
  margin-bottom: var(--space-1);
}

.empty-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ============================================================
 *  Event Detail — Info Grid
 * ============================================================ */

.detail-info {
  margin-bottom: var(--space-5);
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.info-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-weight: 400;
}

.info-value {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
  word-break: break-word;
}

.detail-action-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.detail-status-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 10px;
}

.badge-open {
  background: var(--color-success-light);
  color: var(--color-success);
}

.badge-closed {
  background: var(--color-surface-offset);
  color: var(--color-text-faint);
}

/* ============================================================
 *  Link Display Box (Registration URL)
 * ============================================================ */

.detail-link-box {
  margin-bottom: var(--space-5);
}

.link-display {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.link-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
  font-weight: 500;
}

.link-row {
  display: flex;
  gap: var(--space-2);
}

.link-input {
  flex: 1;
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.link-qr-section {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
  text-align: center;
}

.link-qr-wrapper {
  display: inline-block;
  background: #fff;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-divider);
  margin-bottom: var(--space-2);
}

.link-qr-wrapper img {
  display: block;
}

.link-qr-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-bottom: var(--space-3);
}

/* ============================================================
 *  QR Code Upload Area (Event Form)
 * ============================================================ */

.qr-upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-4);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--color-surface);
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}

.qr-upload-area:hover,
.qr-upload-area:active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.upload-prompt {
  color: var(--color-text-muted);
}

.upload-prompt svg {
  margin: 0 auto var(--space-2);
  color: var(--color-primary);
}

.upload-prompt p {
  font-size: var(--text-sm);
}

.file-input-hidden {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
}

.qr-preview-inline {
  text-align: center;
}

.qr-preview-inline img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-divider);
  margin-bottom: var(--space-3);
}

/* ============================================================
 *  User Registration — Info Card
 * ============================================================ */

.event-info-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
}

.info-card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-2) 0;
  gap: var(--space-4);
}

.info-card-row + .info-card-row {
  border-top: 1px solid var(--color-divider);
}

.info-card-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-shrink: 0;
  min-width: 48px;
  padding-top: 1px;
}

.info-card-value {
  font-size: var(--text-sm);
  color: var(--color-text);
  text-align: right;
  word-break: break-word;
  flex: 1;
}

/* ============================================================
 *  Notice Boxes
 * ============================================================ */

.notice-box {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: center;
}

.notice-warning {
  background: var(--color-warning-light);
  color: var(--color-warning);
  border: 1px solid rgba(161, 53, 68, 0.15);
}

/* ============================================================
 *  QR Code Section (Success Page)
 * ============================================================ */

.qrcode-section {
  text-align: center;
  margin-bottom: var(--space-8);
}

.qr-hint {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
  margin-bottom: var(--space-4);
}

.qr-wrapper {
  display: inline-block;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.qr-wrapper img {
  width: 200px;
  height: 200px;
  display: block;
  border-radius: var(--radius-md);
}

.qr-note {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.qr-no-image {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  text-align: center;
}

/* ============================================================
 *  Section Header (Registrations)
 * ============================================================ */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.section-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.section-actions {
  display: flex;
  gap: var(--space-2);
}

.registration-stats {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

/* ============================================================
 *  Registration Cards
 * ============================================================ */

.registration-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.loading-text {
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  padding: var(--space-6) 0;
}

.reg-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.reg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
}

.reg-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.reg-status {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.status-active {
  background: var(--color-success-light);
  color: var(--color-success);
}

.status-cancelled {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.reg-card-body {
  padding: var(--space-3) var(--space-4);
}

.reg-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-1) 0;
  font-size: var(--text-xs);
  color: var(--color-text);
  gap: var(--space-3);
}

.reg-label {
  color: var(--color-text-muted);
  flex-shrink: 0;
  min-width: 60px;
}

.reg-info-row > span:last-child {
  text-align: right;
  word-break: break-all;
}

/* ============================================================
 *  Detail Actions Bottom
 * ============================================================ */

.detail-actions-bottom {
  margin-top: var(--space-6);
}

/* ============================================================
 *  Toast Notification
 * ============================================================ */

.toast {
  position: fixed;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--color-text);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  z-index: 1000;
  transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
  max-width: calc(100vw - 2 * var(--space-5));
  text-align: center;
  box-shadow: var(--shadow-md);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--color-error);
}

.toast.success {
  background: var(--color-success);
}

/* ============================================================
 *  Footer
 * ============================================================ */

.page-footer {
  padding: var(--space-4) 0 var(--space-6);
  text-align: center;
}

.page-footer a {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
}

.page-footer a:hover {
  color: var(--color-text-muted);
}

/* ============================================================
 *  Animations
 * ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page.active .page-header,
.page.active .page-content {
  animation: fadeIn 350ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
