:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --accent-ink: #04202e;
  --danger: #f87171;
  --success: #4ade80;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-dim: #64748b;
  --accent: #0284c7;
  --accent-dark: #0369a1;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  transition: background-color 0.2s ease, color 0.2s ease;
}

button,
input,
textarea {
  font-size: 16px;
}

/* Auth screen */

.auth-bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.auth-screen {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  margin-bottom: 12px;
}

.auth-title {
  margin: 0 0 4px;
  font-size: 1.7rem;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.auth-subtitle {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.auth-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tabs[hidden] {
  display: none;
}

.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.auth-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-form[hidden] {
  display: none;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.auth-hint {
  margin: -6px 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.1em;
}

.auth-submit {
  margin-top: 6px;
  width: 100%;
}

.auth-disclaimer {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: left;
}

/* App shell */

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.brand-name {
  font-family: "Syne", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

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

.badge {
  background: var(--surface-2);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.capture-section {
  text-align: center;
}

.capture-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.capture-btn {
  flex: 1;
  min-width: 150px;
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 1.02rem;
}

.hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 10px;
}

.processing-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
}

.processing-section[hidden] {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.review-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.review-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.review-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius);
  background: #000;
}

.review-form,
#editForm,
#sendForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-form label,
#editForm label,
#sendForm label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-family: inherit;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}

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

.batch-section h2 {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.batch-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
}

.batch-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  flex-shrink: 0;
}

.batch-info {
  flex: 1;
  min-width: 0;
}

.batch-info strong {
  display: block;
  font-size: 0.95rem;
}

.batch-info span {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.batch-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 40px;
}

.icon-btn.danger {
  color: var(--danger);
}

.empty-state {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px 0;
}

.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.app-footer .btn {
  flex: 1;
  padding: 14px;
}

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(420px, 90vw);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.send-status {
  font-size: 0.85rem;
  min-height: 1.2em;
}

.send-status.error {
  color: var(--danger);
}

.send-status.success {
  color: var(--success);
}

/* Admin panel */

.admin-dialog {
  width: min(640px, 95vw);
  max-height: 80vh;
}

.admin-dialog[open] {
  display: flex;
  flex-direction: column;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.admin-header h2 {
  margin: 0;
}

.admin-table-wrap {
  overflow: auto;
  margin-top: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.status-pill {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill.status-active {
  background: color-mix(in srgb, var(--success) 20%, transparent);
  color: var(--success);
}

.status-pill.status-pending {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
}

.status-pill.status-revoked {
  background: color-mix(in srgb, var(--danger) 20%, transparent);
  color: var(--danger);
}

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

/* Camera overlay */

.camera-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
}

.camera-overlay[hidden] {
  display: none;
}

.camera-video {
  flex: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
}

.camera-guide-hint {
  margin: 0;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.camera-guide {
  width: min(86vw, 640px);
  aspect-ratio: 1.75 / 1;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
}

.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px calc(28px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
}

.camera-icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
}

.shutter-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.shutter-btn:active {
  background: #d4d4d4;
}

/* Mobile */

@media (max-width: 480px) {
  .app-header {
    padding: 12px;
  }

  main {
    padding: 16px;
  }

  .capture-btn {
    min-width: 130px;
  }

  .auth-card {
    padding: 26px 20px;
  }
}
