/* ============================================================
   OBSTEC Scan — dark theme
   ============================================================ */

:root {
  --bg:           #090c10;
  --surface:      #101620;
  --surface-2:    #161e2c;
  --border:       #1f2c3e;
  --border-light: #283850;

  --text:         #dde3ee;
  --text-muted:   #6b7f9a;
  --text-dim:     #3d5068;

  --accent:       #2f80ed;
  --accent-dim:   #1a4d8f;
  --accent-glow:  rgba(47,128,237,.18);

  --success:      #22c55e;
  --success-bg:   rgba(34,197,94,.12);
  --error:        #ef4444;
  --error-bg:     rgba(239,68,68,.12);
  --warning:      #f59e0b;
  --warning-bg:   rgba(245,158,11,.12);
  --info:         #38bdf8;
  --info-bg:      rgba(56,189,248,.12);

  --radius:       6px;
  --radius-lg:    10px;
  --shadow:       0 1px 3px rgba(0,0,0,.5), 0 0 0 1px var(--border);
}

/* ── Reset ───────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 0.9375rem;
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--info); }

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: .02em;
}
.brand:hover { color: var(--text); opacity: .85; }

.brand-logo { width: 86px; height: 38px; object-fit: contain; flex: 0 0 auto; }
.brand-product { color: var(--text-muted); }

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-email {
  font-size: .8125rem;
  color: var(--text-muted);
}

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
}

.container {
  padding-top: 2rem;
}

/* ── Page header ─────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.page-sub {
  color: var(--text-muted);
  font-size: .875rem;
  margin-top: .2rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  font-size: .875rem;
  color: var(--text-muted);
}
.back-link:hover { color: var(--text); }

/* ── Section ─────────────────────────────────────────────── */

.section { margin-bottom: 2rem; }

.section-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.section-heading-row .section-title { margin-bottom: 0; }

.section-title {
  font-size: .875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* ── Card ────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.card.p-0 { padding: 0; overflow: hidden; }

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ── Table ───────────────────────────────────────────────── */

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

.table thead {
  border-bottom: 1px solid var(--border);
}

.table th {
  padding: .625rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr:hover { background: var(--surface-2); }

.td-title   { font-weight: 500; }
.td-date    { color: var(--text-muted); font-size: .8125rem; white-space: nowrap; }
.td-muted   { color: var(--text-muted); font-size: .8125rem; }
.td-action  { text-align: right; white-space: nowrap; }
.td-filename {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 500;
  word-break: break-all;
}

.file-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

/* ── File cards ─────────────────────────────────────────── */

.file-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: .875rem;
}

.file-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.file-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.file-card-name { display: flex; align-items: center; gap: .5rem; min-width: 0; font-weight: 600; }
.file-card-name span { overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
.file-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-top: .75rem; color: var(--text-muted); font-size: .8125rem; }
.file-card-analysis { margin-top: .875rem; padding: .65rem .75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.file-card-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; padding-top: 1rem; }

.reconstruction-hint { margin-bottom: .75rem; color: var(--text-muted); font-size: .875rem; }
.notice { padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .875rem; }
.notice-warning { color: var(--warning); background: var(--warning-bg); border-color: rgba(245,158,11,.3); }
.reconstruction-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem 1.25rem; margin-top: .75rem; }
.reconstruction-summary div { display: flex; min-width: 0; flex-direction: column; }
.reconstruction-summary span { color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.reconstruction-summary code { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.reconstruction-summary .summary-error { grid-column: 1 / -1; color: var(--error); }
.worker-status { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; }
.job-status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .625rem; margin-top: .75rem; }
.job-status-grid div { display: flex; align-items: center; justify-content: space-between; padding: .65rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr)); gap: .625rem; }
.photo-card { display: flex; align-items: center; gap: .65rem; min-width: 0; padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.photo-card-icon { display: grid; place-items: center; flex: 0 0 42px; height: 42px; border-radius: var(--radius); background: var(--surface-2); color: var(--accent); font-size: .65rem; font-weight: 700; }
.photo-card-body { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.photo-card-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; }
.photo-card-body span { color: var(--text-muted); font-size: .75rem; }

.danger-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-color: rgba(239,68,68,.3); }
.danger-card strong { color: var(--error); }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: #1a6cd4;
  border-color: #1a6cd4;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-light);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-light);
}

