/* ═══════════════════════════════════════════════════════════════
   Global Styles — Mobile-first, Chinese UI
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────── */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

@media (min-width: 769px) {
  .container { max-width: 720px; }
  .container.wide { max-width: 1100px; }
}

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.app-header a {
  color: #fff;
  text-decoration: none;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--gray-800);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }

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

.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 17px; width: 100%; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  background: #fff;
  color: var(--gray-800);
  transition: border-color .2s;
  -webkit-appearance: none;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-input.error { border-color: var(--danger); }

select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Photo upload ───────────────────────────────────────── */
.photo-upload {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.photo-box {
  flex: 1;
  min-width: 100px;
  aspect-ratio: 4/3;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
  background: var(--gray-50);
  position: relative;
  overflow: hidden;
}
.photo-box:hover, .photo-box.active {
  border-color: var(--primary);
  background: #eff6ff;
}
.photo-box.has-image { border-style: solid; border-color: var(--success); }

.photo-box img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-box .placeholder {
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
  z-index: 1;
}
.photo-box .placeholder .icon { font-size: 28px; display: block; margin-bottom: 4px; }

/* ── Photo action sheet ─────────────────────────────────── */
.photo-action-sheet {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  z-index: 2000;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  animation: slideUp .25s ease;
}
.photo-action-sheet.show { display: block; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1999;
}
.overlay.show { display: block; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.sheet-btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  text-align: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 10px;
  margin-bottom: 8px;
}
.sheet-btn:hover { background: var(--gray-100); }
.sheet-btn.cancel { color: var(--gray-500); margin-top: 8px; }

/* ── Gender radio group ─────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 12px;
}
.radio-group label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  transition: all .2s;
}
.radio-group input { display: none; }
.radio-group input:checked + span {
  color: var(--primary);
  font-weight: 600;
}
.radio-group label:has(input:checked) {
  border-color: var(--primary);
  background: #eff6ff;
}
.radio-group span { pointer-events: none; }

/* ── Conditional section ────────────────────────────────── */
.conditional-fields {
  display: none;
  padding: 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  margin-top: 12px;
  animation: fadeIn .3s ease;
}
.conditional-fields.show { display: block; }

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

/* ── Toast / messages ───────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  z-index: 3000;
  animation: toastIn .3s ease;
  pointer-events: none;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--primary); }

@keyframes toastIn {
  from { opacity: 0; top: -20px; }
  to   { opacity: 1; top: 20px; }
}

/* ── Table ──────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}
.data-table th, .data-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
.data-table th {
  background: var(--gray-100);
  font-weight: 600;
  position: sticky;
  top: 0;
}
.data-table tr:hover { background: var(--gray-50); }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

/* ── QR card list ───────────────────────────────────────── */
.qr-list {
  display: grid;
  gap: 12px;
}
.qr-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.qr-card img {
  width: 60px;
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
}
.qr-card .info { flex: 1; min-width: 0; }
.qr-card .info .name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qr-card .info .meta {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}
.qr-card .actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal .qr-large { text-align: center; margin-bottom: 16px; }
.modal .qr-large img { max-width: 100%; border-radius: 8px; }
.modal .qr-url {
  font-size: 12px;
  color: var(--gray-500);
  word-break: break-all;
  background: var(--gray-100);
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}
.modal .btn-row { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Split photo row ────────────────────────────────────── */
.photo-row {
  display: flex;
  gap: 10px;
}
.photo-row .photo-box { aspect-ratio: 3/2; }

/* ── Responsive: bigger screens ─────────────────────────── */
@media (min-width: 769px) {
  .qr-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Login page ─────────────────────────────────────────── */
.login-card {
  max-width: 360px;
  margin: 80px auto 0;
}
.login-card .app-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--primary);
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}
.empty-state .icon { font-size: 48px; display: block; margin-bottom: 12px; }

/* ── Page wrapper for form page ─────────────────────────── */
.page-form {
  padding-bottom: 100px; /* space for submit button */
}
.submit-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid var(--gray-200);
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,.05);
}
