:root {
  --bg-base: #0a0a0a;
  --bg-surface: #1a1a1a;
  --bg-elevated: #222222;
  --bg-hover: #2a2a2a;
  --bg-input: #141414;
  --text-primary: #f3f4f6;
  --text-muted: #9ca3af;
  --text-subtle: #6b7280;
  --text-inverse: #0a0a0a;
  --accent-gold: #d89717;
  --accent-gold-muted: rgba(216, 151, 23, 0.15);
  --accent-orange: #f27121;
  --accent-gradient: linear-gradient(135deg, #f27121 0%, #d89717 100%);
  --border-color: #2d2d2d;
  --border-strong: #3d3d3d;
  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.15);
  --danger: #ef4444;
  --danger-muted: rgba(239, 68, 68, 0.15);
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --sidebar-width: 16.5rem;
  --focus-ring: 0 0 0 3px rgba(216, 151, 23, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 2.75rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; min-height: 100dvh; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-base);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(242, 113, 33, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(216, 151, 23, 0.05), transparent);
}
a { color: var(--accent-gold); text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }

.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-gold { color: var(--accent-gold); }
.h2 { font-size: clamp(1.25rem, 4vw, 1.5rem); font-weight: 700; margin: 0; }
.page-kicker { margin: 0 0 0.25rem; font-size: 0.875rem; }

.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.625rem 1.25rem;
  font: 600 0.875rem/1.2 inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: transparent;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { color: var(--text-inverse); background: var(--accent-gradient); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-sm { min-height: 2.25rem; padding: 0.4rem 0.7rem; font-size: 0.75rem; }
.btn-consult { width: 100%; max-width: 16rem; }
.btn-scan {
  flex-shrink: 0;
  min-width: var(--tap);
  color: var(--text-inverse);
  background: var(--accent-gradient);
  padding-inline: 0.85rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.form-control {
  width: 100%;
  min-height: var(--tap);
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.form-control:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: var(--focus-ring);
}
.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
.form-grid .full { grid-column: 1 / -1; }
@media (min-width: 801px) {
  .form-grid {
    grid-template-columns: minmax(12rem, 18rem) minmax(0, 1fr);
  }
  .field-barcode .form-control {
    min-height: 3.15rem;
    font-size: 1.125rem;
    letter-spacing: 0.04em;
  }
  .field-barcode .btn-scan {
    min-height: 3.15rem;
    padding-inline: 1.1rem;
  }
}
.stack { display: flex; flex-direction: column; gap: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.consult-card { padding: 1.25rem; margin-bottom: 1.25rem; }
.consult-actions { margin-top: 1rem; }
.consult-feedback { margin: 0; flex: 1 1 12rem; }
.field-scan { display: flex; gap: 0.5rem; align-items: stretch; }

.badge {
  display: inline-flex;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 0.375rem;
  white-space: nowrap;
}
.badge--danger { color: var(--danger); background: var(--danger-muted); }
.badge--success { color: var(--success); background: var(--success-muted); }

.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--safe-top)) 1rem max(1rem, var(--safe-bottom));
}
.auth__card { width: 100%; max-width: 24rem; padding: 1.5rem; }
.auth__brand { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-bottom: 1.5rem; }
.auth__brand img { width: min(14rem, 70vw); }
.auth__kicker {
  margin: 0;
  letter-spacing: 0.28em;
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 600;
}

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #111;
  border-right: 1px solid var(--border-color);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
}
.sidebar__brand { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1.5rem; }
.sidebar__brand img { width: 2.5rem; }
.sidebar__name { display: block; font-size: 0.875rem; }
.sidebar__nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-link {
  color: var(--text-muted);
  padding: 0.65rem 0.85rem;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
}
.nav-link.is-active, .nav-link:hover {
  color: var(--text-primary);
  background: var(--accent-gold-muted);
}
.sidebar__foot { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding-top: 1rem; }
.app-main {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem calc(1.5rem + var(--safe-bottom));
  overflow: auto;
}
.page-header { margin-bottom: 1.25rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat { padding: 1rem; }
.stat strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.1rem;
  word-break: break-all;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid #242424;
}
.data-table th {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-elevated);
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.empty-state { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; }
.alert--error { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; word-break: break-all; }
.cell-saldo { display: flex; gap: 0.5rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

.item-list { display: none; }
.item-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.item-card.is-empty { border-color: rgba(239, 68, 68, 0.35); }
.item-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.item-card__saldo {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.item-card__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.35;
}
.item-card__meta {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.75rem;
}
.item-card__meta div { min-width: 0; }
.item-card__meta dt {
  color: var(--text-subtle);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.2rem;
}
.item-card__meta dd {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.item-card__price {
  margin: 0.15rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border-color);
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 1.05rem;
}

.scanner {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--safe-top) 0.75rem var(--safe-bottom);
}
.scanner__panel {
  width: min(32rem, 100%);
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 1rem);
  overflow: auto;
  background: #111;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) 0.35rem 0.35rem;
  padding: 1rem;
}
.scanner__bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.scanner__kicker {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-gold);
}
.scanner__reader {
  overflow: hidden;
  border-radius: var(--radius-md);
  background: #000;
  min-height: 12rem;
}
.scanner__reader video { width: 100% !important; border-radius: var(--radius-md); }
.scanner__hint {
  margin: 0.85rem 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}
.scanner__file {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.scanner__file input { display: none; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }
  .sidebar__brand { margin: 0; flex: 1; }
  .sidebar__nav { display: none; }
  .sidebar__foot { padding: 0; margin-left: auto; }
  .app-main { padding: 1rem 1rem calc(1.25rem + var(--safe-bottom)); }
  .consult-card { padding: 1rem; }
  .btn-consult { max-width: none; }
  .btn-scan span { display: none; }
  .auth__card { padding: 1.25rem; }

  .table-wrap { display: none; }
  .item-list { display: grid; gap: 0.75rem; }
  .empty-state { padding: 1.5rem 0.5rem; }
}

@media (min-width: 801px) {
  .scanner {
    align-items: center;
    padding: 1.5rem;
  }
  .scanner__panel {
    border-radius: var(--radius-lg);
    max-height: min(40rem, 90vh);
  }
}
