:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #0a0a0a;
  --panel-light: #121212;
  --muted: #737373;
  --text: #f5f5f5;
  --line: rgba(255, 255, 255, 0.06);
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #0a1020 0%, #020617 100%);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus, button:focus {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  outline-offset: 2px;
}
textarea { resize: vertical; }

.app-shell {
  width: min(1180px, calc(100% - 1rem));
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0.75rem) 0 calc(env(safe-area-inset-bottom, 1rem) + 1.5rem);
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 0.9rem;
}
.brand-block {
  display: grid;
  gap: 0.35rem;
  max-width: 520px;
}
.brand-logo {
  width: min(430px, 100%);
  height: auto;
  display: block;
  color: var(--text);
  overflow: visible;
}
.logo-title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  letter-spacing: 0.01em;
}
.logo-subtitle {
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.topbar-note {
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
  max-width: 58ch;
}
.layout {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: 1fr;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}
.hero-card { padding: 0.8rem; }
.hero-header, .section-header, .scanner-toolbar, .summary-row, .toolbar, .inventory-header, .detail-header, .history-item-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
}
h1, h2, h3, h4, p, dd, dt { margin: 0; }
h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
h3 { font-size: 1rem; font-weight: 700; }
h4 { font-size: 0.9rem; }
.subtle { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.compact { margin-top: 0.35rem; }
.compact-header { margin-bottom: 0.75rem; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}
.badge-muted { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; }

/* ── Scan mode checkboxes ── */
.scan-mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.mode-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  padding: 0.7rem 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  user-select: none;
}
.mode-check:has(input:checked) {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(125, 211, 252, 0.45);
  color: #d6f4ff;
}
.mode-check input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.mode-check span {
  font-size: 0.92rem;
}

/* ── OCR field selector ── */
.ocr-field-selector {
  margin-top: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.14);
}
.ocr-field-checks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.5rem;
}
.field-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  user-select: none;
}
.field-check:has(input:checked) {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.4);
  color: #bbf7d0;
}
.field-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  padding: 0;
  accent-color: var(--ok);
  cursor: pointer;
  flex-shrink: 0;
}
.field-check span {
  font-size: 0.85rem;
}

/* ── OCR field indicator (during scanning) ── */
.ocr-field-indicator {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  z-index: 12;
  pointer-events: none;
}
.field-badge {
  display: inline-flex;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.2);
  color: #bae6fd;
  border: 1px solid rgba(56, 189, 248, 0.4);
}
.field-badge.active {
  background: rgba(34, 197, 94, 0.2);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.5);
  animation: field-pulse 1.2s ease-in-out infinite;
}
.field-progress {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
}
.field-remaining {
  font-size: 0.75rem;
  color: rgba(148, 163, 184, 0.7);
}
@keyframes field-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Legacy mode chip (kept for compat) ── */
.mode-chip {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  padding: 0.7rem 0.85rem;
  font-weight: 700;
}
.mode-chip.is-active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(125, 211, 252, 0.45);
  color: #d6f4ff;
}

