:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eef0f4;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --border: #e2e4e9;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-alt: #23262e;
    --text: #eef0f4;
    --text-muted: #9aa1ac;
    --border: #2c2f38;
    --primary: #818cf8;
    --primary-hover: #a5b0f8;
    --primary-contrast: #14161b;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --success: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 96px;
}

.app--wide {
  max-width: 1100px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  margin: 0 -16px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

/* ---------- Login screen ---------- */

.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: var(--primary);
  color: var(--primary-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}

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

/* ---------- Form elements ---------- */

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

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

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

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

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

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

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

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

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.btn-icon {
  padding: 8px;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
}

.btn-icon:hover:not(:disabled) {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

/* ---------- Cards & sections ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 24px 0 10px;
}

.section-title:first-child {
  margin-top: 0;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Capture / picker ---------- */

.capture-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.capture-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 22px 12px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

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

.capture-btn svg {
  width: 26px;
  height: 26px;
}

/* ---------- File list (review screen) ---------- */

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

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-alt);
  flex-shrink: 0;
}

.thumb.video-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.file-row .field {
  flex: 1;
  gap: 2px;
}

.file-row input[type="text"] {
  padding: 8px 10px;
  font-size: 14px;
}

.file-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.file-row .remove-btn {
  flex-shrink: 0;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-downloaded {
  background: color-mix(in srgb, var(--success) 16%, transparent);
  color: var(--success);
}

.badge-pending {
  background: color-mix(in srgb, var(--text-muted) 16%, transparent);
  color: var(--text-muted);
}

.badge-photo {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
}

.badge-video {
  background: color-mix(in srgb, #ec4899 14%, transparent);
  color: #ec4899;
}

/* ---------- Host: filter chips ---------- */

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 18px;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

/* ---------- Host: file grid ---------- */

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.file-card .preview {
  aspect-ratio: 1;
  width: 100%;
  object-fit: cover;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.file-card .body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-card .name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card .meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

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

.file-card .actions .btn {
  flex: 1;
  padding: 8px;
  font-size: 12px;
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ---------- Toast ---------- */

.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 100;
}

.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease;
}

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

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

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 340px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-size: 16px;
  margin: 0 0 8px;
}

.modal p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.modal .modal-actions {
  display: flex;
  gap: 10px;
}

.modal .modal-actions .btn {
  flex: 1;
}

/* ---------- Sticky send bar ---------- */

.send-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  z-index: 50;
}

.send-bar-inner {
  width: 100%;
  max-width: 720px;
}

/* ---------- Progress bar ---------- */

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* ---------- Utility ---------- */

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

.hidden {
  display: none !important;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
}

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

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}
