/* ===========================================================
   SAVIX — Gerador de QR Code
   Design tokens extraídos da marca oficial Savix
=========================================================== */

:root{
  /* Cores da marca (extraídas da logo) */
  --ink: #01152D;          /* fundo — igual ao fundo da logo */
  --panel: #0A2140;        /* cartões e superfícies elevadas */
  --panel-2: #0E2A4E;      /* superfícies um nível acima */
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);

  --blue-light: #8FC2F2;
  --blue-deep: #0A8FFE;
  --green-light: #7BDB4C;
  --green-deep: #1FA33C;

  --white: #FFFFFF;
  /* Clareados para passar no mínimo de 4,5:1 da WCAG sobre o painel
     escuro — o tom anterior (#5F7796) ficava em ~3,4:1 justamente nos
     rótulos que mais precisam ser lidos. */
  --muted: #A8BDD6;
  --muted-2: #8DA6C2;

  --grad-brand: linear-gradient(115deg, var(--blue-deep) 0%, var(--blue-light) 35%, var(--green-light) 65%, var(--green-deep) 100%);
  --grad-brand-soft: linear-gradient(115deg, rgba(10,143,254,.18) 0%, rgba(143,194,242,.14) 35%, rgba(123,219,76,.14) 65%, rgba(31,163,60,.18) 100%);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.55);
  --shadow-md: 0 12px 30px -14px rgba(0,0,0,0.5);

  --font-display: 'Poppins', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }

body{
  background: var(--ink);
  background-image:
    radial-gradient(900px 500px at 85% -10%, rgba(10,143,254,.10), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, rgba(31,163,60,.10), transparent 60%);
  color: var(--white);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a{ color: inherit; }

.container{
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ---------------- Header ---------------- */
.site-header{
  padding: 26px 0 10px;
}
.header-row{
  display:flex;
  align-items:center;
  justify-content: space-between;
}
.brand{
  display:flex;
  align-items:center;
  gap:12px;
}
.brand img{
  height: 34px;
  display:block;
}
.brand-name{
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: -0.01em;
  color: var(--white);
}
.header-tag{
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 100px;
  background: rgba(255,255,255,0.02);
  white-space: nowrap;
}
.header-tag strong{ color: var(--white); font-weight:600; }

.header-actions{
  display:flex;
  align-items:center;
  gap: 12px;
}
.btn-header{
  width:auto;
  padding: 9px 16px;
  font-size: 13px;
  display:inline-flex;
  align-items:center;
  gap: 8px;
}
.count-pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 100px;
  background: var(--grad-brand);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
}
@media (max-width: 640px){
  .header-tag{ display:none; }
}

/* ---------------- Hero copy ---------------- */
.hero-intro{
  padding: 40px 0 8px;
  max-width: 640px;
}
.eyebrow{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--blue-light);
  margin-bottom: 16px;
}
.eyebrow::before{
  content:"";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--grad-brand);
}
.hero-intro h1{
  font-family: var(--font-display);
  font-size: 40px;
  line-height: 1.15;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.hero-intro p{
  font-size: 16px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}

/* ---------------- Main grid ---------------- */
.workspace{
  display:grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  padding: 34px 0 80px;
  align-items: start;
}
@media (max-width: 900px){
  .workspace{ grid-template-columns: 1fr; }
}

.card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* ---------------- Tabs ---------------- */
.type-tabs{
  display:flex;
  gap: 4px;
  padding: 6px;
  margin: 0;
  background: rgba(0,0,0,0.18);
  border-radius: 100px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.type-tabs button{
  appearance:none;
  border:none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 100px;
  cursor:pointer;
  white-space: nowrap;
  transition: color .18s ease, background .18s ease;
}
.type-tabs button:hover{ color: var(--white); }
.type-tabs button.active{
  color: var(--ink);
  background: var(--grad-brand);
}

/* ---------------- Form panel ---------------- */
.panel-body{
  padding: 26px 26px 28px;
}
.panel-head{
  padding: 26px 26px 0;
}
.panel-head h2{
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 4px;
}
.panel-head p{
  font-size: 13.5px;
  color: var(--muted-2);
  margin: 0 0 20px;
}

.link-mode-toggle{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 520px){ .link-mode-toggle{ grid-template-columns: 1fr; } }
.link-mode-btn{
  text-align:left;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  cursor:pointer;
  transition: border-color .15s ease, background .15s ease;
  display:flex;
  flex-direction:column;
  gap: 4px;
}
.link-mode-btn:hover{ background: rgba(255,255,255,0.05); }
.link-mode-btn.active{
  border-color: var(--blue-deep);
  background: var(--grad-brand-soft);
}
.link-mode-btn .lm-title{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--white);
}
.link-mode-btn .lm-desc{
  font-size: 12px;
  color: var(--muted-2);
  line-height: 1.4;
}

.notice-box{
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue-deep);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 4px;
}
.notice-box strong{ color: var(--white); }
.notice-box .notice-flag{
  display:block;
  margin-top: 8px;
  color: #ffcf8a;
  font-size: 12px;
}

