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

/* ── New York Theme — Zinc palette ───────────────────────────────────────── */
:root {
  --bg:         #09090b;   /* zinc-950 */
  --bg2:        #111113;
  --bg3:        #18181b;   /* zinc-900 */
  --surface:    #1c1c1f;
  --surface2:   #27272a;   /* zinc-800 */
  --border:     #3f3f46;   /* zinc-700 */
  --border2:    #52525b;   /* zinc-600 */
  --text:       #fafafa;   /* zinc-50 */
  --text-muted: #71717a;   /* zinc-500 */
  --text-dim:   #a1a1aa;   /* zinc-400 */
  --primary-bg: #fafafa;
  --primary-fg: #09090b;
  --success:    #4ade80;
  --danger:     #f87171;
  --warn:       #fbbf24;
  --qty-color:  #e4e4e7;   /* zinc-200 */
  --radius:     8px;
  --radius-sm:  4px;
  --header-h:   50px;
  --tools-h:    88px;   /* scan-row + address-row */
  --footer-h:   46px;
}

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.4; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Telas ────────────────────────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; height: 100dvh; overflow: hidden; }
.screen.active { display: flex; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#screen-login {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, var(--bg3) 0%, var(--bg) 70%);
}
.login-container {
  width: min(340px, 90vw); display: flex; flex-direction: column;
  align-items: center; gap: 14px;
}
.logo { font-size: 48px; color: var(--text-dim); }
.logo .ti { font-size: 48px; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.subtitle { color: var(--text-muted); font-size: 14px; text-align: center; }
/* ── OTP Input ────────────────────────────────────────────────────────────── */
.otp-root {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  width: 100%;
}
.otp-group { display: flex; gap: 4px; }
.otp-char {
  width: 34px; height: 42px;
  text-align: center; font-size: 17px; font-weight: 700; text-transform: uppercase;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
  caret-color: transparent;
}
.otp-char:focus {
  border-color: var(--border2);
  box-shadow: 0 0 0 3px rgba(250,250,250,.06);
}
.otp-char.otp-filled { border-color: var(--border2); }
.otp-sep {
  color: var(--text-muted); font-size: 18px; font-weight: 300;
  user-select: none; flex-shrink: 0;
}

/* ── Botões ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: background .15s, opacity .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--primary-bg); color: var(--primary-fg); width: 100%; padding: 13px; font-size: 15px; border-color: var(--primary-bg); }
.btn-primary:hover:not(:disabled) { background: #e4e4e7; }

.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(248,113,113,.1); }

.btn-icon {
  background: none; border: none; color: var(--text-dim); font-size: 20px;
  cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s; flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }

.error-msg {
  background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.25);
  color: #fca5a5; padding: 9px 14px; border-radius: var(--radius-sm);
  font-size: 13px; text-align: center; width: 100%;
}
.hidden { display: none !important; }

/* ── App Header (select-count) ───────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; height: var(--header-h); gap: 8px;
}
.header-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.badge-code {
  font-weight: 700; font-size: 13px; letter-spacing: 1px;
  background: var(--surface2); padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--border);
}
.badge-expiry { font-size: 12px; color: var(--text-muted); }

/* ── Count Header ─────────────────────────────────────────────────────────── */
.count-header {
  display: flex; align-items: center; gap: 4px; padding: 0 6px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; height: var(--header-h); order: 0;
}
.header-center { flex: 1; display: flex; flex-direction: column; align-items: center; overflow: hidden; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.address-chip {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--text-dim); background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 8px; max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: opacity .2s;
}
.address-chip.empty { opacity: 0; }

.count-title {
  font-size: 14px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

.sync-badge { font-size: 16px; padding: 4px; display: flex; align-items: center; }
.sync-badge.online  { color: var(--success); }
.sync-badge.offline { color: var(--text-muted); }

/* ── Barra de filtro ──────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 8px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; order: 1;
}
.filter-bar.hidden { display: none !important; }

#filter-input {
  flex: 1; min-width: 0; padding: 7px 10px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  transition: border-color .2s;
}
#filter-input:focus { border-color: var(--border2); }

#btn-filter-toggle.active { color: var(--text); background: var(--surface2); }

/* ── Câmera ───────────────────────────────────────────────────────────────── */
.camera-container {
  position: relative; flex-shrink: 0; background: #000;
  max-height: 210px; overflow: hidden; order: 2;
}
.camera-container video { width: 100%; height: 210px; object-fit: cover; display: block; }
.scan-overlay { position: absolute; inset: 0; pointer-events: none; }
.scan-line {
  position: absolute; width: 68%; left: 16%; height: 2px;
  background: var(--primary-bg); opacity: .7;
  animation: scanAnim 2s ease-in-out infinite;
}
@keyframes scanAnim { 0%,100% { top: 18%; } 50% { top: 78%; } }
.btn-camera-close {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.7); border: 1px solid rgba(255,255,255,.12);
  color: #fff; border-radius: 20px; padding: 5px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer; display: flex;
  align-items: center; gap: 5px;
}

/* ── Tools block ──────────────────────────────────────────────────────────── */
.tools-block {
  display: flex; flex-direction: column; flex-shrink: 0;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  order: 3;
}

/* layout bottom: tools vão para depois da lista */
#screen-count.tools-bottom .camera-container { order: 4; }
#screen-count.tools-bottom .tools-block      { order: 5; border-bottom: none; border-top: 1px solid var(--border); }
#screen-count.tools-bottom #items-container  { order: 3; }
#screen-count.tools-bottom .count-footer     { order: 6; }

/* ── Scan row ─────────────────────────────────────────────────────────────── */
.scan-row {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
#barcode-input {
  flex: 1; min-width: 0; padding: 8px 10px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  transition: border-color .2s;
}
#barcode-input:focus { border-color: var(--border2); }
#barcode-input.edit-mode { border-color: var(--warn); background: rgba(251,191,36,.05); }

.btn-scan-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim);
  font-size: 17px; transition: background .15s, color .15s, border-color .15s;
}
.btn-scan-icon:hover { background: var(--surface2); color: var(--text); }
.btn-scan-icon.save-mode { border-color: var(--warn); color: var(--warn); }
.btn-scan-icon.active    { border-color: var(--border2); color: var(--text); }

