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

:root {
  --color-primary: #1d6fa4;
  --color-primary-dark: #155680;
  --color-success: #2a7d4f;
  --color-danger: #c0392b;
  --color-danger-dark: #922b21;
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #d1d9e0;
  --color-text: #1a1a2e;
  --color-text-muted: #6b7280;
  --color-ts-pending: #e5e7eb;
  --color-ts-pending-text: #374151;
  --color-ts-captured: #d1fae5;
  --color-ts-captured-text: #065f46;
  --color-ts-captured-border: #6ee7b7;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
}

body {
  margin: 0;
  min-height: 100dvh;
}

/* ─── Layout ─────────────────────────────── */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 0 80px;
}

.page-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

/* ─── Header ─────────────────────────────── */

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.form-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  color: var(--color-primary-dark);
}

.group-badge {
  font-size: 13px;
  font-weight: 600;
  background: var(--color-primary);
  color: #fff;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ─── Form sections ───────────────────────── */

.form {
  padding: 12px 16px;
}

.form-section {
  margin-top: 24px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: 0 0 12px;
}

/* ─── Field label ─────────────────────────── */

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
}

/* ─── Text input ─────────────────────────── */

.text-input-wrap {
  margin-bottom: 16px;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.text-input:focus {
  border-color: var(--color-primary);
}

textarea.text-input {
  resize: vertical;
}

/* ─── Timestamp button ────────────────────── */

.timestamp-button-wrap {
  margin-bottom: 8px;
}

.timestamp-btn {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-ts-pending);
  color: var(--color-ts-pending-text);
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.timestamp-btn.captured {
  background: var(--color-ts-captured);
  color: var(--color-ts-captured-text);
  border-color: var(--color-ts-captured-border);
}

.timestamp-btn:active {
  opacity: 0.8;
}

.ts-label {
  flex: 1;
  font-weight: 500;
}

.ts-time {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ts-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 8px;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 13px;
}

.ts-group {
  background: #f0f4f8;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.ts-group-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary-dark);
  margin: 0 0 8px;
}

/* ─── Scale input ─────────────────────────── */

.scale-input {
  margin-bottom: 20px;
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.scale-buttons {
  display: flex;
  gap: 4px;
}

.scale-btn {
  flex: 1;
  min-height: 44px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

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

.scale-btn:active {
  opacity: 0.7;
}

/* ─── Radio group ─────────────────────────── */

.radio-group {
  margin-bottom: 20px;
}

.radio-group.inline {
  margin-bottom: 0;
  display: flex;
  gap: 6px;
}

.radio-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio-btn {
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.radio-btn.selected {
  background: #dbeafe;
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.radio-btn:active {
  opacity: 0.75;
}

/* ─── Submit button ───────────────────────── */

.btn-submit {
  width: 100%;
  min-height: 54px;
  margin-top: 24px;
  padding: 14px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-submit:hover { background: var(--color-primary-dark); }
.btn-submit:disabled { opacity: 0.6; cursor: default; }

/* ─── Generic buttons ─────────────────────── */

.btn-primary {
  min-height: 44px;
  padding: 10px 18px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover { background: #c0c8d0; }

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

.btn-danger:hover { background: var(--color-danger-dark); }
.btn-danger:disabled { opacity: 0.6; cursor: default; }

/* ─── Admin page ──────────────────────────── */

.admin-page {
  max-width: 1200px;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  padding: 0 16px;
  margin-top: 16px;
}

.tab-btn {
  min-height: 44px;
  padding: 8px 20px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: -2px;
}

.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content {
  padding: 16px;
}

/* ─── Add user form ───────────────────────── */

.add-user-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.add-user-form h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

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

.add-user-row .text-input {
  flex: 1;
  min-width: 160px;
}

/* ─── Admin table ─────────────────────────── */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  white-space: nowrap;
}

.admin-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f0f4f8;
  border-bottom: 2px solid var(--color-border);
  font-weight: 700;
  color: var(--color-text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-table tr:hover td {
  background: #f8fafc;
}

.action-cell {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.submissions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ─── QR Modal ────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  display: none;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.qr-image {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 8px;
}

.qr-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 12px;
}

/* ─── Login form ──────────────────────────── */

.login-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.login-form h2 {
  margin: 0;
  text-align: center;
}

/* ─── Misc ────────────────────────────────── */

.error-text {
  color: var(--color-danger);
  font-size: 13px;
  margin: 4px 0 0;
}

.empty-hint {
  color: var(--color-text-muted);
  font-size: 14px;
  padding: 16px;
  text-align: center;
}

.success h2 { color: var(--color-success); }
.error { color: var(--color-danger); }

.hidden { display: none !important; }