.field-group{ margin-bottom: 16px; }
.field-row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}
/* Numa linha de dois campos, um rótulo que quebra em duas linhas empurrava
   só o campo dele para baixo. Reservando duas linhas, os dois campos ficam
   sempre na mesma altura. */
.field-row > .field-group > label{
  min-height: 2.4em;
  display: flex;
  align-items: flex-start;
}
@media (max-width: 520px){
  .field-row{ grid-template-columns: 1fr; }
  .field-row > .field-group > label{ min-height: 0; }
}

label{
  display:block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}
label .opt{
  font-weight: 400;
  color: var(--muted-2);
  text-transform: none;
}

/* Lista por exclusão em vez de por tipo: antes date, password e search
   ficavam de fora e apareciam com a aparência nativa do navegador —
   fundo branco e altura diferente no meio dos campos escuros. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
textarea,
select{
  width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-strong);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s ease, background .15s ease;
  /* Altura idêntica em todos os tipos: o controle de data tem métrica
     própria e ficava 3px mais alto que o campo ao lado, desalinhando
     as linhas de dois campos. */
  min-height: 45px;
}
input::placeholder, textarea::placeholder{ color: var(--muted-2); }
input:focus, textarea:focus, select:focus{
  border-color: var(--blue-deep);
  background: rgba(255,255,255,0.045);
}
textarea{ resize: vertical; min-height: 84px; font-family: var(--font-mono); font-size: 13px; }

/* Campos de data: sem isto o navegador desenha o seletor de calendário
   em tema claro, invisível sobre o fundo escuro. */