.btn-qty {
  width: 30px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim);
  font-size: 15px; transition: background .15s; user-select: none;
}
.btn-qty:hover  { background: var(--surface2); color: var(--text); }
.btn-qty:active { background: var(--border); }

.qty-input {
  width: 44px; text-align: center; padding: 8px 4px; font-size: 14px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.qty-input:focus { border-color: var(--border2); }

/* ── Address row ──────────────────────────────────────────────────────────── */
.address-row {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px;
}
.address-row-icon { color: var(--text-muted); font-size: 15px; flex-shrink: 0; }
.address-inline-input {
  flex: 1; min-width: 0; padding: 5px 7px; font-size: 13px; font-weight: 500;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  transition: border-color .2s, background .2s;
}
.address-inline-input:focus { border-color: var(--border); background: var(--surface); }
.address-inline-input::placeholder { color: var(--text-muted); }
.keep-label {
  display: flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--text-muted); cursor: pointer; white-space: nowrap; flex-shrink: 0;
  user-select: none;
}
.keep-label input[type="checkbox"] { cursor: pointer; accent-color: var(--text-dim); }

/* ── Items container ──────────────────────────────────────────────────────── */
.items-container {
  flex: 1; overflow-y: auto; padding: 5px 7px; display: flex;
  flex-direction: column; order: 4;
}
.items-list { display: flex; flex-direction: column; gap: 3px; }

/* Table header — hidden on mobile, grid on desktop */
.items-thead { display: none; }

/* ── Item row ─────────────────────────────────────────────────────────────── */
.item-row {
  display: flex; align-items: stretch; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: visible; transition: border-color .25s, background .25s; position: relative;
}
.item-row.item-flash   { border-color: var(--border2); }
.item-row.item-updated {
  border-color: var(--success);
  animation: rowPulse 1s ease-in-out 3; /* 3 ciclos = 3 s */
}
@keyframes rowPulse {
  0%, 100% { background: rgba(74,222,128,.04); }
  50%       { background: rgba(74,222,128,.18); }
}
.item-row.item-editing { border-color: var(--warn); }