.scan-controls-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.8rem 0 0.6rem;
  padding: 0.85rem;
  background: var(--panel-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.status-selector-compact {
  margin-top: 0;
  padding: 0.6rem;
  font-size: 1rem;
  font-weight: 700;
  background: var(--bg);
  border-color: var(--line);
  color: var(--accent);
  text-align: center;
}
.unified-scan-btn {
  font-size: 1rem;
  letter-spacing: 0.05em;
  padding: 0.85rem;
  box-shadow: none;
  font-weight: 900;
}
#quickStatusCustom {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--accent);
  color: #fff;
  border-radius: 12px;
  margin-top: -0.25rem;
  text-align: center;
}
.quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin: 0.95rem 0 0.85rem;
}
.primary-action, .secondary-action, .ghost-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 2.75rem;
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  font-size: 0.9rem;
}
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}
.primary-action {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #00111d;
}
.secondary-action {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #03130a;
}
.ghost-button {
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.18);
}
.danger-text { color: #fecaca; }
.scan-layout { display: grid; gap: 1rem; }
.reader {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0.5rem auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}
.reader video { 
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Red scan line ── */
.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, #ff3333 15%, #ff3333 85%, transparent 100%);
  box-shadow: 0 0 12px rgba(255, 51, 51, 0.5), 0 0 4px rgba(255, 51, 51, 0.8);
  animation: scan-sweep 2.2s ease-in-out infinite;
  z-index: 10;
  pointer-events: none;
  border-radius: 1px;
}
@keyframes scan-sweep {
  0%, 100% { top: 20%; opacity: 0.7; }
  50% { top: 80%; opacity: 1; }
}

.ocr-frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
}
.ocr-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.ocr-overlay {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: #dbeafe;
  font-size: 0.88rem;
  line-height: 1.35;
  backdrop-filter: blur(10px);
  z-index: 11;
}
.hint { margin-top: 0.75rem; color: var(--muted); font-size: 0.9rem; }
.scan-sidebar { display: grid; gap: 0.75rem; }
.inset-card, .detail-panel {
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  padding: 0.9rem;
}
#lastSerial { font-size: 1.3rem; display: block; margin-top: 0.35rem; word-break: break-all; }
.alert, .feedback-banner {
  border-radius: 16px;
  padding: 0.9rem 1rem;
  border: 1px solid transparent;
}
.alert {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}
.feedback-banner.info { background: rgba(56, 189, 248, 0.12); border-color: rgba(56, 189, 248, 0.4); color: #bae6fd; }
.feedback-banner.success { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.feedback-banner.error { background: rgba(248, 113, 113, 0.12); border-color: rgba(248, 113, 113, 0.4); color: #fecaca; }
.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
}
.field-full { grid-column: 1 / -1; }
label span { font-weight: 600; }
.form-actions, .header-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.toolbar { margin: 1rem 0 0.75rem; }
.search-field { flex: 1 1 280px; }
.filter-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.filter-chip {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  padding: 0.65rem 0.8rem;
}
.filter-chip.active { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }
.summary-row {
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
  padding: 0.5rem 0;
  gap: 1rem;
  font-weight: 600;
  text-transform: uppercase;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.detail-grid div, .history-item {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 14px;
  padding: 0.9rem;
}
.detail-grid dt {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-grid dd { font-weight: 600; }
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}
.history-meta {
  color: var(--muted);
  font-size: 0.86rem;
  margin-left: 0.4rem;
}
.detail-empty { min-height: 160px; display: grid; align-content: center; gap: 0.35rem; }
.table-wrapper { overflow: auto; margin-top: 0.75rem; }
.inventory-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.inventory-table th, .inventory-table td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.88rem;
}
.inventory-table tbody tr:hover, .inventory-table tbody tr.is-selected { background: rgba(148, 163, 184, 0.05); }
.serial-cell strong { display: block; }
.serial-meta { display: block; margin-top: 0.25rem; color: var(--muted); font-size: 0.8rem; }
.status-pill {
  display: inline-flex;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}
.status-INSTALADO { background: rgba(34, 197, 94, 0.14); color: #86efac; }
.status-DESINSTALADO { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }
.status-RETIRADO { background: rgba(245, 158, 11, 0.14); color: #fcd34d; }
.status-AVERIADO { background: rgba(248, 113, 113, 0.14); color: #fca5a5; }
.table-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.table-actions button {
  min-height: auto;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.85rem;
}
.hidden, .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;
}
.hidden { display: none !important; }
.empty-state {
  padding: 1.5rem 0.75rem;
  text-align: center;
  color: var(--muted);
}

@media (min-width: 840px) {
  .scan-layout { grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr); }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .app-shell { width: min(100% - 0.8rem, 1180px); }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding-top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
  }
  .brand-block {
    max-width: none;
  }
  .brand-logo {
    width: min(100%, 360px);
  }
  .hero-header, .section-header, .scanner-toolbar, .toolbar, .detail-header, .history-item-header {
    align-items: flex-start;
  }
  .scan-mode-switch {
    grid-template-columns: 1fr;
  }
  .ocr-field-checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .header-actions, .form-actions { flex-direction: column; }
  .header-actions > *, .form-actions > * { width: 100%; }
  .summary-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .reader { min-height: 220px; }
  .inventory-table { min-width: 0; }
  .inventory-table th:nth-child(3),
  .inventory-table th:nth-child(4),
  .inventory-table th:nth-child(5),
  .inventory-table th:nth-child(6),
  .inventory-table td:nth-child(3),
  .inventory-table td:nth-child(4),
  .inventory-table td:nth-child(5),
  .inventory-table td:nth-child(6) {
    display: none;
  }
  .inventory-table th:nth-child(1),
  .inventory-table td:nth-child(1) { min-width: 180px; }
  .inventory-table th:nth-child(2),
  .inventory-table td:nth-child(2) { min-width: 108px; }
  .inventory-table th:nth-child(7),
  .inventory-table td:nth-child(7) { min-width: 132px; }
  .table-actions { flex-direction: column; }
  .table-actions button { width: 100%; }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand-block {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.developer-credit-badge {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  margin-top: -0.2rem;
  margin-left: 2px;
}
.developer-credit-badge a {
  color: var(--accent);
  text-decoration: none;
}
.layout {
  padding: 0.4rem 0.4rem 1.5rem;
  display: grid;
  gap: 0.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