.btn-sm {
  padding: .3rem .7rem;
  font-size: .8125rem;
}

.btn-full { width: 100%; justify-content: center; }

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  border-color: rgba(239,68,68,.45);
}
.btn-danger:hover { background: var(--error); color: #fff; border-color: var(--error); }

.btn-ms {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-light);
  gap: .6rem;
}

/* ── Form elements ───────────────────────────────────────── */

.form-group  { margin-bottom: 1rem; }
.form-row    { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.form-label  { display: block; font-size: .8125rem; font-weight: 500; color: var(--text-muted); margin-bottom: .35rem; }
.form-hint   { font-size: .8125rem; color: var(--text-dim); }

.form-input {
  width: 100%;
  padding: .5rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9375rem;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  outline: none;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-dim); }

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 24 24' fill='none' stroke='%236b7f9a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2rem;
  cursor: pointer;
}

.inline-form { max-width: 480px; }

/* ── Badges ──────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .02em;
}

.badge-pending    { background: rgba(100,116,139,.2); color: #94a3b8; border: 1px solid rgba(100,116,139,.3); }
.badge-processing { background: var(--warning-bg);   color: var(--warning);                                  border: 1px solid rgba(245,158,11,.25); }
.badge-done       { background: var(--success-bg);   color: var(--success);                                  border: 1px solid rgba(34,197,94,.25); }
.badge-error      { background: var(--error-bg);     color: var(--error);                                    border: 1px solid rgba(239,68,68,.25); }
.badge-file-role  { background: var(--accent-glow);  color: var(--accent); border: 1px solid var(--accent-dim); text-transform: capitalize; }

/* ── Scan thumbnails ────────────────────────────────────── */

.thumbnail-heading, .scan-thumbnail-cell { width: 84px; }
.scan-thumbnail {
  display: block;
  width: 64px;
  height: 48px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.scan-thumbnail-placeholder { display: grid; place-items: center; color: var(--text-dim); }
.scan-thumbnail-placeholder svg { width: 24px; height: 24px; }
.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; }

.ext-badge {
  display: inline-block;
  padding: .1rem .45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .75rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: var(--accent);
  letter-spacing: .04em;
}

/* ── Flash messages ──────────────────────────────────────── */

.flash {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin: 1rem 0 0;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: rgba(34,197,94,.2); }
.flash-error   { background: var(--error-bg);   color: var(--error);   border-color: rgba(239,68,68,.2); }
.flash-info    { background: var(--info-bg);    color: var(--info);    border-color: rgba(56,189,248,.2); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(245,158,11,.2); }

.flash-icon { flex-shrink: 0; width: 16px; height: 16px; }
.flash-inline { margin: .75rem 0 1rem; }

/* ── Empty state ─────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1.5rem;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; color: var(--text-dim); }
.empty-state p   { font-size: .9375rem; }

.empty-state-sm { padding: 2rem 1rem; }
.empty-state-sm svg { width: 32px; height: 32px; }

/* ── Upload drop zone ────────────────────────────────────── */

.drop-zone {
  display: block;          /* override inline default when element is a <label> */
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;         /* whole zone is tappable */
}
.drop-zone svg       { width: 36px; height: 36px; color: var(--text-dim); margin-bottom: .75rem; }
.drop-zone.drag-over { border-color: var(--accent); background: var(--accent-glow); }

.drop-label {
  font-size: .9375rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
}

.drop-hint {
  font-size: .8125rem;
  color: var(--text-dim);
}

/* Hidden but label-accessible — display:none still works when the input is
   a child of (or linked via for= to) a <label>; the label tap is a real
   user gesture that iOS Safari will honour. */
.file-input-hidden { display: none; }

.selected-file {
  margin-top: .75rem;
  font-size: .875rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: var(--accent);
  background: var(--accent-glow);
  padding: .4rem .75rem;
  border-radius: var(--radius);
  display: inline-block;
}