/* ── Item columns (mobile) ────────────────────────────────────────────────── */
.item-row { min-height: 44px; }   /* altura uniforme independente de ter descrição */
.item-col-barcode {
  flex: 1; min-width: 0; padding: 8px 11px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.item-barcode-text {
  font-size: 13px; font-weight: 600; font-family: 'Courier New', monospace;
  letter-spacing: .4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
/* Descrição exibida abaixo do código nos cards mobile */
.item-addr-mobile {
  font-size: 11px; color: var(--text-muted); font-family: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-col-desc { display: none; } /* desktop only */
.item-desc-text {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-col-qty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 52px; padding: 0 8px; border-left: 1px solid var(--border); flex-shrink: 0;
}
.item-qty-num {
  font-size: 15px; font-weight: 700; color: var(--qty-color);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.item-qty-unit { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.item-col-actions {
  display: flex; align-items: center;
  border-left: 1px solid var(--border); flex-shrink: 0;
}
/* inline buttons: desktop only */
.item-btn-edit, .item-btn-delete { display: none; }

.item-menu-btn {
  width: 34px; display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  cursor: pointer; color: var(--text-muted); font-size: 17px;
  transition: background .15s, color .15s;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.item-menu-btn:hover { background: var(--surface2); color: var(--text); }

/* Mobile tap highlight */
.item-row { cursor: pointer; }
.item-row.item-selected { background: var(--surface2) !important; border-color: var(--border2); }

/* ── Dropdown ─────────────────────────────────────────────────────────────── */
.item-dropdown {
  position: absolute; right: 0; top: calc(100% + 3px); z-index: 200;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-width: 128px;
  box-shadow: 0 8px 24px rgba(0,0,0,.6); overflow: hidden;
}
.item-dropdown button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; font-size: 13px; font-weight: 500;
  background: none; border: none; color: var(--text); cursor: pointer;
  transition: background .15s;
}
.item-dropdown button:hover { background: var(--surface2); }
.item-dropdown button.dd-delete { color: var(--danger); }
.item-dropdown button.dd-delete:hover { background: rgba(248,113,113,.08); }
.item-dropdown .dd-sep { height: 1px; background: var(--border); }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; color: var(--text-muted);
  padding: 40px 20px; gap: 8px;
}
.empty-icon { font-size: 36px; color: var(--surface2); margin-bottom: 4px; }
.empty-state .small { font-size: 13px; }

/* ── Select count ─────────────────────────────────────────────────────────── */
.content { flex: 1; overflow-y: auto; padding: 18px 14px; }
.content h2 {
  font-size: 11px; font-weight: 700; margin-bottom: 14px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px;
}
.counts-list { display: flex; flex-direction: column; gap: 6px; }
.count-card {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 15px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .2s, background .2s;
  color: var(--text); text-align: left;
}
.count-card:hover { border-color: var(--border2); background: var(--surface2); }
.count-card strong { font-size: 15px; }
.count-meta { font-size: 12px; color: var(--text-muted); }
.loading-text { color: var(--text-muted); text-align: center; padding: 20px; font-size: 14px; }
.error-text   { color: var(--danger);    text-align: center; padding: 20px; font-size: 14px; }
.offline-notice {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px; margin-bottom: 8px;
  background: rgba(251,191,36,.07); border: 1px solid rgba(251,191,36,.2);
  border-radius: var(--radius-sm); font-size: 12px; color: var(--warn);
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
.count-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--bg2); border-top: 1px solid var(--border);
  flex-shrink: 0; height: var(--footer-h); font-size: 13px; color: var(--text-muted);
  gap: 8px; order: 6;
}
.count-footer .ti { font-size: 15px; vertical-align: middle; margin-right: 3px; }
.count-footer strong { color: var(--text); }
.pending-badge {
  display: flex; align-items: center; gap: 4px;
  background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.25);
  color: var(--warn); font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
  cursor: pointer; position: relative; user-select: none;
}
.pending-badge:hover { background: rgba(251,191,36,.14); }

/* ── Pending tooltip ──────────────────────────────────────────────────────── */
.pending-tooltip {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 13px;
  font-size: 12px; color: var(--text-dim); line-height: 1.55; font-weight: 400;
  width: 230px; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  pointer-events: none; opacity: 0; transition: opacity .18s;
  white-space: normal; z-index: 300;
}
.pending-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--border);
}
.pending-badge.tooltip-open .pending-tooltip { opacity: 1; }

