/* ═══════════════════════════════════════════════════════════════════════════
   PhotoVault — design system
   Token-driven (shadcn/ui-style HSL custom properties) so light/dark is a
   single attribute flip on <html>. No framework, no build step.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens: light ───────────────────────────────────────────────────────── */
:root,
[data-theme='light'] {
  --background: 0 0% 100%;
  --foreground: 222 47% 11%;

  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;

  --muted: 210 40% 96%;
  --muted-foreground: 215 16% 47%;

  --border: 214 32% 91%;
  --input: 214 32% 91%;
  --ring: 222 47% 11%;

  --primary: 222 47% 11%;
  --primary-foreground: 210 40% 98%;

  --secondary: 210 40% 96%;
  --secondary-foreground: 222 47% 11%;

  --accent: 210 40% 96%;
  --accent-foreground: 222 47% 11%;

  --destructive: 0 72% 51%;
  --destructive-foreground: 210 40% 98%;

  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;

  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 100%;

  --info: 199 89% 48%;
  --info-foreground: 0 0% 100%;

  --radius: 0.75rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* ── Tokens: dark ────────────────────────────────────────────────────────── */
[data-theme='dark'] {
  --background: 222 47% 7%;
  --foreground: 210 40% 98%;

  --card: 222 47% 10%;
  --card-foreground: 210 40% 98%;

  --muted: 217 33% 15%;
  --muted-foreground: 215 20% 65%;

  --border: 217 33% 20%;
  --input: 217 33% 20%;
  --ring: 213 27% 70%;

  --primary: 210 40% 98%;
  --primary-foreground: 222 47% 11%;

  --secondary: 217 33% 15%;
  --secondary-foreground: 210 40% 98%;

  --accent: 217 33% 18%;
  --accent-foreground: 210 40% 98%;

  --destructive: 0 63% 50%;
  --destructive-foreground: 210 40% 98%;

  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;

  --warning: 38 92% 50%;
  --warning-foreground: 222 47% 7%;

  --info: 199 89% 48%;
  --info-foreground: 0 0% 100%;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  /* Respect notches and home indicators */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Visible focus for keyboard users, never for touch */
:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: calc(var(--radius) - 4px);
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-root { min-height: 100dvh; display: flex; flex-direction: column; }

.boot-splash {
  flex: 1; display: grid; place-content: center; gap: 1rem;
  text-align: center; color: hsl(var(--muted-foreground));
}
.boot-mark {
  width: 64px; height: 64px; margin: 0 auto;
  display: grid; place-content: center;
  border-radius: 16px; font-weight: 700; font-size: 1.5rem;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
}

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 1rem; }
.container-narrow { width: 100%; max-width: 520px; margin: 0 auto; padding: 1rem; }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.75rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.hidden { display: none !important; }

.grid-cards {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: hsl(var(--background) / 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid hsl(var(--border));
  padding-top: calc(0.75rem + env(safe-area-inset-top));
}
.topbar-brand { display: flex; align-items: center; gap: 0.625rem; font-weight: 650; }
.topbar-logo {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  display: grid; place-content: center; font-size: 0.75rem; font-weight: 700;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
}
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ── Bottom navigation (thumb zone) ──────────────────────────────────────── */
.bottom-nav {
  position: sticky; bottom: 0; z-index: 40; margin-top: auto;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: hsl(var(--background) / 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid hsl(var(--border));
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
  padding: 0.625rem 0.25rem; min-height: 56px;
  font-size: 0.6875rem; font-weight: 500; text-decoration: none;
  color: hsl(var(--muted-foreground));
  transition: color 0.15s ease;
}
.bottom-nav a[aria-current='page'] { color: hsl(var(--foreground)); }
.bottom-nav a:hover { color: hsl(var(--foreground)); }
.bottom-nav .nav-icon { font-size: 1.25rem; line-height: 1; }

/* ── Cards & surfaces ────────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1rem; }
.card-header {
  padding: 1rem; border-bottom: 1px solid hsl(var(--border));
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.card-title { font-size: 0.9375rem; font-weight: 600; }
.card-desc { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); margin: 0.125rem 0 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1rem; min-height: 44px;      /* 44px = iOS touch target floor */
  border: 1px solid transparent; border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 0.9375rem; font-weight: 550; cursor: pointer;
  transition: opacity 0.15s ease, transform 0.06s ease, background-color 0.15s ease;
  user-select: none; -webkit-user-select: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { opacity: 0.9; }
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}
.btn-outline { background: transparent; color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: hsl(var(--accent)); opacity: 1; }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-success { background: hsl(var(--success)); color: hsl(var(--success-foreground)); }
.btn-sm { min-height: 34px; padding: 0.3rem 0.7rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }

/**
 * Giant capture actions. Deliberately oversized — technicians use these
 * one-handed, outdoors, often wearing gloves.
 */
.btn-capture {
  width: 100%; min-height: 104px; padding: 1.25rem;
  flex-direction: column; gap: 0.375rem;
  font-size: 1.0625rem; font-weight: 600; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.btn-capture .cap-icon { font-size: 2rem; line-height: 1; }
.btn-capture .cap-hint { font-size: 0.75rem; font-weight: 400; opacity: 0.85; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.375rem; }
.label { font-size: 0.8125rem; font-weight: 550; color: hsl(var(--foreground)); }
.hint { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: 0.625rem 0.75rem;
  background: hsl(var(--background)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 2px);
  font-size: 1rem; /* 16px stops iOS Safari auto-zoom on focus */
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
}
.input[aria-invalid='true'] { border-color: hsl(var(--destructive)); }
.error-text { font-size: 0.75rem; color: hsl(var(--destructive)); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-neutral { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); border-color: hsl(var(--border)); }
.badge-success { background: hsl(var(--success) / 0.15); color: hsl(var(--success)); border-color: hsl(var(--success) / 0.3); }
.badge-warning { background: hsl(var(--warning) / 0.15); color: hsl(var(--warning)); border-color: hsl(var(--warning) / 0.3); }
.badge-danger  { background: hsl(var(--destructive) / 0.15); color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.3); }
.badge-info    { background: hsl(var(--info) / 0.15); color: hsl(var(--info)); border-color: hsl(var(--info) / 0.3); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.stat-label { font-size: 0.75rem; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-sub { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }

/* ── Progress ────────────────────────────────────────────────────────────── */
.progress { height: 8px; background: hsl(var(--muted)); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: hsl(var(--primary)); transition: width 0.3s ease; border-radius: 999px; }
.progress-bar.is-warning { background: hsl(var(--warning)); }
.progress-bar.is-danger { background: hsl(var(--destructive)); }

/* ── Charts (inline SVG, no dependency) ──────────────────────────────────── */
.chart-shell { width: 100%; overflow: hidden; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-bar { fill: hsl(var(--primary)); transition: opacity 0.15s ease; }
.chart-bar:hover { opacity: 0.75; }
.chart-axis { stroke: hsl(var(--border)); stroke-width: 1; }
.chart-grid { stroke: hsl(var(--border)); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.6; }
.chart-label { fill: hsl(var(--muted-foreground)); font-size: 9px; }
.chart-empty { fill: hsl(var(--muted-foreground)); font-size: 11px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
table.data th, table.data td {
  padding: 0.625rem 0.75rem; text-align: left;
  border-bottom: 1px solid hsl(var(--border)); white-space: nowrap;
}
table.data th {
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground)); font-weight: 600;
  position: sticky; top: 0; background: hsl(var(--card)); z-index: 1;
}
table.data tbody tr:hover { background: hsl(var(--accent) / 0.5); }
table.data td.wrap-cell { white-space: normal; max-width: 260px; }

/* ── Photo preview / thumbnails ──────────────────────────────────────────── */
.thumb {
  width: 56px; height: 56px; border-radius: 10px; object-fit: cover;
  border: 1px solid hsl(var(--border)); background: hsl(var(--muted)); flex: none;
}
.preview-frame {
  position: relative; border-radius: var(--radius); overflow: hidden;
  border: 1px solid hsl(var(--border)); background: hsl(var(--muted));
}
.preview-frame img { display: block; width: 100%; max-height: 46dvh; object-fit: contain; background: #000; }

/* ── Queue list ──────────────────────────────────────────────────────────── */
.queue-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
}
.queue-item:last-child { border-bottom: none; }
.queue-meta { min-width: 0; flex: 1; }
.queue-name { font-size: 0.8125rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-sub { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 100; display: flex; flex-direction: column; gap: 0.5rem;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.7rem 0.85rem; border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card)); color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border)); box-shadow: var(--shadow-lg);
  font-size: 0.8125rem; animation: toast-in 0.2s ease;
}
.toast.is-success { border-left: 3px solid hsl(var(--success)); }
.toast.is-error   { border-left: 3px solid hsl(var(--destructive)); }
.toast.is-warn    { border-left: 3px solid hsl(var(--warning)); }
.toast.is-info    { border-left: 3px solid hsl(var(--info)); }

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

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-root {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 1rem;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal {
  width: min(96vw, 460px); max-height: 88dvh; overflow-y: auto;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: modal-in 0.16s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-head {
  padding: 1rem; border-bottom: 1px solid hsl(var(--border));
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.modal-body { padding: 1rem; }
.modal-foot {
  padding: 0.875rem 1rem; border-top: 1px solid hsl(var(--border));
  display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap;
}

/* ── Offline / status banner ─────────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem; font-size: 0.8125rem; font-weight: 500;
  border-bottom: 1px solid hsl(var(--border));
}
.banner-offline { background: hsl(var(--warning) / 0.15); color: hsl(var(--warning)); }
.banner-info    { background: hsl(var(--info) / 0.12); color: hsl(var(--info)); }
.banner-danger  { background: hsl(var(--destructive) / 0.12); color: hsl(var(--destructive)); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block; }
.dot-online  { background: hsl(var(--success)); box-shadow: 0 0 0 3px hsl(var(--success) / 0.2); }
.dot-offline { background: hsl(var(--warning)); box-shadow: 0 0 0 3px hsl(var(--warning) / 0.2); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty { padding: 2.5rem 1rem; text-align: center; color: hsl(var(--muted-foreground)); }
.empty-icon { font-size: 2.25rem; margin-bottom: 0.5rem; opacity: 0.7; }

/* ── Skeleton loading ────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, hsl(var(--muted)) 25%, hsl(var(--accent)) 50%, hsl(var(--muted)) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
  border-radius: calc(var(--radius) - 4px);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton-line { height: 12px; margin-bottom: 0.5rem; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.6875rem; }
.text-muted { color: hsl(var(--muted-foreground)); }
.text-danger { color: hsl(var(--destructive)); }
.text-success { color: hsl(var(--success)); }
.mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.mt-1 { margin-top: 0.25rem; } .mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; } .mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; } .mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; } .gap-4 { gap: 1rem; }

/* ── Responsive: tablet/desktop dashboard ────────────────────────────────── */
@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .container { padding: 1.5rem; }
  .desktop-only { display: block; }
}
@media (max-width: 899px) {
  .desktop-only { display: none; }
}

/* ── Print (audit exports) ───────────────────────────────────────────────── */
@media print {
  .topbar, .bottom-nav, .toast-host, .btn { display: none !important; }
  body { background: #fff; color: #000; }
}