:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0ea5e9;
  --primary-ink: #0369a1;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --dark: #0f172a;
}

* { box-sizing: border-box; }
/* Garante que o atributo [hidden] sempre esconda, mesmo em elementos com
   display definido por classe (.ios-install, .placa-list, .btn, etc.). */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1100px; margin: 0 auto; padding: 20px; }
.muted { color: var(--muted); }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* Topbar */
.topbar { background: var(--dark); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.menu { display: flex; align-items: center; gap: 16px; }
.menu a { color: #cbd5e1; }
.menu a:hover { color: #fff; text-decoration: none; }
.user-tag { color: #94a3b8; font-size: .85rem; }
.link-btn { background: none; border: none; color: #cbd5e1; cursor: pointer; font: inherit; }
.inline { display: inline; }
.hamburger { display: none; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; line-height: 1; }
.btn-install { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }
.btn-install:hover { background: #0284c7; }

/* Modal de instruções iOS */
.ios-install { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; }
.ios-card { background: #fff; width: 100%; border-radius: 16px 16px 0 0; padding: 20px 20px 28px; position: relative; }
.ios-card h3 { margin: 0 0 8px; }
.ios-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; font-size: 1.6rem; cursor: pointer; color: #64748b; }
.ios-share { display: inline-block; }
@media (min-width: 560px) { .ios-install { align-items: center; justify-content: center; } .ios-card { max-width: 420px; border-radius: 16px; } }

.site-footer { padding: 24px 0; color: var(--muted); }

/* Cabeçalho de página */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 1.5rem; }

/* Botões */
.btn { display: inline-block; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font: inherit; text-align: center; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #0284c7; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-lg { padding: 14px 18px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards / forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.form-narrow { max-width: 460px; }
label { display: block; margin-bottom: 12px; font-size: .9rem; color: #334155; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=file] {
  width: 100%; padding: 10px 12px; margin-top: 4px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff; }
input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

/* Alertas */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .92rem; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-done { background: #e2e8f0; color: #475569; }
.badge-on { background: #dcfce7; color: #166534; }
.badge-off { background: #fef3c7; color: #92400e; }
.badge-st-pendente { background: #f1f5f9; color: #475569; }
.badge-st-conferido { background: #dcfce7; color: #166534; }
.badge-st-divergente { background: #fee2e2; color: #991b1b; }

/* Tabelas */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { background: #f8fafc; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: #64748b; }
.table-compact th, .table-compact td { padding: 7px 10px; font-size: .9rem; }

/* Abas de filtro do painel */
.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.filtro-tab { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--card); font-size: .88rem; }
.filtro-tab:hover { background: #f1f5f9; text-decoration: none; }
.filtro-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filtro-n { font-weight: 700; background: rgba(15,23,42,.08); padding: 1px 9px; border-radius: 999px; font-size: .8rem; }
.filtro-tab.has-warn .filtro-n { background: #fef3c7; color: #92400e; }
.filtro-tab.has-danger .filtro-n { background: #fee2e2; color: #991b1b; }
.filtro-tab.has-ok .filtro-n { background: #dcfce7; color: #166534; }
.filtro-tab.active .filtro-n { background: rgba(255,255,255,.25); color: #fff; }
.pos-nenc { color: var(--danger); }
.pos-reloc { color: var(--warn); }
.badge-conflito { background: #fee2e2; color: #991b1b; font-weight: 700; }

/* Área admin */
.form-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-inline input, .form-inline select { width: auto; flex: 1; min-width: 140px; }
.row-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-form select, .row-form input { width: auto; min-width: 90px; }
.chk { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: .85rem; }
.chk input { width: auto; }

/* Resolução de conflitos */
.conflitos-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.conflito-card { background: var(--card); border: 1px solid #fecaca; border-left: 4px solid var(--danger);
  border-radius: 10px; padding: 12px 14px; }
.cc-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.cc-head code { font-size: 1rem; font-weight: 700; }
.cc-qtds { display: flex; gap: 18px; flex-wrap: wrap; font-size: .9rem; margin-bottom: 10px; }
.cc-1 strong { color: var(--primary-ink); }
.cc-2 strong { color: var(--warn); }
.cc-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cc-input { width: 120px; }
.row-conflito { background: #fef2f2 !important; }
.row-conflito td { border-top: 1px solid #fecaca; }

/* Tabela que cabe sem rolagem horizontal (desktop) */
@media (min-width: 761px) {
  .table-fit { table-layout: fixed; width: 100%; }
  .table-fit th, .table-fit td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: .78rem; padding: 6px 7px; }
  .table-fit code { font-size: .76rem; }
  .table-fit .badge { font-size: .62rem; padding: 2px 5px; }
  .table-fit th:nth-child(1), .table-fit td:nth-child(1) { width: 12%; }  /* Placa */
  .table-fit th:nth-child(2), .table-fit td:nth-child(2) { width: 6%; }   /* Item */
  .table-fit th:nth-child(3), .table-fit td:nth-child(3) { width: 21%; }  /* Descrição */
  .table-fit th:nth-child(4), .table-fit td:nth-child(4) { width: 15%; }  /* Lote */
  .table-fit th:nth-child(5), .table-fit td:nth-child(5) { width: 12%; }  /* Posição */
  .table-fit th:nth-child(6), .table-fit td:nth-child(6) { width: 8%; }   /* Esp. */
  .table-fit th:nth-child(7), .table-fit td:nth-child(7) { width: 8%; }   /* Conf. */
  .table-fit th:nth-child(8), .table-fit td:nth-child(8) { width: 6%; }   /* Dif. */
  .table-fit th:nth-child(9), .table-fit td:nth-child(9) { width: 12%; }  /* Status */
}
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.st-divergente td { background: #fef2f2; }
tr.st-conferido td { background: #f0fdf4; }

/* Progresso */
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; width: 140px; }
.progress-bar { height: 100%; background: var(--ok); }

/* Stats */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; min-width: 110px; }
.stat-num { display: block; font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-ok .stat-num { color: var(--ok); }
.stat-warn .stat-num { color: var(--danger); }
.inv-actions { display: flex; gap: 10px; margin-bottom: 24px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--dark); }
.login-card { background: #fff; padding: 32px; border-radius: 16px; width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 20px; font-size: 1.3rem; text-align: center; }
.sso-sep { display: flex; align-items: center; text-align: center; color: var(--muted); margin: 16px 0; font-size: .85rem; }
.sso-sep::before, .sso-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.sso-sep span { padding: 0 12px; }
.btn-ms { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff;
  border: 1px solid #8c8c8c; color: #5e5e5e; font-weight: 600; }
.btn-ms:hover { background: #f3f3f3; text-decoration: none; }
.ms-logo { width: 18px; height: 18px; flex: none;
  background:
    linear-gradient(#f25022 0 0) 0 0 / 8px 8px no-repeat,
    linear-gradient(#7fba00 0 0) 10px 0 / 8px 8px no-repeat,
    linear-gradient(#00a4ef 0 0) 0 10px / 8px 8px no-repeat,
    linear-gradient(#ffb900 0 0) 10px 10px / 8px 8px no-repeat; }

/* ================= SCANNER (PWA) ================= */
.scan-body { background: #0b1220; color: #e2e8f0; min-height: 100vh; margin: 0;
  display: flex; flex-direction: column; }
.scan-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: #0f172a; position: sticky; top: 0; z-index: 5; }
.scan-back { color: #e2e8f0; font-size: 1.8rem; line-height: 1; width: 28px; }
.scan-back:hover { text-decoration: none; }
.scan-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-flags { display: flex; gap: 8px; align-items: center; }
.flag { font-size: .72rem; padding: 3px 8px; border-radius: 999px; background: #334155; }
.flag-on { background: #14532d; color: #bbf7d0; }
.flag-off { background: #7c2d12; color: #fed7aa; }
.flag-queue { background: #1e293b; }
.flag-queue.has-items { background: #b45309; color: #fff; }

.scan-progress { padding: 8px 14px; font-size: .85rem; color: #94a3b8; background: #0d1526; }

/* Scanner compacto — dá mais espaço aos resultados */
.scanner { position: relative; width: 100%; aspect-ratio: 16/9; max-height: 30vh; background: #000; overflow: hidden; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame { position: absolute; inset: 12% 22%; border: 3px solid rgba(56,189,248,.9);
  border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.btn-cam { display: block; width: calc(100% - 28px); margin: 10px 14px 0; background: #1e293b;
  color: #e2e8f0; border-color: #334155; }
.scan-close-cam { position: absolute; right: 10px; top: 10px; background: rgba(15,23,42,.8);
  color: #e2e8f0; border-color: #334155; }

/* Passos (posição / placa) */
.step-box { padding: 12px 14px; }
.step-hint { color: #cbd5e1; font-size: 1.02rem; margin: 4px 2px 10px; }
.step-n { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center;
  background: #0ea5e9; color: #fff; border-radius: 50%; font-weight: 700; font-size: .85rem; margin-right: 8px; }
.pos-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 6px; }
.btn-finalizar { margin-top: 12px; background: #16a34a; border-color: #16a34a; color: #fff; font-size: 1rem; padding: 12px; }
.btn-finalizar:hover { background: #15803d; }

.manual-entry { display: flex; gap: 8px; padding: 6px 0 12px; }
.manual-entry input { flex: 1; background: #0f172a; color: #e2e8f0; border-color: #334155;
  font-size: 1.15rem; padding: 12px 14px; }
.manual-entry .btn { padding: 12px 18px; font-size: 1rem; }

/* Card do palete */
.palete-card { background: #0f172a; border-top: 2px solid #1e293b; padding: 16px 14px 24px;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain; }
.pc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.pc-id { font-size: 1.25rem; font-weight: 700; font-family: ui-monospace, monospace;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-close { margin-left: auto; background: none; border: 0; color: #94a3b8; font-size: 1.7rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.pc-close:hover { color: #e2e8f0; }
.pc-body { margin-bottom: 16px; }
.pc-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid #1e293b; }
.pc-row span { color: #94a3b8; }
.pc-row strong { text-align: right; }
.pc-actions { display: flex; gap: 10px; }
.pc-actions .btn { flex: 1; }
.pc-actions-col { flex-direction: column; }
.pc-hint { margin: 2px 0 12px; font-size: .85rem; text-align: center; color: #94a3b8; }
.pc-hint.ok { color: #4ade80; }
.pc-hint.warn { color: #fbbf24; }
.btn-disabled, .btn:disabled { opacity: .45; cursor: not-allowed; filter: saturate(.4); }
.pc-qtd { margin-top: 12px; }
.pc-qtd input { background: #0b1220; color: #e2e8f0; border-color: #334155; font-size: 1.4rem; text-align: center; }
.palete-card .fld { display: block; margin-bottom: 12px; color: #94a3b8; font-size: .9rem; }
.palete-card .fld input { display: block; width: 100%; margin-top: 5px; background: #0b1220;
  color: #e2e8f0; border-color: #334155; font-size: 1.1rem; padding: 10px 12px; }
.sku-status { display: block; margin-top: 5px; font-size: .82rem; min-height: 1em; overflow-wrap: anywhere; }
.sku-status.sku-ok { color: #4ade80; }
.sku-status.sku-warn { color: #fbbf24; }
.pc-diff { margin: 10px 0; font-weight: 600; text-align: center; }
.pc-diff.ok { color: #4ade80; }
.pc-diff.warn { color: #fbbf24; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 30;
  font-size: .9rem; max-width: 90%; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast-ok { background: #14532d; }
.toast-err { background: #7f1d1d; }
.toast-info { background: #1e293b; }

.scan-foot { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: #0f172a; }
.scan-foot .muted { color: #64748b; font-size: .82rem; }
.scan-foot .btn { background: #1e293b; color: #e2e8f0; border-color: #334155; }

/* Lista de linhas de uma placa (placa mista) */
.placa-list { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; max-height: 72vh;
  display: flex; flex-direction: column; background: #0f172a; border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,.5); border-top: 2px solid #1e293b; }
.pl-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; }
.pl-label { color: #94a3b8; font-size: .75rem; text-transform: uppercase; margin-right: 6px; }
.pl-placa { font-family: ui-monospace, monospace; font-size: 1.2rem; font-weight: 700; }
.pl-progress { padding: 0 2px 10px; color: #94a3b8; font-size: .92rem; }
.pl-filtro { margin: 0 14px 10px; background: #0b1220; color: #e2e8f0; border-color: #334155; width: auto; }
.pl-rows { overflow-y: auto; }
#posRows { max-height: 46vh; }
.pl-row { display: block; width: 100%; text-align: left; background: #0b1220; border: 1px solid #1e293b;
  border-radius: 12px; padding: 14px; margin-bottom: 10px; color: #e2e8f0; cursor: pointer; }
.pl-row:hover { background: #111c33; }
.pl-row.st-conferido { border-color: #14532d; background: #0c1c14; }
.pl-row.st-parcial { border-color: #b45309; }
.pl-row.st-divergente { border-color: #7f1d1d; }
.pl-row-main { display: flex; gap: 8px; align-items: baseline; }
.pl-item { font-weight: 700; font-family: ui-monospace, monospace; font-size: 1.1rem; }
.pl-desc { color: #cbd5e1; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-row-sub { display: flex; gap: 14px; color: #94a3b8; font-size: .85rem; margin-top: 6px; }
.pl-tag { background: #7c2d12; color: #fed7aa; font-size: .68rem; padding: 2px 7px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.pl-mark { margin-left: auto; color: #4ade80; font-weight: 700; font-size: 1.05rem; }
.pl-empty { color: #94a3b8; padding: 14px; text-align: center; }

/* ===== Responsivo (mobile) ===== */
@media (max-width: 760px) {
  .container { padding: 14px; }

  /* Topbar com menu hambúrguer */
  .topbar-inner { flex-wrap: wrap; position: relative; }
  .hamburger { display: block; }
  .menu { display: none; flex-direction: column; align-items: flex-start; gap: 10px;
    width: 100%; padding: 12px 0 4px; }
  .menu.open { display: flex; }
  .menu a, .menu .user-tag, .menu form, .menu .btn { width: 100%; }
  .menu .btn-install { text-align: center; }
  .user-tag { order: 3; }

  /* Cabeçalho de página empilha */
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn, .page-head .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; }

  /* Ações e formulários ocupam a largura */
  .inv-actions { flex-wrap: wrap; }
  .inv-actions .inline, .inv-actions .btn { flex: 1; }
  .form-narrow { max-width: 100%; }

  /* Botões e campos com alvo de toque maior */
  .btn { padding: 11px 14px; }
  input[type=text], input[type=email], input[type=password], input[type=number], input[type=file] { font-size: 16px; }

  /* Stats em grade de 2 colunas */
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { min-width: 0; }

  /* Tabelas roláveis lateralmente */
  .table th, .table td { white-space: nowrap; }

  /* Cards e formulários compactos */
  .card { padding: 14px; }
  .login-card { padding: 24px 20px; }

  /* Form "novo usuário" empilha */
  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline input, .form-inline select, .form-inline .btn { width: 100%; flex: none; min-width: 0; }

  /* Resolução de conflito: controles ocupam a largura */
  .cc-form { flex-direction: column; align-items: stretch; }
  .cc-form .btn, .cc-input { width: 100%; }
  .cc-qtds { gap: 10px 18px; }

  /* Abas de filtro cabem melhor */
  .filtro-tab { font-size: .82rem; padding: 6px 10px; }

  /* Card do scanner nunca corta (rola internamente) */
  .palete-card { max-height: 85vh; }

  .site-footer { padding: 16px 0; text-align: center; }
}

@media (max-width: 400px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .brand { font-size: 1rem; }
}