/* ── Modais ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  backdrop-filter: blur(6px); display: flex; align-items: center;
  justify-content: center; z-index: 1000; padding: 20px;
}
.modal-box {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; width: min(380px,100%);
  box-shadow: 0 8px 32px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 16px;
}
.modal-box-sm { width: min(300px,100%); }
.modal-box h3 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-delete-desc { font-size: 13px; color: var(--text-dim); line-height: 1.5; }

.modal-box input, .modal-box select {
  width: 100%; padding: 6px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 12px; outline: none; transition: border-color .2s;
}
.modal-box input:focus, .modal-box select:focus { border-color: var(--border2); }
.modal-box select option { background: var(--bg3); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn { min-width: 88px; }

.setting-row { display: flex; flex-direction: column; gap: 6px; }
.setting-row > label { font-size: 13px; color: var(--text-dim); }
.setting-hint { color: var(--text-muted); font-size: 11px; }

/* ── Setting toggle group (topo / rodapé) ─────────────────────────────────── */
.setting-toggle-group { display: flex; gap: 6px; }
.setting-toggle {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); cursor: pointer; transition: all .15s;
}
.setting-toggle:hover { border-color: var(--border2); color: var(--text); }
.setting-toggle.active {
  background: var(--surface2); border-color: var(--border2); color: var(--text);
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 2000;
  display: flex; gap: 5px; align-items: center;
  pointer-events: none; width: min(320px, 90%);
  /* padrão: controles no topo → toast logo abaixo dos controles (topo da lista) */
  top: calc(var(--header-h) + var(--tools-h) + 8px);
  bottom: auto;
  flex-direction: column;
}
/* controles no rodapé → toast logo acima dos controles (base da lista) */
.toast-container.toast-top {
  bottom: calc(var(--footer-h) + var(--tools-h) + 8px);
  top: auto;
  flex-direction: column-reverse;
}
.toast {
  font-size: 13px; font-weight: 600;
  padding: 8px 16px; border-radius: 20px;
  border: 1px solid transparent;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(10px);
  transition: opacity .22s, transform .22s;
  pointer-events: none; text-align: center; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateY(0); }

.toast.toast-success {
  background: #14532d;
  border-color: #16a34a;
  color: #bbf7d0;
}
.toast.toast-error {
  background: #7f1d1d;
  border-color: #dc2626;
  color: #fecaca;
}
.toast.toast-warn {
  background: #78350f;
  border-color: #d97706;
  color: #fde68a;
}
.toast.toast-info {
  background: var(--surface2);
  border-color: var(--border2);
  color: var(--text);
}

/* ── Tamanhos sm para modal de settings ──────────────────────────────────── */
.btn-sm { padding: 7px 14px !important; font-size: 13px !important; }
.input-sm, .select-sm {
  width: 100%; padding: 7px 10px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
  transition: border-color .2s;
}
.input-sm:focus, .select-sm:focus { border-color: var(--border2); }
.select-sm option { background: var(--bg3); }
.setting-row label { font-size: 12px; }

/* ── Tema Claro ───────────────────────────────────────────────────────────── */
body.theme-light {
  --bg:         #ffffff;
  --bg2:        #fafafa;
  --bg3:        #f4f4f5;
  --surface:    #f4f4f5;
  --surface2:   #e4e4e7;
  --border:     #d4d4d8;
  --border2:    #a1a1aa;
  --text:       #09090b;
  --text-muted: #71717a;
  --text-dim:   #52525b;
  --primary-bg: #09090b;
  --primary-fg: #fafafa;
  --qty-color:  #18181b;
  --success:    #16a34a;
  --danger:     #dc2626;
  --warn:       #d97706;
}
body.theme-light .modal { background: rgba(0,0,0,.4); }
body.theme-light .item-dropdown { box-shadow: 0 4px 16px rgba(0,0,0,.15); }
body.theme-light ::-webkit-scrollbar-thumb { background: var(--border); }

/* ── App container (mobile: full screen) ─────────────────────────────────── */
#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Modais e toasts ficam dentro do #app */
.modal { position: absolute; }