.upload-option { display: inline-flex; align-items: center; gap: .5rem; margin-top: .75rem; color: var(--text-muted); font-size: .8125rem; cursor: pointer; }
.upload-option input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ── Login page ──────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(2rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(47,128,237,.12) 0%, transparent 70%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0,0,0,.4);
}

.login-logo {
  width: 210px;
  height: 118px;
  margin: 0 auto 1.25rem;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }

.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
  margin-bottom: .3rem;
}

.login-sub {
  font-size: .875rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.login-form  { text-align: left; margin-bottom: 1rem; }

.login-note {
  font-size: .8125rem;
  color: var(--text-dim);
  margin-top: 1rem;
}

.dev-badge {
  display: inline-block;
  margin-bottom: 1.25rem;
  padding: .15rem .6rem;
  background: var(--warning-bg);
  border: 1px solid rgba(245,158,11,.3);
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--warning);
}

/* ── 3-D Preview panel ───────────────────────────────────── */

.preview-wrap {
  position: relative;
  overflow: hidden;
  max-width: 100%;
}

.preview-canvas {
  display: block;
  width: 100%;
  height: 440px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  touch-action: none; /* let OrbitControls own touch events */
  max-width: 100%;
}

.preview-overlay {
  position: absolute;
  inset: 0 0 2.25rem; /* leave room for the hint bar */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.preview-overlay.hidden {
  display: none !important;
}

/* Loading state */
.preview-spinner {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--text-muted);
  font-size: .875rem;
  background: rgba(9,12,16,.75);
  padding: .65rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

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

.spinner-ring {
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  flex-shrink: 0;
}

/* Error state */
.preview-error {
  color: var(--error);
  font-size: .875rem;
  background: var(--error-bg);
  border: 1px solid rgba(239,68,68,.25);
  padding: .65rem 1.1rem;
  border-radius: var(--radius);
  max-width: 26rem;
  text-align: center;
}

/* Idle state (no file loaded yet) */
.preview-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  color: var(--text-dim);
  font-size: .875rem;
  text-align: center;
  padding: 1rem;
}
.preview-idle svg {
  width: 40px;
  height: 40px;
  color: var(--text-dim);
  opacity: .6;
}

.preview-hint {
  padding: .55rem 1rem;
  font-size: .75rem;
  color: var(--text-dim);
  text-align: center;
  border-top: 1px solid var(--border);
  letter-spacing: .01em;
}

