/* Quer Falar Comigo — tokens e componentes compartilhados dos painéis.
   Visual inspirado no shadcn/ui (paleta zinc), em CSS puro, sem build.
   Os nomes antigos (--red, --muted, --surface…) continuam existindo porque o JS inline dos HTMLs usa. */

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

:root {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #09090b;
  --card: #ffffff;
  --secondary: #f4f4f5;
  --secondary-hover: #e4e4e7;
  --muted-foreground: #71717a;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: #a1a1aa;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --overlay: rgba(9, 9, 11, .5);
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .25), 0 4px 6px -4px rgba(0, 0, 0, .08);
  --success: #15803d; --success-dot: #16a34a; --success-bg: #f0fdf4; --success-border: #bbf7d0;
  --warning: #b45309; --warning-dot: #f59e0b; --warning-bg: #fffbeb; --warning-border: #fde68a;
  --danger: #dc2626;  --danger-dot: #ef4444;  --danger-bg: #fef2f2;  --danger-border: #fecaca;
  --info: #2563eb;    --info-dot: #3b82f6;
  --neutral-dot: #a1a1aa;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --font-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  /* apelidos usados pelo JS inline */
  --bg: var(--background); --surface: var(--card); --surface2: var(--secondary);
  --text: var(--foreground); --muted: var(--muted-foreground);
  --green: var(--success); --yellow: var(--warning); --red: var(--danger); --blue: var(--info);
  --accent: var(--foreground); --accent2: var(--foreground);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: #09090b;
    --foreground: #fafafa;
    --card: #0c0c0e;
    --secondary: #18181b;
    --secondary-hover: #27272a;
    --muted-foreground: #a1a1aa;
    --border: #27272a;
    --input: #27272a;
    --ring: #71717a;
    --primary: #fafafa;
    --primary-foreground: #18181b;
    --overlay: rgba(0, 0, 0, .7);
    --shadow: none;
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .8);
    --success: #4ade80; --success-dot: #22c55e; --success-bg: rgba(34, 197, 94, .08); --success-border: rgba(34, 197, 94, .25);
    --warning: #fbbf24; --warning-dot: #f59e0b; --warning-bg: rgba(245, 158, 11, .08); --warning-border: rgba(245, 158, 11, .25);
    --danger: #f87171;  --danger-dot: #ef4444;  --danger-bg: rgba(239, 68, 68, .08);  --danger-border: rgba(239, 68, 68, .25);
    --info: #60a5fa;    --info-dot: #3b82f6;
    --neutral-dot: #71717a;
  }
}

html { -webkit-text-size-adjust: 100% }
body {
  background: var(--background); color: var(--foreground);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
a { color: var(--foreground); text-decoration: underline; text-decoration-color: var(--ring); text-underline-offset: 3px }
a:hover { text-decoration-color: var(--foreground) }
strong, b { font-weight: 600 }
code, .mono { font-family: var(--font-mono) }
::selection { background: var(--foreground); color: var(--background) }
[hidden] { display: none !important }
.muted { color: var(--muted-foreground) }

/* ── Cabeçalho ── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--background) 85%, transparent);
  backdrop-filter: saturate(180%) blur(8px); -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; min-height: 56px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--foreground); font-weight: 600; font-size: 15px; letter-spacing: -.01em; text-decoration: none }
.brand:hover { text-decoration: none }
.brand-tag { color: var(--muted-foreground); font-weight: 400; font-size: 13px; padding-left: 10px; border-left: 1px solid var(--border) }
.logo { flex: none; display: block }
.logo .logo-bg { fill: var(--foreground) }
.logo .logo-fg { fill: var(--background) }
.spacer { flex: 1 }
.topbar .who { color: var(--muted-foreground); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.topbar .nav-link { color: var(--muted-foreground); font-size: 13px; text-decoration: none }
.topbar .nav-link:hover { color: var(--foreground) }
.hdr-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap }

/* ── Botões ── */
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit }
button:disabled { opacity: .5; cursor: not-allowed; pointer-events: none }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px }

.btn-primary, .btn-ghost, .btn-soft, .btn-copy, .btn-pay, .btn-row-pay, .btn-danger, .btn-warn, .btn-ok {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s;
}
.btn-primary, .btn-pay { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary) }
.btn-primary:hover, .btn-pay:hover { opacity: .88; text-decoration: none }
.btn-ghost, .btn-soft, .btn-row-pay, .btn-danger, .btn-warn, .btn-ok { background: var(--background); color: var(--foreground); border-color: var(--input); box-shadow: var(--shadow) }
.btn-ghost:hover, .btn-soft:hover, .btn-row-pay:hover, .btn-danger:hover, .btn-warn:hover, .btn-ok:hover { background: var(--secondary) }
.btn-soft { height: 32px; padding: 0 12px; font-size: 12.5px }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px }
.btn-row-pay { height: 30px; padding: 0 10px; font-size: 12px }
.btn-copy { height: 26px; padding: 0 8px; font-size: 11.5px; background: var(--background); color: var(--muted-foreground); border-color: var(--input); flex: none }
.btn-copy:hover { color: var(--foreground); background: var(--secondary) }
.btn-danger { color: var(--danger) }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-border) }
.btn-warn { color: var(--warning) }
.btn-warn:hover { background: var(--warning-bg); border-color: var(--warning-border) }
.btn-ok { color: var(--success) }
.btn-ok:hover { background: var(--success-bg); border-color: var(--success-border) }