input[type="date"]{
  color-scheme: dark;
  font-family: var(--font-body);
}
input[type="date"]::-webkit-calendar-picker-indicator{
  cursor: pointer;
  opacity: .75;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover{ opacity: 1; }

input[type="search"]{ -webkit-appearance: none; appearance: none; }
input[type="search"]::-webkit-search-cancel-button{
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px; cursor: pointer;
  background: var(--muted-2);
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M1 1l10 10M11 1L1 11' stroke='black' stroke-width='2'/></svg>") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M1 1l10 10M11 1L1 11' stroke='black' stroke-width='2'/></svg>") center/contain no-repeat;
}

/* O número da folha de impressão e afins: sem as setinhas claras. */
input[type="number"]{ color-scheme: dark; }

select{ appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2390A7C7'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

.checkbox-row{
  display:flex;
  align-items:center;
  gap:9px;
  font-size: 13.5px;
  color: var(--muted);
  margin-top: -4px;
  margin-bottom: 16px;
  cursor: pointer;
}
.checkbox-row input{ width:16px; height:16px; accent-color: var(--blue-deep); }

.hint{
  font-size: 12px;
  color: var(--muted-2);
  margin-top: 6px;
}

.error-text{
  font-size: 12px;
  color: #ff9b8a;
  margin-top: 6px;
  display:none;
}
.field-group.has-error input,
.field-group.has-error select{ border-color: #e2604a; }
.field-group.has-error .error-text{ display:block; }

.logo-upload-row{
  display:flex;
  align-items:center;
  gap: 14px;
}
.logo-preview{
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.03);
  border: 1px dashed var(--border-strong);
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
  flex-shrink:0;
}
.logo-preview img{ width:100%; height:100%; object-fit:contain; }
.logo-preview span{ font-size: 10px; color: var(--muted-2); text-align:center; padding:4px; }
.logo-upload-actions{ display:flex; gap:8px; align-items:center; }
.logo-upload-btn{ width:auto; padding: 10px 14px; font-size: 13px; cursor:pointer; }
#btn-remove-logo{ width:auto; padding: 10px 14px; font-size: 13px; }

.divider-note{
  display:flex;
  align-items:center;
  gap:10px;
  font-size: 12px;
  color: var(--muted-2);
  margin: 4px 0 18px;
}
.divider-note::before, .divider-note::after{
  content:"";
  height:1px; flex:1;
  background: var(--border);
}

/* ---------------- Buttons ---------------- */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
  width: 100%;
}
.btn[hidden]{ display:none; }
.btn:active{ transform: translateY(1px); }
.btn-primary{
  background: var(--grad-brand);
  color: var(--ink);
}
.btn-primary:hover{ filter: brightness(1.06); }
.btn-secondary{
  background: rgba(255,255,255,0.04);
  border-color: var(--border-strong);
  color: var(--white);
}
.btn-secondary:hover{ background: rgba(255,255,255,0.08); }
.btn[disabled]{ opacity:.45; cursor:not-allowed; }

.action-row{
  display:flex;
  gap: 10px;
  margin-top: 6px;
}

/* ---------------- Preview panel ---------------- */
.preview-col{ position: sticky; top: 26px; }

.preview-card{
  position: relative;
  padding: 30px 26px 26px;
  overflow: hidden;
  isolation: isolate;
}

.logo-watermark{
  position:absolute;
  z-index: 0;
  width: 420px;
  max-width: none;
  right: -110px;
  top: -70px;
  opacity: .16;
  transform: rotate(-6deg);
  pointer-events:none;
  user-select:none;
}

.preview-head{
  position:relative; z-index:1;
  display:flex;
  align-items:center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.preview-head h3{
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin:0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.preview-badge{
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 100px;
  background: var(--grad-brand-soft);
  border: 1px solid var(--border-strong);
  color: var(--white);
}

.qr-stage{
  position: relative; z-index:1;
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 22px;
  display:flex;
  align-items:center;
  justify-content:center;
  min-height: 260px;
  box-shadow: var(--shadow-lg);
}
.qr-stage.is-label{
  padding: 14px;
  min-height: auto;
}

.qr-stage.empty{
  background: rgba(255,255,255,0.03);
  border: 1px dashed var(--border-strong);
  box-shadow: none;
}
.qr-stage.empty .empty-state{
  text-align:center;
  color: var(--muted-2);
  font-size: 13px;
  max-width: 220px;
}
.qr-stage #qr-render{ line-height: 0; }
.qr-stage #qr-render img, .qr-stage #qr-render canvas{
  display:block;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto !important;
  width: 100% !important;
}

.btn-save{
  position: relative; z-index:1;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--muted);
  margin-top: 10px;
  font-size: 13px;
  padding: 10px 14px;
}
.btn-save:hover{ color: var(--white); border-color: var(--blue-deep); }
.btn-save[disabled]{ opacity: .4; cursor:not-allowed; }

.bulk-print-row{
  position: relative; z-index:1;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.bulk-print-label{
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 10px;
}
.bulk-print-controls{
  display:flex;
  gap: 10px;
}
.bulk-print-controls input[type=number]{
  width: 76px;
  flex: none;
  text-align:center;
}
.bulk-print-controls .btn{
  width:auto;
  padding: 10px 16px;
  font-size: 13px;
  flex: 1;
}

.preview-meta{
  position: relative; z-index:1;
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted-2);
  text-align:center;
}

.payload-box{
  position: relative; z-index:1;
  margin-top: 16px;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--blue-light);
  word-break: break-all;
  max-height: 90px;
  overflow-y: auto;
  display:none;
}

.preview-actions{
  position: relative; z-index:1;
  display:flex;
  gap: 10px;
  margin-top: 18px;
}
.preview-actions .btn{ font-size: 13.5px; padding: 11px 16px; }