.preview-name {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .8125rem;
  color: var(--accent);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* Active state on Preview button */
.preview-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ── Scan metadata display ───────────────────────────────── */

.meta-category {
  font-size: .75rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  padding: .1rem .45rem;
  border-radius: 999px;
}

.meta-source {
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: .1rem .45rem;
  border-radius: 999px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.scan-meta-line {
  margin-top: .2rem;
  display: flex;
  gap: .4rem;
  align-items: center;
}

.meta-card {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.meta-row {
  display: flex;
  gap: 1.5rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.meta-row:last-child { border-bottom: none; }

.meta-label {
  flex-shrink: 0;
  width: 100px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.meta-value {
  font-size: .9375rem;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}

.meta-notes {
  white-space: pre-wrap;
  word-break: break-word;
  display: block;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: .1rem .5rem;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  font-size: .75rem;
  color: var(--text-muted);
}

/* ── Admin stat cards ────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: .35rem;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: .8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
}

/* ── Role badges ─────────────────────────────────────────── */

.badge-admin { background: var(--accent-glow); color: var(--accent);     border: 1px solid var(--accent-dim); }
.badge-user  { background: var(--surface-2);   color: var(--text-muted); border: 1px solid var(--border); }

/* ── Inline role select ──────────────────────────────────── */

.role-select {
  width: auto;
  padding: .2rem .5rem;
  font-size: .8125rem;
  height: auto;
  cursor: pointer;
}

/* ── Analysis sub-row ────────────────────────────────────── */

.analysis-sub-row td {
  background: var(--surface);
  padding: .3rem 1rem .45rem;
  border-top: none;
}

.analysis-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .2rem .6rem;
  font-size: .775rem;
  color: var(--text-muted);
}

.analysis-stat strong { color: var(--text); }
.analysis-sep         { color: var(--border-light); }
.analysis-error       { color: var(--error); }
.analysis-pending     { font-style: italic; }

/* ── Job status badge variants ───────────────────────────── */

.badge-running  { background: var(--info-bg);    color: var(--info);    border-color: var(--info); }
.badge-done     { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.badge-error    { background: var(--error-bg);   color: var(--error);   border-color: var(--error); }

.job-error {
  font-size: .78rem;
  color: var(--error);
  max-width: 28ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Utilities ───────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Mobile / responsive ─────────────────────────────────── */

@media (max-width: 640px) {

  /* Layout */
  .main         { padding: 0 max(.875rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(.875rem, env(safe-area-inset-left)); }
  .container    { padding-top: 1.25rem; }
  .header-inner { padding: 0 max(.875rem, env(safe-area-inset-right)) 0 max(.875rem, env(safe-area-inset-left)); gap: .5rem; }
  .header-email { display: none; }

  /* Page header: stack button below title */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: 1rem;
  }
  .page-header > .btn { align-self: stretch; justify-content: center; }

  /* Tables → stacked cards
     Uses data-label attributes on <td> elements to label each row.  */
  .card.p-0 thead { display: none; }

  .card.p-0 .table { border: none; }

  .card.p-0 tbody tr {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
  }
  .card.p-0 tbody tr:last-child { border-bottom: none; }
  .card.p-0 tbody tr:hover { background: var(--surface-2); }

  .card.p-0 td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: .2rem 0;
    border: none;
    font-size: .875rem;
  }

  .card.p-0 td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    width: 6.5rem;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-right: .5rem;
  }

  /* Action cell: no label, left-align buttons */
  .card.p-0 .td-action {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: .4rem;
    padding-top: .5rem;
  }
  .card.p-0 .td-action::before { content: none !important; }

  /* Filename cell: stack icon + name vertically on very small screens */
  .card.p-0 .td-filename { flex-direction: column; align-items: flex-start; gap: .15rem; }

  .scan-thumbnail-cell { width: auto; }
  .scan-thumbnail { width: 80px; height: 60px; }

  /* Hide analysis sub-rows (colspan layout breaks in stacked mode) */
  .analysis-sub-row { display: none; }

  /* Form rows: stack vertically */
  .form-row { flex-direction: column; align-items: stretch; gap: .5rem; }
  .inline-form { max-width: 100%; }

  /* Upload drop zone: more compact on mobile */
  .drop-zone { padding: 1.75rem 1rem; }
  .drop-zone svg { width: 28px; height: 28px; margin-bottom: .5rem; }

  /* 3-D preview canvas: shorter on mobile */
  .preview-canvas { height: 260px; }

  /* Hint bar: hide desktop wording */
  .preview-hint { font-size: .7rem; letter-spacing: 0; }

  /* Scan metadata */
  .meta-label { width: 80px; }
  .meta-row   { gap: .75rem; }

  /* Cards */
  .card { border-radius: var(--radius); }
  .card.p-0 { border-radius: var(--radius); }

  /* Login */
  .login-card { padding: 2rem 1.25rem; }

  .file-card-grid { grid-template-columns: 1fr; }
  .file-card-actions .btn { flex: 1 1 auto; justify-content: center; }
  .danger-card { align-items: stretch; flex-direction: column; }
  .danger-card .btn { width: 100%; justify-content: center; }
  .section-heading-row { align-items: stretch; flex-direction: column; }
  .section-heading-row .btn { width: 100%; justify-content: center; }
  .photo-grid { grid-template-columns: 1fr; }
  .job-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Apple recommends a minimum 44px touch target. */
  .btn, .form-input { min-height: 44px; }
  .header-nav .btn { min-width: 44px; justify-content: center; }

  /* Stat grid: 2 cols on narrow screens */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
  .header-nav { gap: .4rem; }
  .btn-sm { padding: .3rem .5rem; font-size: .75rem; }
  .brand-logo { width: 66px; }
  .brand-product { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: .625rem; }
  .stat-value { font-size: 1.4rem; }
}

/* On touch devices the zone already reads "Tap to select…"; no extra patch needed. */