/* ── Desktop layout ──────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  :root { --item-grid: 200px 1fr 100px 80px; }

  /* Fundo com tom ligeiramente diferente para revelar o boxed */
  html, body {
    overflow: hidden;
    background: #050507;
    height: 100dvh;
  }
  body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }
  body.theme-light { background: #d4d4d8; }

  /* Container boxed: largura máxima, altura total, borda sutil */
  #app {
    width: 100%;
    max-width: 1440px;
    height: 100dvh;
    border-radius: 0;
    box-shadow:
      -1px 0 0 rgba(255,255,255,.06),
       1px 0 0 rgba(255,255,255,.06);
    flex-shrink: 0;
  }
  body.theme-light #app {
    box-shadow:
      -1px 0 0 rgba(0,0,0,.12),
       1px 0 0 rgba(0,0,0,.12);
  }

  .screen { height: 100dvh; }
  .modal           { position: absolute; }
  .toast-container { position: absolute; width: min(380px, 50%); }

  /* ── Count header ─────────────────────────────────────────────────────── */
  .count-header { padding: 0 16px; gap: 8px; }
  .count-title  { font-size: 15px; }

  /* ── Horizontal toolbar (scan + address side by side) ─────────────────── */
  .tools-block {
    flex-direction: row; align-items: stretch; gap: 0; padding: 0;
    height: 44px; flex-shrink: 0;
  }
  .scan-row    { flex: 1; border-bottom: none; padding: 5px 12px; }
  .address-row {
    width: 260px; flex-shrink: 0;
    border-left: 1px solid var(--border); padding: 5px 12px;
  }

  /* ── Items container ──────────────────────────────────────────────────── */
  .items-container { padding: 0; flex-direction: column; }

  /* Table header */
  .items-thead {
    display: grid;
    grid-template-columns: var(--item-grid);
    background: var(--bg3);
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
  }
  .items-thead span {
    padding: 5px 12px;
    font-size: 11px; font-weight: 700;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px;
    display: flex; align-items: center;
  }
  .items-thead span:nth-child(3) { justify-content: center; }

  /* Item list: no gap, table-style rows */
  .items-list { gap: 0; flex: 1; overflow-y: auto; }

  .item-row {
    display: grid;
    grid-template-columns: var(--item-grid);
    border-radius: 0;
    border-left: none; border-right: none; border-top: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    min-height: 36px;
    cursor: pointer;
  }
  .item-row:hover { background: var(--surface) !important; }
  .item-row.item-selected { background: var(--surface2) !important; }
  .item-row.item-editing {
    background: rgba(251,191,36,.04) !important;
    border-bottom-color: var(--warn);
  }
  .item-row.item-updated {
    background: rgba(74,222,128,.04) !important;
    border-bottom-color: var(--success);
  }
  .item-row.item-flash { border-bottom-color: var(--border2); }

  body.theme-light .item-row:hover { background: var(--surface2) !important; }

  /* Columns */
  .item-col-barcode {
    flex-direction: row; align-items: center; gap: 0;
    padding: 0 12px;
    border-right: 1px solid var(--border);
  }
  .item-addr-mobile { display: none; }
  .item-col-desc {
    display: flex; align-items: center;
    padding: 0 10px;
    border-right: 1px solid var(--border);
    overflow: hidden;
  }
  .item-col-qty {
    border-left: none;
    border-right: 1px solid var(--border);
    min-width: unset; justify-content: center; padding: 0;
  }
  .item-col-actions {
    border-left: none; justify-content: center; gap: 4px; padding: 0 6px;
  }
  .item-btn-edit, .item-btn-delete {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; background: none; border: none;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--text-muted);
    font-size: 15px; transition: background .15s, color .15s; flex-shrink: 0;
  }
  .item-btn-edit:hover   { background: var(--surface2); color: var(--text); }
  .item-btn-delete:hover { background: rgba(248,113,113,.1); color: var(--danger); }
  .item-menu-btn { display: none; }

  /* Select-count: center the card list */
  #screen-select-count .content { max-width: 560px; margin: 0 auto; padding: 28px 24px; }

  /* Câmera desabilitada no desktop (não há webcam para código de barras) */
  #btn-enable-camera:not(.hidden) {
    opacity: .3;
    pointer-events: none;
    cursor: not-allowed;
    filter: grayscale(1);
  }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }


/* ── Install tutorial modal ──────────────────────────────────────────────── */
.modal-install-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.5;
}
.modal-install-step i {
  font-size: 18px;
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 1px;
}
.modal-install-note {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

/* ── Install hint on login screen ───────────────────────────────────────── */
.btn-install-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-install-hint:hover {
  color: var(--text);
  border-color: var(--border2);
}

/* ── Error banner (counts list / server down) ────────────────────────────── */
.error-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 20px;
  text-align: center;
}
.error-banner-icon {
  font-size: 36px;
  color: var(--warn);
  opacity: .7;
}
.error-banner-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.error-banner-msg {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 280px;
  line-height: 1.5;
}
.error-banner-retry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.error-banner-retry:hover { background: var(--surface3); }

/* ── Loading text ────────────────────────────────────────────────────────── */
.loading-text {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 8px;
}

/* ── Login error message ─────────────────────────────────────────────────── */
.error-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.25);
  border-radius: var(--radius);
  color: var(--danger, #f87171);
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}
.error-msg.hidden { display: none; }

/* ── Spin animation (loading icon) ──────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