/* ── Formulários ── */
label { display: block; font-size: 13px; font-weight: 500; color: var(--foreground); margin: 16px 0 6px }
label span { color: var(--muted-foreground); font-weight: 400 }
input, select, textarea {
  width: 100%; height: 36px; padding: 0 12px;
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; outline: none; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 8px 12px }
input::placeholder { color: var(--muted-foreground) }
input:focus, select:focus, textarea:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent) }
input[type="date"] { min-height: 36px }
label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; cursor: pointer; line-height: 1.4 }
label.check input { width: 16px; height: 16px; flex: none; margin-top: 1px; padding: 0; box-shadow: none; accent-color: var(--foreground) }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px }
.hint { color: var(--muted-foreground); font-size: 12px; margin-top: 6px; line-height: 1.4 }

/* ── Login ── */
.login { max-width: 380px; margin: 12vh auto 48px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 24px; box-shadow: var(--shadow) }
.login h1, .login h2 { font-size: 20px; font-weight: 600; letter-spacing: -.02em; margin-bottom: 4px }
.login p { color: var(--muted-foreground); font-size: 13.5px }
.login button[type="submit"] { width: 100%; margin-top: 8px }

/* ── Cartões, títulos, grid ── */
.page-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; margin: 36px 0 14px }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; min-width: 0; box-shadow: var(--shadow) }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-width: 0 }
.card-head .label { font-weight: 600; font-size: 15px; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.empty { grid-column: 1 / -1; border: 1px dashed var(--border); border-radius: var(--radius-lg); padding: 40px 20px; text-align: center; color: var(--muted-foreground) }

/* ── Badge: contorno neutro + ponto colorido (a única cor é o estado) ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--background); color: var(--foreground);
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--neutral-dot) }
.badge.connected::before, .badge.active::before, .badge.paid::before { background: var(--success-dot) }
.badge.qr_pending::before, .badge.pending::before, .badge.overdue::before { background: var(--warning-dot) }
.badge.connecting::before { background: var(--info-dot) }
.badge.disconnected::before, .badge.offline::before, .badge.blocked::before, .badge.billing_blocked::before, .badge.late::before { background: var(--danger-dot) }
.badge.disconnected, .badge.offline, .badge.blocked, .badge.billing_blocked, .badge.late { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg) }
.badge.logged_out, .badge.suspended, .badge.inactive, .badge.canceled { color: var(--muted-foreground) }
.badge.qr_pending::before, .badge.connecting::before { animation: qf-pulse 1.4s ease-in-out infinite }
@keyframes qf-pulse { 50% { opacity: .35 } }

/* ── Tabela ── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; background: var(--card); -webkit-overflow-scrolling: touch }
table { width: 100%; border-collapse: collapse; font-size: 13px }
th { text-align: left; height: 40px; padding: 0 14px; font-size: 12.5px; font-weight: 500; color: var(--muted-foreground); border-bottom: 1px solid var(--border); white-space: nowrap }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle }
tbody tr:last-child td { border-bottom: none }
tbody tr:hover td { background: color-mix(in srgb, var(--secondary) 55%, transparent) }

/* ── Campos rótulo/valor ── */
.field-row, .row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-width: 0; min-height: 26px }
.field-label, .row .k { font-size: 12.5px; color: var(--muted-foreground); min-width: 86px; flex: none }
.field-value, .row .v { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.field-value.plain { font-family: inherit; font-size: 13px }

/* ── Ações no rodapé do cartão ── */
.card-footer, .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border) }
.card-footer .spacer { flex: 1 }

/* ── Segredo copiável e avisos ── */
.secret {
  display: flex; gap: 8px; align-items: center; margin-top: 6px;
  background: var(--secondary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 8px 8px 12px; font-family: var(--font-mono); font-size: 12px; word-break: break-all;
}
.secret span { flex: 1; min-width: 0 }
.warnbox, .modal .warn { background: var(--warning-bg); border: 1px solid var(--warning-border); color: var(--warning); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-top: 14px; line-height: 1.45 }

/* ── Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: var(--overlay); padding: 6vh 16px; overflow-y: auto;
  align-items: flex-start; justify-content: center;
}
.modal-overlay.open { display: flex; animation: qf-fade .15s ease-out }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px; width: 460px; max-width: 100%; box-shadow: var(--shadow-lg);
  animation: qf-pop .15s ease-out;
}
.modal.wide { width: 760px }
.modal h3 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 6px }
.modal p { color: var(--muted-foreground); font-size: 13.5px; line-height: 1.55 }
.modal .table-wrap { margin-top: 12px }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 24px; flex-wrap: wrap }
@keyframes qf-fade { from { opacity: 0 } }
@keyframes qf-pop { from { opacity: 0; transform: translateY(6px) scale(.98) } }

/* ── Toast ── */
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 200; max-width: calc(100vw - 32px);
  background: var(--card); color: var(--foreground); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none }

/* ── Celular ── */
@media (max-width: 560px) {
  .topbar-inner { padding: 8px 16px; gap: 8px 10px }
  .brand-tag { display: none }
  .topbar .who { order: 10; flex-basis: 100%; max-width: none }
  .modal { padding: 20px 16px }
  .modal-overlay { padding: 16px 12px }
  .modal-actions > button { flex: 1 1 auto }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none }
  .card { padding: 16px }
  .field-label, .row .k { min-width: 72px }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important }
}
