:root {
  --bg: #0f1419; --panel: #161c24; --panel-2: #1d2530; --line: #2a3441; --text: #e6ebf1; --muted: #8b98a8;
  --accent: #1e88e5; --accent-2: #1565c0; --ok: #2e9e5b; --warn: #d9a300; --bad: #d64545; --new: #7c6ff0;
  --radius: 8px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.inline input { width: auto; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.mono { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 20px 0 10px; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 20; }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: grid; gap: 12px; }
.brand { font-weight: 700; letter-spacing: .04em; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 12px; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 9px 10px; border-radius: 6px; color: var(--text); }
.sidebar nav a:hover { background: var(--panel-2); }
.sidebar nav a.active { background: var(--accent-2); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
/* min-width:0 — sem isso uma tabela larga empurra a coluna do grid e a página inteira rola de lado */
.main { padding: 24px 28px; max-width: 1300px; min-width: 0; }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat { display: grid; gap: 4px; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.tabs a.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; max-width: 100%; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .row { flex-wrap: nowrap; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.new { background: rgba(124,111,240,.18); color: #b3aaff; }
.pill.active { background: rgba(46,158,91,.18); color: #6fd39a; }
.pill.expired { background: rgba(217,163,0,.18); color: #ffd35c; }
.pill.blocked { background: rgba(214,69,69,.18); color: #ff8a8a; }
.pill.offline { background: rgba(139,152,168,.18); color: var(--muted); }
.pill.kind { background: var(--panel-2); color: var(--text); }

form.form { display: grid; gap: 10px; }
form.form .grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px; z-index: 30; max-width: 380px; }
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
details { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: var(--panel); }
summary { cursor: pointer; font-weight: 600; }
.notice { border-left: 3px solid var(--warn); padding: 8px 12px; background: rgba(217,163,0,.08); border-radius: 4px; }
/* fase 02A: personalização remota + teste automático */
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
.theme-preview { border-radius: 10px; border: 2px solid; padding: 12px; display: grid; gap: 8px; margin-top: 6px; }
.theme-preview .tp-logo { font-weight: 800; letter-spacing: .06em; font-size: 14px; }
.theme-preview .tp-row { display: flex; gap: 8px; }
.theme-preview .tp-card { width: 56px; height: 36px; border-radius: 6px; }
.theme-preview .tp-badge { justify-self: start; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px; letter-spacing: .05em; }

/* ================================================================== fase 02E: celular primeiro + PWA */
:root { --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --tabbar-h: 58px; --topbar-h: 52px; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
.btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; touch-action: manipulation; }
.btn.small { min-height: 30px; }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.icon { width: 44px; height: 44px; padding: 0; }
.btn.icon svg, .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.topbar, .tabbar, .drawer-scrim { display: none; }
.offline-bar { position: fixed; left: 0; right: 0; top: 0; z-index: 60; background: var(--bad); color: #fff; text-align: center; font-size: 13px; padding: calc(6px + var(--safe-t)) 12px 6px; }

/* folha de confirmacao: centralizada no desktop */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
.sheet { width: min(460px, 100%); max-height: 86vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: grid; gap: 12px; }
.sheet-title { margin: 0; font-size: 17px; line-height: 1.35; }
.sheet-text { margin: 0; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.sheet-actions .btn { min-width: 110px; min-height: 44px; }
body.sheet-open { overflow: hidden; }

@media (max-width: 950px) {
  /* 16 px nos campos: abaixo disso o Safari do iPhone da zoom sozinho ao focar */
  input, select, textarea { font-size: 16px; min-height: 46px; padding: 10px 12px; }
  textarea { min-height: 88px; }
  input[type="checkbox"] { min-height: 0; width: 22px; height: 22px; }
  input[type="color"] { padding: 4px; }
  select[multiple] { min-height: 160px; }
  label { font-size: 14px; }
  label.inline { min-height: 44px; }
  .btn { min-height: 46px; padding: 10px 16px; font-size: 15px; }
  .btn.small { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  h1 { font-size: 20px; margin-bottom: 12px; overflow-wrap: anywhere; }

  .shell { display: block; min-height: 100%; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 30; align-items: center; justify-content: space-between; gap: 8px;
    height: calc(var(--topbar-h) + var(--safe-t)); padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(14px + var(--safe-l));
    background: var(--panel); border-bottom: 1px solid var(--line); }
  .topbar .brand { min-width: 0; } .topbar #topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn.icon { border-color: transparent; background: transparent; }
  .main { padding: 16px calc(14px + var(--safe-r)) calc(var(--tabbar-h) + var(--safe-b) + 24px) calc(14px + var(--safe-l)); max-width: none; }

  /* barra inferior: as quatro telas do dia a dia + "Mais", ao alcance do polegar */
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
    background: var(--panel); border-top: 1px solid var(--line); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: var(--tabbar-h);
    background: none; border: 0; color: var(--muted); font-size: 11px; cursor: pointer; touch-action: manipulation; }
  .tabbar .active { color: var(--accent); }

  /* menu completo vira gaveta */
  .sidebar { position: fixed; z-index: 45; top: 0; bottom: 0; right: 0; left: auto; width: min(320px, 86vw); height: auto; border-right: 0; border-left: 1px solid var(--line);
    padding: calc(16px + var(--safe-t)) calc(14px + var(--safe-r)) calc(16px + var(--safe-b)) 14px; overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(105%); visibility: hidden; transition: transform .18s ease, visibility 0s linear .18s; }
  .sidebar nav a { padding: 13px 12px; font-size: 16px; }
  .sidebar-foot { font-size: 13px; }
  body.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .18s ease; }
  body.drawer-open .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); }
  body.drawer-open { overflow: hidden; }

  /* cabecalhos de tela: titulo em cima, busca ocupando a largura */
  .row.between { align-items: stretch; }
  .row.between > form.row { flex: 1 1 100%; flex-wrap: nowrap; }
  .row.between > form.row input, .row.between > form.row select { width: auto !important; flex: 1 1 auto; min-width: 0; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -14px; padding-inline: 14px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: 0 0 auto; padding: 10px 14px; font-size: 14px; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2, form.form .grid { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; }
  .notice.row { align-items: stretch; } .notice.row .btn { width: 100%; }
  form.form > div:last-child .btn, form.form > .row > .btn { flex: 1 1 auto; }
  details > summary { padding: 8px 0; min-height: 44px; display: flex; align-items: center; }

  /* acao principal do aparelho (bloquear/desbloquear) presa acima da barra inferior */
  .sticky-actions { position: fixed; right: calc(14px + var(--safe-r)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 20; }
  .sticky-actions .btn { box-shadow: 0 6px 18px rgba(0,0,0,.5); background: var(--panel-2); }
  .sticky-actions .btn.primary { background: var(--accent); }

  /* tabelas viram cards: nenhuma coluna some */
  .table-wrap { overflow: visible; }
  table.cards, table.cards tbody { display: block; background: none; border: 0; }
  table.cards thead { display: none; }
  table.cards tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
  table.cards td { display: block; border: 0; padding: 4px 0; min-width: 0; max-width: none; white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
  table.cards td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 1px; }
  table.cards td:first-child { grid-column: 1 / -1; font-size: 16px; padding-bottom: 6px; }
  table.cards td:first-child::before { display: none; }
  table.cards td.clip, table.cards td.actions, table.cards tr.full td { grid-column: 1 / -1; }
  table.cards td.blank { display: none; }
  table.cards td.actions::before { display: none; }
  table.cards td.actions { padding-top: 8px; }
  table.cards td .row, td .row { flex-wrap: wrap; }
  table.cards td .row .btn { flex: 1 1 auto; }
  table.cards tr.full { padding: 0 12px 10px; margin-top: -16px; border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
  table.cards tr.clickable:active { background: var(--panel-2); }
  table.kv, table.kv tbody { display: block; } table.kv tr { display: block; padding: 8px 10px; border-bottom: 1px solid var(--line); }
  table.kv tr:last-child { border-bottom: 0; }
  table.kv th, table.kv td { display: block; border: 0; padding: 0; overflow-wrap: anywhere; } table.kv th { margin-bottom: 2px; }

  .toast { left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); max-width: none; }
  .login { padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }

  /* confirmacao vira folha presa embaixo, com os botoes sempre visiveis */
  .sheet-backdrop { place-items: end stretch; padding: 0; }
  .sheet { width: 100%; max-height: 88vh; border-radius: 16px 16px 0 0; border-bottom: 0; padding: 20px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .sheet-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 4px; }
  .sheet-actions .btn { flex: 1 1 0; min-height: 50px; }
}
/* celular deitado: barra inferior mais baixa, para sobrar tela */
@media (max-width: 950px) and (max-height: 480px) and (orientation: landscape) { :root { --tabbar-h: 46px; --topbar-h: 44px; } .tabbar span { display: none; } }
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none !important; } }

/* fase 02F: erro ao lado do campo, campos por tipo, listas de seleção por caixa */
.field-error { display: block; color: var(--bad); font-size: 13px; margin-top: 4px; font-weight: 600; }
[aria-invalid="true"] { border-color: var(--bad) !important; outline-color: var(--bad); }
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; font-weight: 400; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 260px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.check-list label { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.section-title { margin: 22px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat.warn .n { color: var(--bad); }
.kv-line { display: flex; flex-wrap: wrap; gap: 6px 14px; }

/* ---------- APIs e integrações / Revendas (API online) ---------- */
fieldset.int-mode { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; display: grid; gap: 10px; }
fieldset.int-mode legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
fieldset.int-mode label.inline { align-items: flex-start; color: var(--text); font-size: 14px; }
fieldset.int-mode label.inline input { margin-top: 3px; flex: none; }
table.int-facts { margin: 10px 0 14px; }
table.int-facts th { width: 38%; color: var(--muted); font-weight: 500; }
.int-result { margin: 4px 0 0; padding: 8px 12px; border-radius: 6px; font-weight: 600; }
.int-result.ok { background: rgba(46,158,91,.14); color: #6fd39a; }
.int-result.bad { background: rgba(214,69,69,.14); color: #ff8a8a; }
.int-app { max-width: 460px; margin-bottom: 14px; }
.rs-sub { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 6px; }
.rs-inline { margin-top: 8px; align-items: flex-end; }
.rs-inline label { flex: 1 1 200px; }
.rs-cred { margin: 0 0 14px; display: grid; gap: 4px; }
.rs-cred p { margin: 0; }
.rs-secret { font-size: 15px; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.grid.int-fields { grid-template-columns: 1fr; }
label.int-check { align-items: flex-start; }
label.int-check input { margin-top: 3px; flex: none; }
