/* =====================================================================================
   Admin ISP — componentes da Central do Assinante
   Camada de produto sobre os tokens do design system (design/tokens.css).
   Sem dependência externa: fontes embutidas, ícones em SVG inline, QR gerado no cliente.

   Regras da casa (não negociáveis):
   * fundo #F6F8FC, cartões brancos, borda #E3E9F2, raio 16px, sombra suave;
   * AÇÃO sempre em var(--aisp-brand); ciano var(--aisp-signal) só para sinal/conexão/identidade;
   * nenhum degradê de fundo de página, sem glassmorphism pesado, sem emoji;
   * mobile-first, alvos >= 44px, :focus-visible visível, contraste >= 4.5:1;
   * prefers-reduced-motion respeitado.
   ===================================================================================== */

/* ---------- Fonte (Inter, embutida — funciona offline no PWA) ---------- */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/inter-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/inter-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/inter-latin-700-normal.woff2') format('woff2');
}

/* ---------- Tokens de layout (a marca do tenant sobrescreve só --aisp-brand/--aisp-signal) ---------- */
:root {
  --aisp-ink: #0b1220;
  --aisp-brand: var(--brand-color-primary, #1e6be6);
  --aisp-brand-strong: var(--brand-color-primary-active, #0f4dbf);
  --aisp-brand-soft: var(--brand-color-primary-bg, #eef4ff);
  --aisp-brand-line: #cfe1ff;
  --aisp-signal: #16d0c4;
  --aisp-success: #12b76a;
  --aisp-warning: #f79009;
  --aisp-danger: #f04438;
  /* "tinta" das cores de estado: mesmas famílias com contraste >= 4.5:1 sobre os fundos claros */
  --aisp-success-ink: #067647;
  --aisp-warning-ink: #8a4b00;
  --aisp-danger-ink: #9b2318;
  --aisp-bg: #f6f8fc;
  --aisp-surface: #ffffff;
  --aisp-line: #e3e9f2;
  --aisp-line-strong: #d3dcea;
  --aisp-muted: #5b6b84;
  --aisp-subtle: #667691;
  --aisp-r-sm: 8px;
  --aisp-r-md: 12px;
  --aisp-r-lg: 16px;
  --aisp-r-xl: 24px;
  --aisp-r-full: 999px;
  --aisp-sh-1: 0 1px 2px rgba(11, 18, 32, .06), 0 1px 3px rgba(11, 18, 32, .04);
  --aisp-sh-2: 0 2px 4px rgba(11, 18, 32, .05), 0 10px 22px -14px rgba(11, 18, 32, .22);
  --aisp-sh-3: 0 6px 12px rgba(11, 18, 32, .08), 0 24px 48px -20px rgba(11, 18, 32, .34);
  --aisp-max: 1180px;
  --aisp-header-h: 64px;
  --aisp-nav-h: 68px;
}

/* Tints derivados da cor do provedor (o tenant troca a marca só por --aisp-brand) */
@supports (color: color-mix(in srgb, #fff, #000)) {
  :root {
    --aisp-brand-soft: color-mix(in srgb, var(--aisp-brand) 10%, #fff);
    --aisp-brand-line: color-mix(in srgb, var(--aisp-brand) 26%, #fff);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.47;
  color: var(--aisp-ink);
  background: var(--aisp-bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: 1.25; }
a { color: var(--aisp-brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--aisp-brand); outline-offset: 2px; border-radius: 8px; }
.money, .num, .invoice-value, .latency-ms { font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: .86rem; letter-spacing: .2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Marca (logo do provedor) ---------- */
.brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 600; color: inherit; text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-plate {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--aisp-brand-soft);
  border: 1px solid var(--aisp-brand-line);
  box-shadow: var(--aisp-sh-1);
}
.brand-mark { width: 26px; height: 26px; display: block; }
.brand-text { display: block; min-width: 0; }
.brand-name { display: block; font-weight: 700; font-size: 16px; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-tag { display: block; font-size: 10.5px; font-weight: 600; color: var(--aisp-subtle); letter-spacing: .55px; text-transform: uppercase; }

/* ---------- Estrutura do painel ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  min-height: var(--aisp-header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--aisp-line);
  box-shadow: 0 1px 0 rgba(11, 18, 32, .02), 0 8px 20px -22px rgba(11, 18, 32, .5);
}
.app-header-brand { flex: 1 1 auto; min-width: 0; }
.app-header .who { display: none; font-size: 12px; color: var(--aisp-muted); text-align: right; line-height: 1.3; min-width: 0; }
.app-header .who strong { display: block; font-size: 13.5px; color: var(--aisp-ink); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.app-header .who span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.hdr-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
/* pílula de status do serviço: só a partir de 560px (no celular ela vive no Início) */
.service-pill { display: none; min-height: 34px; padding: 0 13px; font-size: 12.5px; white-space: nowrap; }
.service-pill .dot { width: 8px; height: 8px; }

.app-main { max-width: var(--aisp-max); margin: 0 auto; padding: 18px 16px calc(var(--aisp-nav-h) + 28px); }
.app-shell { display: block; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  min-height: var(--aisp-nav-h);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, .97);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--aisp-line);
  box-shadow: 0 -10px 26px -22px rgba(11, 18, 32, .55);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav button {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px; border: 0; background: none; cursor: pointer;
  color: var(--aisp-muted);
  font: inherit; font-size: 11.5px; font-weight: 600; letter-spacing: -.1px;
  padding: 8px 2px 6px;
  transition: color .15s ease, background-color .15s ease;
}
.bottom-nav button svg { width: 24px; height: 24px; stroke-width: 1.8; }
.bottom-nav button[aria-current='page'] { color: var(--aisp-brand); font-weight: 700; }
.bottom-nav button[aria-current='page'] svg {
  border-radius: 7px;
  box-shadow: 0 0 0 7px var(--aisp-brand-soft);
  stroke-width: 2.1;
}
.bottom-nav button[aria-current='page']::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 38px; height: 3px; border-radius: 0 0 3px 3px; background: var(--aisp-brand);
}
.bottom-nav button:hover { color: var(--aisp-ink); }

.sidebar { display: none; }

/* ---------- Botões de ícone ---------- */
.icon-btn {
  border: 1px solid var(--aisp-line);
  background: var(--aisp-surface);
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: 13px; cursor: pointer;
  display: grid; place-items: center; color: var(--aisp-muted);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}
.icon-btn:hover { background: var(--aisp-bg); color: var(--aisp-ink); border-color: var(--aisp-line-strong); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.bell { position: relative; color: var(--aisp-ink); }
.icon-btn.bell:hover { color: var(--aisp-brand); border-color: var(--aisp-brand-line); }
#bell-dot {
  position: absolute; top: 8px; right: 8px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--aisp-danger);
  box-shadow: 0 0 0 3px var(--aisp-surface);
}
#bell-dot::after {
  content: ''; position: absolute; inset: -5px;
  border-radius: 50%; border: 2px solid var(--aisp-danger);
  animation: bellPulse 2.2s ease-out infinite;
}
@keyframes bellPulse {
  0% { transform: scale(.55); opacity: .65; }
  70% { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}
/* sino com aviso = mais contraste e marca visível */
.icon-btn.bell:has(#bell-dot:not(.hidden)) { background: var(--aisp-brand-soft); border-color: var(--aisp-brand-line); color: var(--aisp-brand); }

/* ---------- Cartões e seções ---------- */
.section { margin-bottom: 22px; }
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 21px; font-weight: 700; letter-spacing: -.5px; margin-bottom: 6px;
}
.section-title::before {
  content: ''; flex: 0 0 auto;
  width: 4px; height: 20px; border-radius: 3px;
  background: var(--aisp-brand);
}
.section-sub {
  font-size: 13.5px; color: var(--aisp-muted);
  margin: 0 0 16px 14px;
  padding-left: 11px;
  border-left: 2px solid var(--aisp-line);
  line-height: 1.4;
}
.card {
  background: var(--aisp-surface);
  border: 1px solid var(--aisp-line);
  border-radius: var(--aisp-r-lg);
  box-shadow: var(--aisp-sh-1);
  padding: 18px;
}
.card + .card { margin-top: 12px; }
.card-title { font-size: 16.5px; font-weight: 700; letter-spacing: -.2px; margin-bottom: 10px; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stack { display: grid; gap: 10px; }
/* cartões que são atalhos (o JS monta <button class="card" data-act=...>) */
button.card, a.card {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}
button.card:hover, a.card:hover {
  text-decoration: none;
  border-color: var(--aisp-brand-line);
  box-shadow: var(--aisp-sh-2);
  transform: translateY(-1px);
}
button.card:active { transform: translateY(0); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px;
  border-radius: var(--aisp-r-md); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  white-space: nowrap;
  transition: transform .12s cubic-bezier(.2,.8,.2,1), background-color .12s, border-color .12s, box-shadow .12s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn-primary { background: var(--aisp-brand); color: #fff; box-shadow: 0 6px 16px -10px rgba(11, 18, 32, .55); }
.btn-primary:hover { background: var(--brand-color-primary-hover, #468ef2); }
.btn-secondary { background: var(--aisp-surface); color: var(--aisp-ink); border-color: var(--aisp-line-strong); }
.btn-secondary:hover { background: var(--aisp-bg); border-color: var(--aisp-brand-line); color: var(--aisp-brand); }
.btn-ghost { background: transparent; color: var(--aisp-brand); padding: 0 10px; }
.btn-ghost:hover { background: var(--aisp-brand-soft); }
.btn-danger { background: var(--aisp-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; font-size: 14px; padding: 0 13px; border-radius: 11px; }

/* ---------- Pílulas e badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: var(--aisp-r-full);
  border: 1px solid transparent;
  font-size: 12.5px; font-weight: 600; line-height: 1.35;
  white-space: nowrap;
}
.pill svg { width: 14px; height: 14px; }
.pill-ok { background: rgba(18, 183, 106, .12); border-color: rgba(18, 183, 106, .3); color: var(--aisp-success-ink); }
.pill-warn { background: rgba(247, 144, 9, .14); border-color: rgba(247, 144, 9, .34); color: var(--aisp-warning-ink); }
.pill-bad { background: rgba(240, 68, 56, .12); border-color: rgba(240, 68, 56, .3); color: var(--aisp-danger-ink); }
.pill-info { background: var(--aisp-brand-soft); border-color: var(--aisp-brand-line); color: var(--aisp-brand-strong); }
.pill-signal { background: rgba(22, 208, 196, .16); border-color: rgba(22, 208, 196, .34); color: #0a5b56; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

/* ---------- Campos ---------- */
.field { display: block; margin-bottom: 14px; }
.field label, .field > span:first-child { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--aisp-muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--aisp-line-strong); border-radius: var(--aisp-r-md);
  background: var(--aisp-surface); color: var(--aisp-ink);
  font: inherit; font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea.input { min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--aisp-subtle); }
.input:hover { border-color: var(--aisp-line-strong); }
.input:focus { border-color: var(--aisp-brand); outline: none; box-shadow: 0 0 0 3px var(--aisp-brand-soft); }
.field-hint { font-size: 12.5px; color: var(--aisp-subtle); margin-top: 6px; line-height: 1.45; }

/* ---------- Fatura (componente mais importante da central) ---------- */
.invoice { display: grid; gap: 14px; }
.invoice + .invoice { margin-top: 12px; }
.invoice-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.invoice-comp { font-size: 12.5px; color: var(--aisp-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.invoice-doc { font-size: 12.5px; color: var(--aisp-subtle); margin-top: 2px; }
.invoice-value { font-size: 27px; font-weight: 700; letter-spacing: -.8px; text-align: right; white-space: nowrap; }
.invoice-value small {
  display: inline-block; margin-top: 6px;
  font-size: 10.5px; font-weight: 700; color: var(--aisp-warning-ink);
  letter-spacing: .5px; text-transform: uppercase;
  background: rgba(247, 144, 9, .14); border: 1px solid rgba(247, 144, 9, .32);
  padding: 3px 8px; border-radius: var(--aisp-r-full);
}
.invoice-value.is-paid { color: var(--aisp-success-ink); }
.invoice-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--aisp-muted); }
.invoice-meta b { color: var(--aisp-ink); font-weight: 600; }
.invoice-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.invoice-actions .btn { flex: 1 1 auto; min-height: 44px; }

/* item da lista: a barra lateral de estado é decidida pelo conteúdo que o JS injeta */
.card.invoice { position: relative; overflow: hidden; }
.card.invoice::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--aisp-brand); opacity: .85;
}
.card.invoice:has(.invoice-value.is-paid)::before { background: var(--aisp-success); }
.card.invoice:has(.pill-warn)::before { background: var(--aisp-warning); }
.card.invoice .pill { padding: 6px 12px; font-size: 12.5px; }

.invoice-hero {
  position: relative;
  border: 1px solid var(--aisp-line);
  border-radius: var(--aisp-r-lg);
  background: var(--aisp-surface);
  box-shadow: var(--aisp-sh-2);
  padding: 20px 18px;
  overflow: hidden;
}
.invoice-hero::after {
  content: ''; position: absolute; right: -60px; top: -60px;
  width: 160px; height: 160px; border-radius: 50%;
  background: var(--aisp-brand-soft); opacity: .55;
  pointer-events: none;
}
.invoice-hero > * { position: relative; }
.invoice-hero.is-open { border-left: 6px solid var(--aisp-warning); }
.invoice-hero.is-clear { border-left: 6px solid var(--aisp-success); }
.invoice-hero .invoice-comp { font-size: 13px; }
.invoice-hero .invoice-doc { font-size: 13.5px; color: var(--aisp-muted); font-weight: 500; }
.invoice-hero .invoice-value { font-size: 34px; font-weight: 800; letter-spacing: -1.4px; }
.invoice-hero .invoice-actions { margin-top: 16px; }
.invoice-hero .invoice-actions .btn { min-height: 48px; font-size: 15.5px; }
.invoice-hero .alert { margin-top: 14px; border: 1px solid rgba(247, 144, 9, .3); }
.invoice-hero .empty { padding: 10px 4px 6px; }

/* ---------- Latência ---------- */
.latency { display: grid; gap: 14px; }
.latency-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding-top: 12px; border-top: 1px dashed var(--aisp-line); }
.latency-row:first-child { padding-top: 0; border-top: 0; }
.latency-name { font-size: 14px; font-weight: 600; }
.latency-ms {
  font-size: 12.5px; font-weight: 700; color: var(--aisp-muted);
  background: var(--aisp-bg); border: 1px solid var(--aisp-line);
  padding: 3px 9px; border-radius: var(--aisp-r-full);
}
.latency-bar { grid-column: 1 / -1; height: 8px; border-radius: var(--aisp-r-full); background: var(--aisp-bg); overflow: hidden; box-shadow: inset 0 0 0 1px var(--aisp-line); }
.latency-bar i { display: block; height: 100%; border-radius: var(--aisp-r-full); background: var(--aisp-success); transition: width .3s cubic-bezier(.2,.8,.2,1); }
.latency-bar i.warn { background: var(--aisp-warning); }
.latency-bar i.bad { background: var(--aisp-danger); }
.latency-bar i.self { background: var(--aisp-signal); }
.latency-row:has(i.warn) .latency-ms { background: rgba(247, 144, 9, .14); border-color: rgba(247, 144, 9, .3); color: var(--aisp-warning-ink); }
.latency-row:has(i.bad) .latency-ms { background: rgba(240, 68, 56, .12); border-color: rgba(240, 68, 56, .28); color: var(--aisp-danger-ink); }

/* ---------- Estados ---------- */
.empty { text-align: center; padding: 30px 16px; color: var(--aisp-muted); }
.empty svg {
  width: 64px; height: 64px; padding: 17px; box-sizing: border-box;
  border-radius: 50%; margin: 0 auto 14px;
  background: var(--aisp-brand-soft);
  border: 1px solid var(--aisp-brand-line);
  stroke: var(--aisp-brand);
  display: block;
}
.empty h3 { font-size: 17px; font-weight: 700; color: var(--aisp-ink); margin-bottom: 6px; }
.empty p { font-size: 14px; margin: 0 auto 16px; max-width: 36ch; line-height: 1.5; }
.alert {
  display: flex; gap: 11px; padding: 14px 15px;
  border-radius: var(--aisp-r-md); border-left: 4px solid currentColor;
  font-size: 14px; line-height: 1.45; align-items: flex-start;
}
.alert svg { width: 19px; height: 19px; flex: 0 0 auto; margin-top: 1px; }
.alert-warn { background: #fff8ec; color: #7a4300; }
.alert-bad { background: #fdf2f1; color: #8f1d14; }
.alert-ok { background: #eefaf3; color: #08603a; }
.alert-info { background: var(--aisp-brand-soft); color: #12385f; }
.alert .btn { margin-top: 8px; }
.skeleton {
  background: linear-gradient(90deg, #eef2f8 25%, #e3e9f2 37%, #eef2f8 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
  border-radius: 10px;
}
.skeleton-line { height: 12px; margin-bottom: 8px; }
.skeleton-line.w60 { width: 60%; }
.skeleton-block { height: 84px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Aviso / nota (lista) ---------- */
.notices { display: grid; gap: 10px; }
.notice {
  display: flex; gap: 12px; padding: 14px;
  border: 1px solid var(--aisp-line); border-radius: 14px;
  background: var(--aisp-surface); box-shadow: var(--aisp-sh-1);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.notice:hover { border-color: var(--aisp-brand-line); box-shadow: var(--aisp-sh-2); }
.notice-icon {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--aisp-brand-soft); color: var(--aisp-brand);
  border: 1px solid var(--aisp-brand-line);
}
.notice-icon svg { width: 20px; height: 20px; }
.notice-body { min-width: 0; flex: 1; }
.notice-body h4 { font-size: 14.5px; font-weight: 700; margin: 0 0 3px; }
.notice-body p { font-size: 13.5px; color: var(--aisp-muted); line-height: 1.45; }

/* ---------- Consumo ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.chart-bar { flex: 1; background: var(--aisp-brand); border-radius: 6px 6px 2px 2px; min-height: 4px; opacity: .85; transition: opacity .15s; }
.chart-bar:hover { opacity: 1; }
.chart-axis { display: flex; gap: 6px; margin-top: 8px; }
.chart-axis span { flex: 1; text-align: center; font-size: 11px; color: var(--aisp-subtle); }

/* ---------- Assistente (chat) ---------- */
#chat-fab {
  position: fixed; right: 16px; bottom: calc(var(--aisp-nav-h) + 16px); z-index: 55;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--aisp-brand); color: #fff;
  box-shadow: 0 10px 22px -10px rgba(11, 18, 32, .6), 0 2px 6px rgba(11, 18, 32, .18);
  display: grid; place-items: center;
  transition: transform .14s cubic-bezier(.2,.8,.2,1);
}
#chat-fab:hover { transform: translateY(-2px); }
#chat-fab svg { width: 26px; height: 26px; }
#chat-panel {
  position: fixed; inset: auto 0 0 0; z-index: 65; display: none;
  background: var(--aisp-surface); border-radius: var(--aisp-r-xl) var(--aisp-r-xl) 0 0;
  box-shadow: var(--aisp-sh-3); max-height: 84vh; flex-direction: column;
  border: 1px solid var(--aisp-line); border-bottom: 0;
}
#chat-panel.open { display: flex; }
.chat-head { display: flex; align-items: center; gap: 11px; padding: 15px 16px; border-bottom: 1px solid var(--aisp-line); }
.chat-head .avatar {
  position: relative; width: 38px; height: 38px; border-radius: 50%;
  background: var(--aisp-brand-soft); color: var(--aisp-brand);
  border: 1px solid var(--aisp-brand-line);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.chat-head .avatar::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--aisp-signal); border: 2px solid var(--aisp-surface);
}
.chat-log { flex: 1; overflow: auto; padding: 16px; display: grid; gap: 10px; background: var(--aisp-bg); }
.msg { max-width: 84%; padding: 11px 14px; border-radius: 16px; font-size: 14px; white-space: pre-wrap; line-height: 1.45; box-shadow: var(--aisp-sh-1); }
.msg.bot { background: var(--aisp-surface); border: 1px solid var(--aisp-line); border-bottom-left-radius: 5px; }
.msg.me { background: var(--aisp-brand); color: #fff; margin-left: auto; border-bottom-right-radius: 5px; }
.chat-form { display: flex; gap: 8px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0)); border-top: 1px solid var(--aisp-line); }
.chat-form input { flex: 1; }
.chat-form button { min-width: 48px; padding: 0 14px; }

/* =====================================================================================
   LOGIN — impacto: prova de valor + mockup + formulário
   ===================================================================================== */
.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: grid; gap: 20px; align-content: start;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "copy" "panel" "mock";
  padding: 26px 16px 40px;
  background: var(--aisp-bg);
}
.login-copy { grid-area: copy; display: grid; gap: 14px; justify-items: start; }
.login-h1 { font-size: 30px; font-weight: 800; letter-spacing: -1.1px; line-height: 1.14; margin: 6px 0 0; }
.login-h1 em { font-style: normal; background: var(--aisp-brand-soft); box-shadow: inset 0 0 0 1px var(--aisp-brand-line); border-radius: 6px; padding: 0 5px; }
.login-lead { font-size: 15.5px; color: var(--aisp-muted); max-width: 46ch; line-height: 1.5; }
.login-highlights { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 12px; width: 100%; }
.hi { display: flex; gap: 12px; align-items: flex-start; }
.hi-ico {
  width: 42px; height: 42px; flex: 0 0 auto; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--aisp-surface); color: var(--aisp-brand);
  border: 1px solid var(--aisp-line); box-shadow: var(--aisp-sh-1);
}
.hi-ico svg { width: 21px; height: 21px; }
.hi-ico.is-signal { color: #0a5b56; background: rgba(22, 208, 196, .14); border-color: rgba(22, 208, 196, .3); }
.hi-text { min-width: 0; }
.hi-text strong { display: block; font-size: 14.5px; font-weight: 700; letter-spacing: -.2px; }
.hi-text span { display: block; font-size: 13.5px; color: var(--aisp-muted); line-height: 1.45; }
/* linha de confiança: aqui o ciano é legítimo — é sobre conexão/qualidade do link */
.login-note {
  display: flex; align-items: center; gap: 10px;
  margin-top: 4px; padding: 11px 13px;
  font-size: 13px; font-weight: 500; color: var(--aisp-ink);
  background: var(--aisp-surface); border: 1px solid var(--aisp-line);
  border-radius: 14px; box-shadow: var(--aisp-sh-1); max-width: 46ch;
}
.login-note-ico {
  width: 30px; height: 30px; flex: 0 0 auto; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(22, 208, 196, .14); color: #0a5b56;
  border: 1px solid rgba(22, 208, 196, .3);
}
.login-note-ico svg { width: 17px; height: 17px; }

.login-panel { grid-area: panel; }
.login-card {
  width: 100%; max-width: 460px; margin: 0 auto;
  background: var(--aisp-surface); border: 1px solid var(--aisp-line);
  border-radius: var(--aisp-r-xl); box-shadow: var(--aisp-sh-2);
  padding: 24px 20px;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-align: center; }
.login-title { font-size: 23px; font-weight: 700; letter-spacing: -.5px; text-align: center; }
.login-sub { font-size: 14px; color: var(--aisp-muted); text-align: center; margin-bottom: 20px; line-height: 1.45; }
.login-foot { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--aisp-line); font-size: 13px; color: var(--aisp-muted); text-align: center; line-height: 1.6; }
.login-foot a { font-weight: 600; }

/* ---- mockup de celular desenhado em CSS (tela de faturas) ---- */
.login-mock { grid-area: mock; display: grid; place-items: center; gap: 14px; width: 100%; }
.mk-wrap { position: relative; display: grid; place-items: center; padding: 6px 0; }
.mk-phone {
  width: 258px; border-radius: 40px; padding: 9px;
  background: #0b1220; box-shadow: var(--aisp-sh-3);
  border: 1px solid #1d2b47;
}
.mk-screen {
  border-radius: 32px; background: var(--aisp-surface); overflow: hidden;
  padding: 10px 11px 12px; display: grid; gap: 10px;
}
.mk-status { display: flex; align-items: center; justify-content: space-between; font-size: 10px; font-weight: 700; color: var(--aisp-muted); padding: 2px 4px 0; }
.mk-status-bar { display: inline-flex; align-items: flex-end; gap: 2px; height: 9px; }
.mk-status-bar i { width: 3px; border-radius: 1px; background: var(--aisp-signal); display: block; }
.mk-status-bar i:nth-child(1) { height: 4px; }
.mk-status-bar i:nth-child(2) { height: 6px; }
.mk-status-bar i:nth-child(3) { height: 9px; }
.mk-appbar { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--aisp-line); }
.mk-logo {
  width: 24px; height: 24px; border-radius: 8px; flex: 0 0 auto;
  background: var(--aisp-brand-soft); border: 1px solid var(--aisp-brand-line);
  display: grid; place-items: center;
}
.mk-logo i { width: 9px; height: 9px; border-radius: 50%; background: var(--aisp-signal); display: block; }
.mk-appname { font-size: 11px; font-weight: 700; letter-spacing: -.2px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mk-bellicon { width: 16px; height: 16px; border-radius: 5px; background: var(--aisp-bg); border: 1px solid var(--aisp-line); flex: 0 0 auto; }
.mk-hero {
  border: 1px solid var(--aisp-line); border-left: 4px solid var(--aisp-warning);
  border-radius: 14px; padding: 12px; background: var(--aisp-surface);
  box-shadow: var(--aisp-sh-1);
}
.mk-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.mk-label { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; color: var(--aisp-muted); font-weight: 700; }
.mk-value { font-size: 25px; font-weight: 800; letter-spacing: -.9px; font-variant-numeric: tabular-nums; margin-top: 3px; }
.mk-badge {
  font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--aisp-warning-ink); background: rgba(247, 144, 9, .14);
  border: 1px solid rgba(247, 144, 9, .32); border-radius: var(--aisp-r-full);
  padding: 3px 7px; white-space: nowrap;
}
.mk-meta { font-size: 10px; color: var(--aisp-muted); margin-top: 3px; }
.mk-cta {
  margin-top: 10px; height: 34px; border-radius: 10px;
  background: var(--aisp-brand); color: #fff;
  font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center; letter-spacing: -.1px;
}
.mk-list { display: grid; gap: 7px; }
.mk-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border: 1px solid var(--aisp-line); border-radius: 11px;
  background: var(--aisp-surface);
}
.mk-item-l { min-width: 0; }
.mk-item-l strong { display: block; font-size: 10.5px; font-weight: 700; }
.mk-item-l span { display: block; font-size: 9.5px; color: var(--aisp-muted); }
.mk-item-r { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mk-item-r.is-paid { color: var(--aisp-success-ink); }
.mk-pill { font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 2px 6px; border-radius: var(--aisp-r-full); border: 1px solid transparent; }
.mk-pill.ok { color: var(--aisp-success-ink); background: rgba(18, 183, 106, .12); border-color: rgba(18, 183, 106, .3); }
.mk-foot { display: flex; align-items: center; justify-content: space-between; padding: 9px 8px 2px; border-top: 1px solid var(--aisp-line); }
.mk-foot i { width: 17px; height: 17px; border-radius: 6px; background: var(--aisp-line); display: block; }
.mk-foot i.on { background: var(--aisp-brand); }
.mk-float {
  position: absolute; z-index: 2;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 700; color: var(--aisp-ink);
  background: var(--aisp-surface); border: 1px solid var(--aisp-line);
  border-radius: var(--aisp-r-full); padding: 8px 13px;
  box-shadow: var(--aisp-sh-2);
}
.mk-float svg { width: 15px; height: 15px; flex: 0 0 auto; }
.mk-float.pix { top: 34px; left: -22px; color: var(--aisp-brand); }
.mk-float.ok { bottom: 42px; right: -26px; color: var(--aisp-success-ink); }
/* telas muito estreitas: o mockup fica só com o celular, sem os selos flutuantes */
@media (max-width: 400px) {
  .mk-float { display: none; }
  .mk-phone { width: 100%; max-width: 262px; }
}

/* ---- login legado (select_contract.html usa .login-wrap/.login-card) ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }

/* ---------- Escolha de contrato ---------- */
.contract-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 16px; border: 1px solid var(--aisp-line); border-radius: var(--aisp-r-lg);
  background: var(--aisp-surface); cursor: pointer; font: inherit;
  box-shadow: var(--aisp-sh-1);
  transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}
.contract-card:hover { border-color: var(--aisp-brand); box-shadow: var(--aisp-sh-2); transform: translateY(-1px); }
.contract-card .marker { width: 4px; align-self: stretch; border-radius: 4px; background: var(--aisp-brand); flex: 0 0 auto; }
.contract-card .info { flex: 1; min-width: 0; }
.contract-card .info strong { display: block; font-size: 14.5px; font-weight: 700; }
.contract-card .info span { display: block; font-size: 13px; color: var(--aisp-muted); }

/* ---------- Modal / folha ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: flex-end; justify-content: center;
  background: rgba(11, 18, 32, .45); padding: 0;
}
.overlay.open { display: flex; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--aisp-surface);
  border-radius: var(--aisp-r-xl) var(--aisp-r-xl) 0 0;
  box-shadow: var(--aisp-sh-3);
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0));
  animation: up .32s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet::before {
  content: ''; display: block; width: 42px; height: 4px; border-radius: 3px;
  background: var(--aisp-line-strong); margin: -8px auto 14px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.sheet .icon-btn { background: var(--aisp-bg); border-color: var(--aisp-line); }
.pix-qr { display: grid; place-items: center; margin: 6px 0 14px; }
.pix-qr canvas { border: 1px solid var(--aisp-line); border-radius: var(--aisp-r-md); padding: 8px; background: #fff; }
.pix-code { width: 100%; min-height: 84px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* ---------- Toast ---------- */
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--aisp-nav-h) + 12px); z-index: 70; display: grid; gap: 8px; }
.toast {
  background: var(--aisp-ink); color: #fff; border-radius: 14px;
  padding: 13px 15px; font-size: 14px; font-weight: 500; box-shadow: var(--aisp-sh-3);
  display: flex; gap: 10px; align-items: center;
  border-left: 4px solid rgba(255, 255, 255, .35);
  animation: toastIn .26s cubic-bezier(.2,.8,.2,1);
}
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.ok { background: #0d6b45; }
.toast.bad { background: #8f1d14; }

/* ---------- Rodapé ---------- */
.app-footer { padding: 22px 16px 8px; border-top: 1px solid var(--aisp-line); margin-top: 26px; font-size: 13px; color: var(--aisp-muted); }
.app-footer .cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.app-footer h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .55px; color: var(--aisp-subtle); margin: 0 0 8px; font-weight: 700; }
.app-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.app-footer .legal { border-top: 1px solid var(--aisp-line); padding-top: 12px; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; }

/* =====================================================================================
   Desktop
   ===================================================================================== */
@media (min-width: 560px) {
  .service-pill { display: inline-flex; }
  .app-header { padding: 8px 18px; }
}

@media (min-width: 900px) {
  :root { --aisp-nav-h: 0px; --aisp-header-h: 70px; }
  .app-shell { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
  .sidebar {
    display: flex; flex-direction: column; gap: 6px;
    background: #0e2547; color: #cfe0ff; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  }
  .sidebar .brand { color: #fff; margin-bottom: 24px; padding: 0 6px; }
  .sidebar .brand-name { font-size: 17px; }
  .sidebar .brand-tag { color: #9ab4e4; }
  .sidebar .brand-plate { background: rgba(255, 255, 255, .09); border-color: rgba(255, 255, 255, .16); box-shadow: none; }
  .sidebar nav { display: grid; gap: 6px; }
  .sidebar button {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    width: 100%; min-height: 46px; padding: 11px 13px; border: 0; border-radius: 12px;
    background: none; color: inherit; font: inherit; font-size: 14.5px; font-weight: 500;
    cursor: pointer; text-align: left;
    transition: background-color .15s ease, color .15s ease;
  }
  .sidebar button svg { width: 20px; height: 20px; flex: 0 0 auto; opacity: .9; }
  .sidebar button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
  .sidebar button[aria-current='page'] { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 700; }
  .sidebar button[aria-current='page']::before {
    content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
    border-radius: 3px; background: var(--aisp-brand);
  }
  .sidebar .side-foot { margin-top: auto; padding: 14px 4px 0; border-top: 1px solid rgba(255, 255, 255, .14); font-size: 12px; color: #9ab4e4; }
  .sidebar .side-foot a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
  .sidebar .side-foot a:hover { color: #fff; }

  .bottom-nav { display: none; }
  .app-header { padding: 0 30px; }
  .app-main { padding: 28px 30px 48px; }
  .section-title { font-size: 25px; }
  .section-title::before { height: 24px; width: 5px; }
  .section-sub { font-size: 14.5px; }
  .app-footer { padding: 26px 30px 10px; }
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: var(--aisp-r-xl); max-width: 560px; padding: 26px; }
  .sheet::before { display: none; }
  #chat-panel { inset: auto 24px 24px auto; width: 400px; border-radius: var(--aisp-r-xl); border-bottom: 1px solid var(--aisp-line); }
  #chat-fab { right: 24px; bottom: 24px; }
  #toasts { left: auto; right: 24px; bottom: auto; top: 86px; width: 340px; }
  .invoice-actions .btn { flex: 0 0 auto; }
  .invoice-hero { padding: 24px 26px; }
  .invoice-hero .invoice-value { font-size: 40px; }
  .card { padding: 20px; }

  /* Login em duas colunas: marca + prova de valor à esquerda, formulário à direita */
  .login-page {
    grid-template-columns: minmax(0, 1.04fr) minmax(0, .96fr);
    grid-template-areas: "copy panel" "mock panel";
    gap: 0; padding: 0; align-content: stretch; align-items: start;
    background: var(--aisp-bg);
  }
  .login-copy { padding: 56px 52px 16px; max-width: 660px; }
  .login-mock { padding: 4px 52px 56px; justify-items: start; }
  .login-panel {
    background: var(--aisp-surface);
    border-left: 1px solid var(--aisp-line);
    min-height: 100vh; display: grid; place-items: center; padding: 40px 32px;
  }
  .login-card { box-shadow: none; border: 0; padding: 0; max-width: 420px; background: transparent; }
  .login-h1 { font-size: 42px; letter-spacing: -1.6px; }
  .login-lead { font-size: 16.5px; }
  .login-highlights { gap: 14px; margin-top: 10px; }
  .login-title { text-align: left; font-size: 26px; }
  .login-sub { text-align: left; }
  .login-foot { text-align: left; }
  .login-brand-lg .brand-plate { width: 46px; height: 46px; border-radius: 15px; }
  .login-brand-lg .brand-name { font-size: 19px; }
  .mk-phone { width: 272px; }
}

@media (min-width: 1180px) {
  .app-header .who { display: block; }
  .app-header .who span { max-width: 260px; }
  .app-header .who strong { max-width: 260px; }
}

/* Modo escuro (mesma identidade, tokens escuros) */
@media (prefers-color-scheme: dark) {
  body.auto-dark {
    --aisp-bg: #0b1220;
    --aisp-surface: #121b2e;
    --aisp-line: #22304b;
    --aisp-line-strong: #2b3b5c;
    --aisp-ink: #eaf0fb;
    --aisp-muted: #a8bada;
    --aisp-subtle: #93a8c9;
    --aisp-brand-soft: #16233c;
    --aisp-brand-line: #26375a;
    --aisp-success-ink: #4ade8f;
    --aisp-warning-ink: #ffc061;
    --aisp-danger-ink: #ff9b93;
    --aisp-sh-1: 0 1px 2px rgba(0, 0, 0, .35);
    --aisp-sh-2: 0 2px 4px rgba(0, 0, 0, .3), 0 10px 22px -16px rgba(0, 0, 0, .7);
    --aisp-sh-3: 0 6px 12px rgba(0, 0, 0, .4), 0 24px 48px -22px rgba(0, 0, 0, .8);
  }
  body.auto-dark .app-header, body.auto-dark .bottom-nav { background: rgba(18, 27, 46, .95); border-color: var(--aisp-line); }
  body.auto-dark .icon-btn { background: #16233c; border-color: var(--aisp-line); }
  body.auto-dark .icon-btn:hover { background: #1b2740; }
  body.auto-dark #bell-dot { box-shadow: 0 0 0 3px var(--aisp-surface); }
  body.auto-dark .skeleton { background: linear-gradient(90deg, #16213a 25%, #1d2b47 37%, #16213a 63%); background-size: 400% 100%; }
  body.auto-dark .alert-warn { background: #2a1f10; color: #ffc061; }
  body.auto-dark .alert-bad { background: #2c1618; color: #ff9b93; }
  body.auto-dark .alert-ok { background: #10241b; color: #4ade8f; }
  body.auto-dark .alert-info { background: var(--aisp-brand-soft); color: #bcd4ff; }
  body.auto-dark .latency-bar i.self { background: var(--aisp-signal); }
  body.auto-dark .mk-phone { background: #060b16; border-color: #22304b; }
  body.auto-dark .mk-cta { color: #fff; }
  body.auto-dark .login-panel { background: var(--aisp-surface); }
  body.auto-dark .login-note-ico { color: #5eead4; }
  body.auto-dark .hi-ico { background: #16233c; border-color: var(--aisp-line); }
  body.auto-dark .mk-badge { color: var(--aisp-warning-ink); }
  body.auto-dark .toast.ok { background: #0d6b45; }
  body.auto-dark .toast.bad { background: #8f1d14; }
}

/* Movimento reduzido: nada de pulsar, deslizar ou animar */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .skeleton { background: #e9eef6; }
  .skeleton::after { content: none; }
  button.card:hover, .contract-card:hover, #chat-fab:hover { transform: none; }
}
