:root {
  --ink: #142327;
  --ink-soft: #405458;
  --muted: #6b7d80;
  --paper: #f4f1e9;
  --panel: #fffdf8;
  --line: #d9d4c8;
  --brand: #0b3b45;
  --brand-2: #12616b;
  --accent: #d9772e;
  --success: #1e7a52;
  --success-soft: #e1f2e9;
  --warning: #9a5b12;
  --warning-soft: #fff0d9;
  --danger: #a13c36;
  --danger-soft: #fae5e2;
  --info-soft: #e4f0f2;
  --shadow: 0 16px 42px rgba(8, 32, 38, 0.09);
  --radius: 18px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(18, 97, 107, 0.11), transparent 30rem),
    linear-gradient(180deg, #f7f4ed 0%, var(--paper) 100%);
  min-height: 100vh;
  line-height: 1.48;
}
body.scan-page { background: linear-gradient(180deg, #efede5 0%, #f7f4ed 58%, #f0ece2 100%); }

h1, h2, h3, h4, p { margin-top: 0; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); line-height: 1.12; letter-spacing: -0.035em; margin-bottom: 0.4rem; }
h2 { font-size: 1.24rem; line-height: 1.25; margin-bottom: 0.65rem; letter-spacing: -0.015em; }
h3 { font-size: 1rem; margin-bottom: 0.5rem; }
h4 { font-size: 0.84rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.4rem; }
a { color: var(--brand-2); }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 0.88em; background: #ede9df; padding: 0.12rem 0.34rem; border-radius: 5px; word-break: break-word; }
pre { margin: 0; }

.topbar {
  background: var(--brand);
  color: #f8f5ed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.2rem);
  box-shadow: 0 4px 20px rgba(5, 28, 33, 0.2);
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: max(0.85rem, env(safe-area-inset-top));
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.22; }
.topbar-title strong { font-size: 1.02rem; }
.topbar-user { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; justify-content: flex-end; font-size: 0.88rem; }
.topbar .eyebrow { color: #b8d9dd; }
.topbar .text-link { color: #d3e8eb; text-decoration: none; }
.topbar .text-link:hover { text-decoration: underline; }
.topbar .role-chip { background: rgba(255, 255, 255, 0.13); border-color: rgba(255, 255, 255, 0.28); color: #fff; }
.topbar .button-ghost { color: #eef8f9; border-color: rgba(255, 255, 255, 0.35); }
.role-chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.12rem 0.52rem;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.69rem; font-weight: 700; color: var(--brand-2); margin-bottom: 0.15rem; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.tiny { font-size: 0.75rem; }
.hint { font-size: 0.79rem; color: var(--muted); line-height: 1.45; margin-bottom: 0; }
.form-error { min-height: 1.2em; color: var(--danger); font-size: 0.86rem; margin: 0; }
.text-link { color: var(--brand-2); text-decoration: underline; text-underline-offset: 2px; font-size: 0.88rem; }

.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 650;
  font-size: 0.9rem;
  line-height: 1.2;
  padding: 0.66rem 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  gap: 0.35rem;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  min-height: 2.55rem;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-primary { background: var(--brand); color: #fff; box-shadow: 0 5px 14px rgba(11, 59, 69, 0.2); }
.button-primary:hover:not(:disabled) { background: #0e4954; }
.button-secondary { background: #e8e2d5; color: var(--ink); }
.button-secondary:hover:not(:disabled) { background: #dfd6c4; }
.button-ghost { background: transparent; color: inherit; border-color: var(--line); }
.button-ghost:hover:not(:disabled) { background: rgba(11, 59, 69, 0.06); }
.button-success { background: var(--success); color: #fff; }
.button-warning { background: var(--accent); color: #fff; }
.button-danger { background: var(--danger); color: #fff; }
.button-small { font-size: 0.82rem; padding: 0.44rem 0.8rem; min-height: 2.1rem; }
.button-tiny { font-size: 0.74rem; padding: 0.3rem 0.58rem; min-height: 1.75rem; }
.button-wide { width: 100%; }
.button-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.panel {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.4vw, 1.4rem);
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.8rem; margin-bottom: 0.9rem; }
.panel-head.compact { margin-bottom: 0.35rem; align-items: center; }
.panel-head h2, .panel-head h1 { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grow { flex: 1 1 12rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field > span, .field-label { font-size: 0.78rem; font-weight: 650; color: var(--ink-soft); letter-spacing: 0.01em; }
.field input, .field select, .field textarea {
  font: inherit;
  font-size: 0.94rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c7c1b4;
  border-radius: var(--radius-sm);
  padding: 0.63rem 0.72rem;
  width: 100%;
  min-height: 2.65rem;
}
.field textarea { resize: vertical; min-height: 4rem; }
.field input:focus, .field select:focus, .field textarea:focus, .button:focus-visible, .nav-item:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(18, 97, 107, 0.25);
  outline-offset: 1px;
  border-color: var(--brand-2);
}
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.45rem 1rem; }
.check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--brand-2); }
.check-inline { align-self: end; padding: 0.6rem 0.15rem; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.8rem; align-items: start; }
.form-actions { display: flex; gap: 0.55rem; align-items: center; flex-wrap: wrap; }
.form-grid .form-actions { align-self: end; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.8rem; margin: 0; min-width: 0; }
.fieldset legend { font-size: 0.78rem; font-weight: 700; color: var(--ink-soft); padding: 0 0.35rem; }
.filter-row { display: flex; gap: 0.65rem; align-items: end; flex-wrap: wrap; margin-bottom: 0.8rem; }
.filter-row .field { min-width: 8.5rem; }
.filter-row .form-actions { margin-left: auto; }
select:disabled, input:disabled { background: #f0ede6; color: var(--muted); }

/* Login */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card {
  width: min(29rem, 100%);
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: clamp(1.3rem, 5vw, 2.2rem);
  box-shadow: var(--shadow);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 4.4rem;
  height: 4.4rem;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

/* Lector */
.scan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(19rem, 0.85fr);
  gap: 1rem;
  width: min(82rem, 100%);
  margin: 0 auto;
  padding: clamp(0.8rem, 2.4vw, 1.4rem);
  align-items: start;
}
.control-panel { display: flex; flex-direction: column; gap: 0.9rem; }
.mode-block { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem; background: #f8f4ea; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.mode-button {
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.05em;
  border: 1px solid #beb7aa;
  background: #fff;
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 0.85rem 0.5rem;
  font-size: 1.02rem;
  cursor: pointer;
}
.mode-button.is-active[data-mode="IN"] { background: var(--success); border-color: var(--success); color: #fff; box-shadow: 0 4px 14px rgba(30, 122, 82, 0.25); }
.mode-button.is-active[data-mode="OUT"] { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(217, 119, 46, 0.25); }
.mode-banner { margin: 0.55rem 0 0.2rem; font-weight: 800; letter-spacing: 0.08em; font-size: 0.8rem; color: var(--success); }
.mode-banner[data-mode="OUT"] { color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; margin-left: auto; }
.switch input { width: 1.15rem; height: 1.15rem; accent-color: var(--brand-2); }
.status-dot { font-size: 0.72rem; border: 1px solid #b8d4c7; color: var(--success); background: var(--success-soft); border-radius: 999px; padding: 0.2rem 0.55rem; }
.scanner-shell {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #24454b 0%, #0a2228 68%);
  aspect-ratio: 4 / 3;
  min-height: 14rem;
  border: 1px solid #203d43;
}
.scanner-shell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-shell:not(.camera-on) video { display: none; }
.scanner-shell.camera-on { aspect-ratio: 3 / 4; max-height: 58vh; }
.camera-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #d9e6e7;
  padding: 1.1rem;
}
.camera-placeholder p { margin: 0.18rem 0; max-width: 30rem; font-size: 0.86rem; }
.camera-icon { font-size: 2.4rem; color: #70a0a7; margin-bottom: 0.4rem; }
.camera-warning { color: #ffcf86 !important; font-weight: 650; }
.scan-frame {
  pointer-events: none;
  position: absolute;
  inset: 18% 12%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(3, 18, 21, 0.18);
  opacity: 0;
}
.scanner-shell.camera-on .scan-frame { opacity: 1; }
.manual-form { display: flex; align-items: end; gap: 0.55rem; }
.manual-form .field input { font-size: 1.12rem; letter-spacing: 0.04em; font-family: "Cascadia Mono", Consolas, monospace; }
.result-panel { position: sticky; top: 5.2rem; }
.result-card {
  border-radius: 16px;
  padding: 1.1rem;
  border: 2px solid #c9c2b5;
  background: #faf7f0;
  min-height: 12rem;
  transition: background 0.15s ease, border 0.15s ease;
}
.result-kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.68rem; font-weight: 800; color: var(--muted); margin-bottom: 0.2rem; }
.result-card h2 { font-size: clamp(1.6rem, 5vw, 2.5rem); letter-spacing: -0.03em; margin-bottom: 0.3rem; }
.result-idle h2 { font-size: 1.4rem; }
.result-message { font-size: 0.98rem; margin-bottom: 0.6rem; }
.result-success { background: var(--success-soft); border-color: #7bb89d; }
.result-success h2 { color: #145c3c; }
.result-danger { background: var(--danger-soft); border-color: #d08b84; }
.result-danger h2 { color: #7f2a25; }
.result-warning { background: var(--warning-soft); border-color: #e4b66f; }
.result-warning h2 { color: #7a470d; }
.result-error { background: #f7e3e0; border-color: #cf9993; }
.result-pending { background: var(--info-soft); border-color: #8fbcc3; }
.result-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 0.2rem 0.9rem; margin: 0.7rem 0 0; }
.result-details > div { border-top: 1px dashed rgba(20, 35, 39, 0.18); padding: 0.35rem 0; min-width: 0; }
.result-details dt { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.result-details dd { margin: 0.1rem 0 0; font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.retry-box { margin-top: 0.8rem; background: rgba(255, 255, 255, 0.75); border: 1px solid #dfb16b; border-radius: 10px; padding: 0.75rem; }
.retry-box p { font-size: 0.86rem; }
.retry-box code { display: block; margin-top: 0.4rem; font-size: 0.72rem; }
.recent-block { margin-top: 1rem; }
.recent-list { list-style: none; padding: 0; margin: 0.4rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; max-height: 18rem; overflow: auto; }
.recent-item { display: flex; justify-content: space-between; gap: 0.6rem; border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px; padding: 0.48rem 0.6rem; background: #fffdf8; }
.recent-item.ok { border-left-color: var(--success); }
.recent-item.bad { border-left-color: var(--danger); }
.recent-main { display: flex; flex-direction: column; min-width: 0; }
.recent-main strong { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-main span { font-size: 0.72rem; color: var(--muted); }
.recent-meta { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; font-size: 0.71rem; color: var(--muted); }
.operator-tip { margin-top: 1rem; background: #fff7e7; border: 1px solid #ead3a9; border-radius: 10px; padding: 0.7rem; font-size: 0.83rem; }
.toast-host { position: fixed; right: 1rem; bottom: max(1rem, env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 0.45rem; max-width: min(24rem, calc(100vw - 2rem)); }
.toast { padding: 0.7rem 0.85rem; border-radius: 10px; background: var(--brand); color: #fff; box-shadow: 0 8px 22px rgba(6, 29, 34, 0.25); font-size: 0.86rem; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: #8a5110; }

/* Administración */
.admin-shell {
  display: grid;
  grid-template-columns: 14.5rem minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 4rem);
  max-width: 100rem;
  margin: 0 auto;
}
.admin-nav {
  padding: 1rem 0.8rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  position: sticky;
  top: 4.2rem;
  align-self: start;
  max-height: calc(100vh - 4.2rem);
  overflow: auto;
}
.nav-item {
  font: inherit;
  text-align: left;
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.56rem 0.65rem;
  cursor: pointer;
  text-decoration: none;
}
.nav-item:hover { background: rgba(11, 59, 69, 0.06); }
.nav-item.is-active { background: var(--brand); color: #fff; }
.nav-link { display: block; }
.nav-divider { height: 1px; background: var(--line); margin: 0.5rem 0.2rem; }
.admin-main { padding: clamp(1rem, 2.8vw, 2rem); min-width: 0; }
.tab-panel { display: flex; flex-direction: column; gap: 1rem; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.1rem; }
.page-heading > div:first-child { max-width: 54rem; }
.page-heading p { margin-bottom: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.7rem; }
.stat-grid.compact { grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); margin-bottom: 0.9rem; }
.stat-card { background: #fffdf8; border: 1px solid var(--line); border-radius: 13px; padding: 0.75rem 0.85rem; box-shadow: 0 7px 18px rgba(8, 32, 38, 0.045); display: flex; flex-direction: column; gap: 0.12rem; min-width: 0; }
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; }
.stat-value { font-size: 1.65rem; line-height: 1.1; letter-spacing: -0.03em; }
.stat-hint { font-size: 0.72rem; color: var(--muted); }
.stat-danger { border-color: #d7a19b; background: #fdf1ef; }
.stat-warning { border-color: #e3c28c; background: #fff8eb; }
.stat-success { border-color: #a6cdb9; background: #f2faf6; }
.notice { border: 1px solid #a9c8ce; background: var(--info-soft); border-radius: 11px; padding: 0.7rem 0.85rem; font-size: 0.87rem; }
.notice p { margin: 0.15rem 0; }
.notice-warning { border-color: #e1bd7e; background: var(--warning-soft); color: #5c390b; }
.notice-error { border-color: #d7a19b; background: var(--danger-soft); color: #6d2521; }
.notice-success { border-color: #a6cdb9; background: var(--success-soft); color: #145c3c; }
.plain-list { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.plain-list.small { font-size: 0.82rem; gap: 0.25rem; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.table-wrap.tall { max-height: 62vh; }
.data-table { border-collapse: collapse; width: 100%; font-size: 0.82rem; min-width: 42rem; }
.data-table th, .data-table td { padding: 0.52rem 0.6rem; border-bottom: 1px solid #ece7dc; text-align: left; vertical-align: top; }
.data-table th { background: #f1ede4; font-size: 0.69rem; text-transform: uppercase; letter-spacing: 0.055em; color: var(--ink-soft); position: sticky; top: 0; z-index: 2; }
.data-table tbody tr:hover { background: #fcf9f2; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table code { white-space: nowrap; }
.compact-table { min-width: 34rem; }
.row-warning { background: #fff8e9; }
.row-error { background: #fdf0ee; }
.row-voided { opacity: 0.6; }
.row-voided td:nth-child(2) { text-decoration: line-through; }
.cell-wrap { min-width: 13rem; max-width: 25rem; overflow-wrap: anywhere; }
.actions-cell { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.badge { display: inline-block; border-radius: 999px; padding: 0.1rem 0.46rem; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.025em; white-space: nowrap; border: 1px solid transparent; }
.badge-success { background: var(--success-soft); color: #155f3f; border-color: #b4d9c6; }
.badge-warning { background: var(--warning-soft); color: #784408; border-color: #e7c994; }
.badge-danger { background: var(--danger-soft); color: #7f2a25; border-color: #dfb1ac; }
.badge-muted { background: #edeae2; color: #5f6664; border-color: #d8d3c8; }
.badge-premium { background: #ede7f8; color: #543a85; border-color: #cdbfe8; }
.inline-badges { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.35rem; }
.pill { display: inline-block; background: #edf3f3; border: 1px solid #c7d9da; color: var(--brand); border-radius: 999px; padding: 0.08rem 0.42rem; font-size: 0.7rem; margin: 0 0.2rem 0.2rem 0; }
.panel > h2:first-child { margin-top: 0; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244, 241, 233, 0.95); backdrop-filter: blur(6px); padding: 0.7rem 0; border-top: 1px solid var(--line); }
.issues { margin: 0; padding-left: 1rem; font-size: 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }
.issue-error { color: var(--danger); }
.issue-warning { color: var(--warning); }
.select-small { min-height: 2rem !important; padding: 0.3rem 0.4rem !important; font-size: 0.78rem !important; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0.55rem; margin: 0.5rem 0 0.8rem; }
.meta-grid dt { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.meta-grid dd { margin: 0.1rem 0 0; font-size: 0.85rem; font-weight: 600; }
.activity-card { break-inside: avoid; }
.gates-list li { margin-bottom: 0.3rem; }
.gate-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; border-bottom: 1px dashed var(--line); padding: 0.35rem 0; font-size: 0.84rem; }
.gate-row:last-child { border-bottom: 0; }
.window-row { display: grid; grid-template-columns: minmax(8rem, 1fr) minmax(11rem, 1.2fr) minmax(11rem, 1.2fr) auto; gap: 0.5rem; align-items: end; border: 1px dashed var(--line); border-radius: 9px; padding: 0.5rem; }
.inside-activity { border-top: 1px solid var(--line); padding-top: 0.8rem; margin-top: 0.8rem; }
.history-box { border: 1px solid var(--line); background: #faf7ef; border-radius: 9px; padding: 0.65rem; max-height: 15rem; overflow: auto; }
.history-box h3 { font-size: 0.9rem; }
.history-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.audit-details { max-height: 15rem; overflow: auto; white-space: pre-wrap; font-size: 0.7rem; background: #f7f3e9; padding: 0.5rem; border-radius: 6px; }
.report-main { max-width: 94rem; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }

/* Modales */
.modal {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.15rem;
  width: min(52rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(5, 28, 33, 0.32);
}
.modal::backdrop { background: rgba(7, 27, 32, 0.55); backdrop-filter: blur(2px); }
.modal form { margin: 0; }

@media (max-width: 980px) {
  .scan-layout { grid-template-columns: 1fr; }
  .result-panel { position: static; }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-nav {
    position: sticky;
    top: 3.6rem;
    z-index: 20;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 0.45rem 0.7rem;
    max-height: none;
    background: rgba(244, 241, 233, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(7px);
  }
  .nav-item { white-space: nowrap; font-size: 0.8rem; padding: 0.45rem 0.6rem; }
  .nav-divider { width: 1px; height: auto; margin: 0.2rem; }
  .admin-main { padding: 0.9rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .history-columns { grid-template-columns: 1fr; }
  .window-row { grid-template-columns: 1fr 1fr; }
  .window-row .button { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; padding-left: 0.8rem; padding-right: 0.8rem; }
  .topbar-user { gap: 0.45rem; font-size: 0.78rem; }
  .topbar-user .role-chip { display: none; }
  .scan-layout { padding: 0.65rem; gap: 0.65rem; }
  .panel { border-radius: 14px; padding: 0.85rem; }
  .grid-2 { grid-template-columns: 1fr; gap: 0.65rem; }
  .manual-form { flex-direction: column; align-items: stretch; }
  .manual-form .button { width: 100%; }
  .scanner-shell { min-height: 10rem; }
  .scanner-shell.camera-on { max-height: 52vh; }
  .button-row .button { flex: 1 1 auto; }
  .filter-row { align-items: stretch; }
  .filter-row .field, .filter-row .check-inline { min-width: 100%; }
  .filter-row .form-actions { margin-left: 0; }
  .form-actions .button { flex: 1 1 auto; }
  .result-details { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.35rem; }
  .admin-nav { top: 3.6rem; }
  .page-heading { gap: 0.6rem; }
  .page-heading .button-row { width: 100%; }
  .page-heading .button-row .button { flex: 1 1 auto; }
  .table-wrap.tall { max-height: 68vh; }
  .window-row { grid-template-columns: 1fr; }
  .window-row .button { grid-column: auto; }
  .modal { width: calc(100vw - 1rem); padding: 0.8rem; max-height: calc(100vh - 1rem); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