/* ---------------- Footer ---------------- */
.site-footer{
  border-top: 1px solid var(--border);
  padding: 26px 0 40px;
}
.footer-row{
  display:flex;
  align-items:center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.footer-brand{
  display:flex;
  align-items:center;
  gap:10px;
  color: var(--muted-2);
  font-size: 13px;
}
.footer-brand img{ height: 20px; opacity:.8; }
.footer-tag{
  font-size: 12.5px;
  color: var(--muted-2);
}

.auth-area{ display:flex; align-items:center; }

.user-chip{
  display:flex;
  align-items:center;
  gap: 9px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  padding: 6px 8px 6px 6px;
}
.user-avatar{
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--grad-brand);
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.user-email{
  font-size: 12.5px;
  color: var(--muted);
  max-width: 140px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip .btn-header{ padding: 6px 12px; font-size: 12px; }
.mock-flag{
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #ffcf8a;
  background: rgba(255,207,138,0.12);
  border: 1px solid rgba(255,207,138,0.3);
  padding: 2px 7px;
  border-radius: 100px;
}

/* ---------------- Auth modal ---------------- */
.auth-overlay{
  position: fixed;
  inset: 0;
  background: rgba(1,10,22,0.68);
  backdrop-filter: blur(4px);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index: 70;
  opacity: 0;
  pointer-events:none;
  transition: opacity .2s ease;
  padding: 20px;
}
.auth-overlay.show{ opacity: 1; pointer-events:auto; }

.auth-modal{
  position: relative;
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 26px 26px;
  transform: translateY(10px);
  transition: transform .22s ease;
}
.auth-overlay.show .auth-modal{ transform: translateY(0); }

.auth-logo{ height: 30px; display:block; margin: 0 auto 18px; }

.auth-close{
  position: absolute;
  top: 16px; right: 16px;
}

.auth-tabs{
  display:flex;
  gap: 4px;
  padding: 5px;
  background: rgba(0,0,0,0.18);
  border-radius: 100px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
}
.auth-tab{
  flex:1;
  appearance:none; border:none; background:transparent;
  color: var(--muted);
  font-weight: 600; font-size: 13px;
  padding: 9px 10px;
  border-radius: 100px;
  cursor:pointer;
  transition: color .15s ease, background .15s ease;
}
.auth-tab.active{ color: var(--ink); background: var(--grad-brand); }

.auth-error{
  font-size: 12.5px;
  color: #ff9b8a;
  background: rgba(226,96,74,0.1);
  border: 1px solid rgba(226,96,74,0.3);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin: -4px 0 14px;
}

.btn-google{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 10px;
  background: #FFFFFF;
  color: #1F1F1F;
  border: 1px solid var(--border-strong);
  font-size: 14px;
  font-weight: 600;
}
.btn-google:hover{ filter: brightness(0.97); }

.auth-switch{
  text-align:center;
  font-size: 12.5px;
  color: var(--muted-2);
  margin: 18px 0 0;
}
.auth-switch button{
  background:none; border:none;
  color: var(--blue-light);
  font-weight: 600;
  font-size: 12.5px;
  cursor:pointer;
  padding: 0;
}

/* ---------------- Clientes / permissões ---------------- */
.client-form-card{
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
  background: rgba(255,255,255,0.02);
}
.perm-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.perm-chip{
  display:flex; align-items:center; gap:8px;
  font-size: 13px; color: var(--muted);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor:pointer;
}
.perm-chip input{ accent-color: var(--blue-deep); width:15px; height:15px; }
.perm-chip:has(input:checked){
  border-color: var(--blue-deep);
  background: var(--grad-brand-soft);
  color: var(--white);
}

.cliente-item{
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.02);
}
.cliente-item.blocked{ opacity: .55; }
.cliente-top{
  display:flex; justify-content:space-between; align-items:flex-start; gap:10px; margin-bottom:8px;
}
.cliente-nome{ font-weight:700; font-size:14px; color:var(--white); }
.cliente-email{ font-size:12px; color:var(--muted-2); }
.cliente-badges{ display:flex; flex-wrap:wrap; gap:6px; margin: 8px 0; }
.perm-badge{
  font-size: 10.5px; font-weight:700; text-transform:uppercase; letter-spacing:.03em;
  padding: 3px 9px; border-radius:100px;
  background: var(--grad-brand-soft); border:1px solid var(--border-strong); color:var(--white);
}
.cliente-actions{ display:flex; gap:8px; margin-top:10px; }
.cliente-actions .btn{ width:auto; padding:7px 12px; font-size:12px; }
.status-toggle{
  font-size:11px; font-weight:700; padding:4px 10px; border-radius:100px; cursor:pointer; border:none;
}
.status-toggle.ativo{ background: rgba(123,219,76,0.16); color:#7BDB4C; }
.status-toggle.bloqueado{ background: rgba(226,96,74,0.16); color:#e2604a; }

.history-toolbar{
  display:flex; gap:8px;
  padding: 0 22px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
/* O campo de busca virou type="search": o seletor antigo era por
   type=text e deixava a barra inteira sem alinhamento. */
.history-toolbar input{
  flex:1; min-width:0; font-size:13px; padding:9px 12px;
}
.history-toolbar select{
  font-size:12.5px; padding:9px 10px; width:auto;
}
.history-toolbar #btn-export-csv{
  width:auto; padding:9px 14px; font-size:12.5px;
}

/* ---------------- History panel ---------------- */
.history-overlay{
  position: fixed;
  inset: 0;
  background: rgba(1,10,22,0.6);
  backdrop-filter: blur(3px);
  display:flex;
  justify-content: flex-end;
  z-index: 60;
  opacity: 0;
  pointer-events:none;
  transition: opacity .2s ease;
}
.history-overlay.show{ opacity: 1; pointer-events:auto; }

.history-panel{
  width: 460px;
  max-width: 100%;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  display:flex;
  flex-direction: column;
  transform: translateX(24px);
  transition: transform .22s ease;
}
.history-overlay.show .history-panel{ transform: translateX(0); }

.history-head{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--border);
}
.history-head h2{
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 6px;
}
.history-head p{
  font-size: 12.5px;
  color: var(--muted-2);
  margin: 0;
  line-height: 1.5;
}
.btn-close{
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-strong);
  color: var(--white);
  width: 30px; height: 30px;
  border-radius: 100px;
  cursor:pointer;
  flex-shrink: 0;
  font-size: 13px;
}
.btn-close:hover{ background: rgba(255,255,255,0.1); }

.history-list{
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px 22px;
}
.history-empty{
  display:none;
  text-align:center;
  padding: 60px 30px;
  color: var(--muted-2);
}
.history-empty p{ color: var(--muted); font-weight:600; margin: 0 0 6px; }
.history-empty span{ font-size: 13px; }

.history-item{
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.02);
}
.hi-top{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.hi-badges{ display:flex; gap:6px; align-items:center; }
.hi-type-badge{
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 4px 9px;
  border-radius: 100px;
  background: var(--grad-brand-soft);
  border: 1px solid var(--border-strong);
  color: var(--white);
}
.hi-mode-badge{
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 100px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.hi-date{ font-size: 11px; color: var(--muted-2); }
.hi-delete{
  background: none; border:none; color: var(--muted-2);
  cursor:pointer; font-size: 15px; line-height:1; padding: 4px;
}
.hi-delete:hover{ color: #e2604a; }

.hi-body{ display:flex; gap: 12px; align-items:flex-start; }
.hi-qr{
  width: 68px; height: 68px;
  background: #fff;
  border-radius: 8px;
  flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
}
.hi-qr canvas, .hi-qr img{ width: 100% !important; height: 100% !important; }
.hi-qr.hi-qr-label{ width: 104px; background:#fff; }
.hi-qr.hi-qr-label canvas{ object-fit: contain; }
.hi-info{ flex:1; min-width:0; }
.hi-label{
  font-size: 12.5px;
  color: var(--white);
  word-break: break-word;
  margin-bottom: 8px;
}
.hi-dest-row{ display:flex; gap: 8px; }
.hi-dest-row input{
  flex:1;
  font-size: 12.5px;
  padding: 8px 10px;
}
.hi-dest-row .btn{
  width:auto;
  padding: 8px 12px;
  font-size: 12px;
}
.hi-actions{ display:flex; gap: 8px; margin-top: 10px; }
.hi-actions .btn{ width:auto; padding: 7px 12px; font-size: 12px; }

.account-blocked{
  position: fixed; inset:0; z-index: 55;
  background: rgba(1,10,22,0.92);
  display:flex; align-items:center; justify-content:center;
  padding: 24px;
}
.account-blocked-card{
  text-align:center; max-width: 360px;
}
.account-blocked-icon{ font-size: 40px; margin-bottom: 14px; }
.account-blocked-card h2{ font-family: var(--font-display); font-size:19px; margin:0 0 10px; }
.account-blocked-card p{ font-size: 13.5px; color: var(--muted); line-height:1.6; margin:0; }

.toast{
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  color: var(--white);
  font-size: 13.5px;
  font-weight: 500;
  padding: 12px 20px;
  border-radius: 100px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  /* Acima da tela de bloqueio (55) e dos painéis (60/70): as mensagens
     precisam aparecer justamente quando algo trava. */
  z-index: 90;
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast .dot{
  display:inline-block;
  width:7px; height:7px;
  border-radius:50%;
  background: var(--grad-brand);
  margin-right: 9px;
}

@media (max-width: 560px){
  .hero-intro h1{ font-size: 30px; }
  .panel-body, .panel-head{ padding-left: 18px; padding-right: 18px; }
  .preview-card{ padding: 22px 18px; }
}

/* ===========================================================
   Adições da migração para Firebase
   (papéis de usuário, etapas extras, código de confirmação,
   métricas do admin, acessibilidade)
=========================================================== */

/* --- acessibilidade --- */
.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;
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible{
  outline: 2px solid var(--blue-light);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- papel do usuário no cabeçalho --- */
.role-flag{
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 3px 8px; border-radius: 100px;
  white-space: nowrap;
}
.role-admin{ background: rgba(123,219,76,.16); color: #9BE87A; border: 1px solid rgba(123,219,76,.34); }
.role-cliente{ background: rgba(10,143,254,.16); color: #A9D3F8; border: 1px solid rgba(10,143,254,.34); }
.role-none{ background: rgba(255,150,120,.14); color: #FFB1A0; border: 1px solid rgba(255,150,120,.32); }
.role-loading{ background: rgba(255,255,255,.07); color: var(--muted); border: 1px solid var(--border-strong); }

/* --- etapas extras da cadeia --- */
.etapa-extra{
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 16px 4px;
  margin-bottom: 12px;
  background: rgba(255,255,255,.02);
}
.etapa-extra-head{
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.etapa-extra-num{
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.btn.btn-mini{ width: auto; padding: 5px 11px; font-size: 11.5px; }
#btn-add-etapa{ margin-bottom: 6px; }

/* --- cor do QR no perfil ---
   O seletor nativo do navegador é feio por padrão em todo lugar: sem
   borda combinando e com altura própria. Estes ajustes só o encaixam
   no resto do formulário. */
.cor-input{
  width: 100%; height: 46px; padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.cor-input::-webkit-color-swatch-wrapper{ padding: 0; }
.cor-input::-webkit-color-swatch{ border: none; border-radius: 5px; }
.cor-input::-moz-color-swatch{ border: none; border-radius: 5px; }

#pf-contraste{ margin-top: 12px; }
#pf-contraste p{ margin: 6px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
#pf-contraste.contraste-aviso{
  border-color: rgba(240,180,41,0.45);
  background: rgba(240,180,41,0.10);
}
#pf-contraste.contraste-ruim{
  border-color: rgba(226,96,74,0.5);
  background: rgba(226,96,74,0.12);
}

/* --- plano do mês (limite de etiquetas) ---
   Três estados: informativo (o padrão do notice-box), perto do fim e
   estourado. As cores repetem as que a lista de acessos já usa para
   "Bloqueado", para a pessoa reconhecer o sinal em vez de aprender
   outro. */
.plano-mes-box{ margin-top: 14px; }
.plano-mes-box p{ margin: 6px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.plano-mes-box.plano-aviso{
  border-color: rgba(240,180,41,0.45);
  background: rgba(240,180,41,0.10);
}
.plano-mes-box.plano-estourado{
  border-color: rgba(226,96,74,0.5);
  background: rgba(226,96,74,0.12);
}
.plano-badge{
  background: rgba(143,194,242,0.14);
  color: var(--blue-light);
}

/* --- código de confirmação --- */
.confirm-code-box{ margin-top: 14px; }
.confirm-code-box p{ margin: 8px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.cc-code{
  font-family: var(--font-mono); font-size: 19px; letter-spacing: .18em;
  color: var(--green-light); margin-left: 4px;
}
.hi-confirm{
  font-size: 12px; color: var(--muted); margin: 4px 0 8px;
}
.hi-confirm code{
  font-family: var(--font-mono); color: var(--green-light);
  letter-spacing: .12em; font-size: 12.5px;
}

/* --- métricas do admin --- */
.metrics-grid{
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.metric{
  background: var(--panel-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: 13px 15px;
  display: flex; flex-direction: column; gap: 5px;
}
.metric-wide{ grid-column: 1 / -1; }
.m-k{
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted-2);
}
.m-v{
  font-family: var(--font-display); font-size: 26px; font-weight: 700;
  line-height: 1; font-variant-numeric: tabular-nums;
}
.m-text{ font-size: 15px; line-height: 1.3; }

/* --- diversos --- */
.history-loading{
  padding: 22px 26px; font-size: 13px; color: var(--muted);
}
.perm-label{
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin-bottom: 8px;
}
.link-button{
  background: none; border: none; padding: 8px 0 0;
  color: var(--blue-light); font-family: var(--font-body);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  width: 100%; text-align: center;
}
.link-button:hover{ text-decoration: underline; }
.link-button[hidden]{ display: none; }
.auth-info{
  background: rgba(123,219,76,.10); border: 1px solid rgba(123,219,76,.28);
  color: #C6F3AC; font-size: 12.5px; line-height: 1.55;
  padding: 10px 13px; border-radius: var(--radius-sm); margin: 12px 0 0;
}
.hint-ok{ color: var(--green-light); }

/* ===========================================================
   Painel de acessos — abas internas
=========================================================== */
.panel-tabs{
  display: flex;
  gap: 4px;
  padding: 0 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-tab{
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.panel-tab:hover{ color: var(--white); background: rgba(255,255,255,.04); }
.panel-tab.active{
  color: var(--ink);
  background: var(--grad-brand);
}
.panel-tab.active .count-pill{
  background: rgba(1,21,45,.22);
  color: var(--ink);
}

/* Badge de papel na lista de acessos */
.papel-badge{
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 3px 9px; border-radius: 100px;
  white-space: nowrap;
}
.papel-admin{
  background: rgba(123,219,76,.16); color: #9BE87A;
  border: 1px solid rgba(123,219,76,.34);
}
.papel-cliente{
  background: rgba(10,143,254,.16); color: #A9D3F8;
  border: 1px solid rgba(10,143,254,.34);
}
.cliente-item.eu{ border-color: var(--blue-deep); }
.cliente-voce{
  font-size: 11.5px; color: var(--muted-2); margin-top: 6px;
}

/* O painel lateral precisa de mais largura para os dois campos por linha
   caberem sem espremer; em tela estreita vira largura cheia. */
.history-panel{ width: 540px; }
@media (max-width: 620px){
  .history-panel{ width: 100%; border-left: none; }
  .history-head, .history-toolbar, .panel-tabs, .history-list{
    padding-left: 16px; padding-right: 16px;
  }
  .perm-grid{ grid-template-columns: 1fr; }
  .history-toolbar{ flex-wrap: wrap; }
  .history-toolbar input{ flex: 1 1 100%; }
}

/* Dentro do painel, duas colunas de campo ficam apertadas demais. */
.history-panel .field-row{ grid-template-columns: 1fr; }

/* ===========================================================
   Responsivo — de 320px ao 4K
   -----------------------------------------------------------
   O que estava quebrado: com todas as abas liberadas (o caso do
   administrador), a fila de 7 abas empurrava a página inteira no
   celular — até 358px de rolagem lateral num aparelho de 320px.

   A causa não era a fila em si, que já tinha `overflow-x:auto`,
   e sim o `min-width:auto` que todo item de grid recebe por
   padrão: a coluna do formulário não podia ficar menor que o
   conteúdo mais largo dentro dela. Sem `min-width:0` na corrente,
   nenhuma rolagem interna funciona.
=========================================================== */

/* ---- Nada empurra a página ---- */
.workspace > *,
.card,
.panel-head,
.panel-body,
.type-tabs{
  min-width: 0;
}
img, canvas, svg, video{ max-width: 100%; }

/* ---- Fila de abas: rola sozinha, sem barra à mostra ---- */
.type-tabs{
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.type-tabs::-webkit-scrollbar{ display: none; }
.type-tabs button{ scroll-snap-align: start; flex: 0 0 auto; }

/* ---- Altura real no celular ----
   `100vh` no celular conta a barra do navegador que some ao rolar,
   e o rodapé do painel fica escondido. `dvh` acompanha o que a
   pessoa realmente vê; navegador antigo ignora e fica no 100%. */
body{ min-height: 100dvh; }
.history-panel{ height: 100dvh; }

/* ---- Pré-visualização nunca maior que a coluna ---- */
.qr-stage{ overflow: hidden; }
.qr-stage #qr-render canvas,
.qr-stage #qr-render img{ max-width: 100%; height: auto; }

/* ===========================================================
   Telas de dedo — alvo mínimo de 44px (WCAG 2.2, 2.5.8)
=========================================================== */
@media (pointer: coarse){
  .type-tabs button,
  .btn,
  .panel-tab,
  .btn-close{ min-height: 44px; }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea{ min-height: 44px; }

  /* 16px é o limiar abaixo do qual o Safari do iPhone dá zoom
     sozinho ao focar o campo — e aí a página fica torta. */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea{ font-size: 16px; }

  .perm-chip{ min-height: 44px; display:flex; align-items:center; }
}

/* ===========================================================
   Celular pequeno — 320 a 380px
=========================================================== */
@media (max-width: 380px){
  .container{ padding: 0 14px; }
  .panel-body{ padding: 18px 14px 20px; }
  .panel-head{ padding: 18px 14px 0; }
  .preview-card{ padding: 18px 14px; }
  .hero-intro{ padding: 24px 0 4px; }
  .hero-intro h1{ font-size: 26px; }
  .hero-intro p{ font-size: 14.5px; }
  .type-tabs{ padding: 4px; }
  .type-tabs button{ padding: 10px 12px; font-size: 12.5px; }
  .qr-stage{ padding: 14px; min-height: 200px; }
  .history-head, .history-toolbar, .panel-tabs, .history-list{
    padding-left: 12px; padding-right: 12px;
  }
}

/* ===========================================================
   Celular deitado e telas baixas — sobra pouca altura, então
   o que ocupa espaço vertical encolhe.
=========================================================== */
@media (max-height: 520px) and (orientation: landscape){
  .site-header{ padding: 12px 0 6px; }
  .hero-intro{ padding: 14px 0 4px; }
  .hero-intro h1{ font-size: 24px; margin-bottom: 8px; }
  .hero-intro p{ display: none; }
  .workspace{ padding: 16px 0 40px; gap: 16px; }
  .qr-stage{ min-height: 180px; }
}

/* ===========================================================
   Tablet em pé — uma coluna, porém com folga maior que a do
   celular. O corte de 900px já existe; aqui só o respiro.
=========================================================== */
@media (min-width: 641px) and (max-width: 900px){
  .workspace{ gap: 22px; }
  .preview-card{ position: sticky; top: 16px; }
}

/* ===========================================================
   Monitores grandes — o conteúdo para de ficar espremido no
   meio de uma faixa de 1180px cercada de vazio.
=========================================================== */
@media (min-width: 1600px){
  .container{ max-width: 1360px; padding: 0 40px; }
  .workspace{ gap: 36px; }
}
@media (min-width: 2200px){
  .container{ max-width: 1560px; }
  .hero-intro{ max-width: 760px; }
  .hero-intro h1{ font-size: 46px; }
  .qr-stage{ min-height: 320px; }
}

/* ===========================================================
   Impressão — a folha de etiquetas já tem tratamento próprio
   no JavaScript; aqui é a página comum saindo em papel.
=========================================================== */
@media print{
  .site-header, .hero-intro, .type-tabs, .preview-actions,
  .history-overlay, .btn, .bulk-print-row{ display: none !important; }
  body{ background: #fff; color: #000; }
  .workspace{ display: block; padding: 0; }
  .card{ border: none; box-shadow: none; }
}

/* ===========================================================
   Motor de rastreio — contagem por tag no histórico
=========================================================== */
.hi-scans{
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.hi-scans-vazio{
  font-size: 12.5px;
  color: var(--muted-2);
}
.hi-scans-num{
  font-size: 13.5px;
  color: var(--white);
  margin-bottom: 10px;
}
.hi-scans-num strong{ font-size: 18px; }
.hi-scans-per{
  color: var(--muted-2);
  font-size: 12px;
}
.hi-bars{
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  height: 74px;
}
.hi-bar{
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  gap: 4px;
}
.hi-bar-fill{
  width: 100%;
  min-height: 0;
  border-radius: 4px 4px 2px 2px;
  background: var(--grad-brand);
  transition: height .2s ease;
}
/* Dia sem movimento fica com um traço apagado, para a coluna não
   sumir e dar a impressão de que o dia não existiu. */
.hi-bar-fill[style*="height:0%"]{
  min-height: 2px;
  background: var(--border-strong);
}
.hi-bar-dia{
  font-size: 10px;
  color: var(--muted-2);
  white-space: nowrap;
}
@media (max-width: 380px){
  .hi-bars{ height: 60px; gap: 4px; }
  .hi-bar-dia{ font-size: 9px; }
}

/* ===========================================================
   Editor de campos da etiqueta
=========================================================== */
.campos-editor{
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}
.campo-regiao + .campo-regiao{ margin-top: 14px; }
.campo-regiao-nome{
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 8px;
}
.campo-linha{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.campo-linha:last-child{ border-bottom: none; }
.campo-chip{
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--white);
  cursor: pointer;
  min-width: 0;
}
.campo-chip input{ flex: 0 0 auto; }
.campo-chip span{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Campo desligado continua legível, só recuado — some da etiqueta,
   não da lista, senão não dá para ligar de volta. */
.campo-chip input:not(:checked) + span{ color: var(--muted-2); }

.campo-setas{ display: flex; gap: 4px; flex: 0 0 auto; }
.campo-seta{
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--white);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.campo-seta:hover:not(:disabled){ border-color: var(--border-strong); }
.campo-seta:disabled{ opacity: .3; cursor: default; }

@media (pointer: coarse){
  .campo-seta{ width: 44px; height: 44px; }
}

/* ===========================================================
   Série histórica no painel do administrador
=========================================================== */
.metric-bars{
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  align-items: end;
  height: 56px;
  margin-top: 10px;
}
.mb-col{
  height: 100%;
  display: flex;
  align-items: flex-end;
}
.mb-fill{
  width: 100%;
  border-radius: 2px 2px 0 0;
  background: var(--grad-brand);
  min-height: 0;
}
/* Dia sem leitura vira um traço apagado: some a barra, não o dia. */
.mb-fill[style*="height:0%"]{
  min-height: 2px;
  background: var(--border-strong);
}
.metric-bars-eixo{
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted-2);
  margin-top: 4px;
}
