/* consultanumero — design system dos apps internos do LIA.
   light = AUSÊNCIA de data-theme. Tokens sempre em par (--surface-X / --on-X). */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --on-primary: #ffffff;
  --surface-ok: #dcfce7;      --on-ok: #166534;
  --surface-warn: #fef3c7;    --on-warn: #92400e;
  --surface-danger: #fee2e2;  --on-danger: #991b1b;
  --surface-info: #dbeafe;    --on-info: #1e40af;
  --surface-accent: #ede9fe;  --on-accent: #5b21b6;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.05);
  --sidebar-bg: #0f172a;
  --sidebar-on: #e2e8f0;
  --sidebar-on-muted: #94a3b8;
  --sidebar-active: rgba(59,130,246,.18);
  --sidebar-brand: #ffffff;
  --code-bg: #0f172a;
  --code-on: #e2e8f0;
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111c31;
  --surface-2: #16233c;
  --border: #24334d;
  --text: #e6edf7;
  --muted: #93a4bd;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --on-primary: #ffffff;
  --surface-ok: rgba(22,163,74,.20);     --on-ok: #86efac;
  --surface-warn: rgba(217,119,6,.20);   --on-warn: #fcd34d;
  --surface-danger: rgba(220,38,38,.20); --on-danger: #fca5a5;
  --surface-info: rgba(37,99,235,.22);   --on-info: #93c5fd;
  --surface-accent: rgba(124,58,237,.22);--on-accent: #c4b5fd;
  --input-bg: #0d1728;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --sidebar-bg: #070d18;
  --sidebar-on: #e2e8f0;
  --sidebar-on-muted: #8fa1ba;
  --sidebar-active: rgba(59,130,246,.22);
  --sidebar-brand: #ffffff;
  --code-bg: #060c16;
  --code-on: #dbe6f5;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); }
.hidden { display: none !important; }

/* ── controles ───────────────────────────────────────────────────────────── */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--input-bg); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.16);
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 16px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-weight: 600; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { background: var(--surface-danger); border-color: transparent; color: var(--on-danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

/* ── layout ──────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--sidebar-bg); color: var(--sidebar-on);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--sidebar-brand); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background-color: #1d4ed8; background-image: linear-gradient(135deg,#1d4ed8,#0ea5e9); display: grid; place-items: center; flex: 0 0 auto; }
.brand-mark svg { width: 19px; height: 19px; color: #fff; }
.brand-txt { min-width: 0; }
.brand-txt b { display: block; font-size: 14.5px; line-height: 1.2; }
.brand-txt span { font-size: 11px; color: var(--sidebar-on-muted); }
.navitem {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: var(--sidebar-on-muted); cursor: pointer; font-weight: 600; font-size: 13.5px; border: none; background: none; width: 100%; text-align: left;
}
.navitem svg { width: 17px; height: 17px; flex: 0 0 auto; }
.navitem:hover { background: rgba(148,163,184,.12); color: var(--sidebar-on); }
.navitem.active { background: var(--sidebar-active); color: var(--sidebar-on); }
.navitem .pill { margin-left: auto; background: var(--surface-danger); color: var(--on-danger); border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
.sidefoot { margin-top: auto; border-top: 1px solid rgba(148,163,184,.18); padding-top: 12px; }
.userline {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; min-width: 0;
  /* é <button> (abre "Meu perfil"): sem este reset vem com fundo e cor do browser */
  width: 100%; background: none; border: none; border-radius: 9px;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.userline:hover { background: rgba(148,163,184,.12); }
.avatar { width: 30px; height: 30px; border-radius: 999px; background-color: #1d4ed8; background-image: linear-gradient(135deg,#1d4ed8,#0ea5e9); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.userline div { min-width: 0; }
.userline b { display: block; font-size: 12.5px; color: var(--sidebar-on); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userline span { font-size: 11px; color: var(--sidebar-on-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.content { flex: 1 1 auto; min-width: 0; padding: 26px 30px 60px; }

.topbar { display: none; align-items: center; gap: 10px; padding: 10px 14px; background: var(--sidebar-bg); color: var(--sidebar-on); position: sticky; top: 0; z-index: 30; }
.sechead { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.sechead h1 { font-size: 21px; margin: 0 0 3px; }
.sechead p { margin: 0; color: var(--muted); font-size: 13px; }
.sechead .acts { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.filterbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.fgroup { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.flabel { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.grid-2 > .card + .card, .grid-3 > .card + .card, .grid-4 > .card + .card { margin-top: 0; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 14px; align-items: start; }
/* cards de perfil: mesma altura na linha (o rodapé usa margin-top:auto) */
.grid-2:has(.perfilcard) { align-items: stretch; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }

/* ── kpi ─────────────────────────────────────────────────────────────────── */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .kpitop { display: flex; align-items: center; gap: 9px; }
.kpi .ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: 0 0 auto; background: var(--surface-info); color: var(--on-info); }
.kpi .ico svg { width: 17px; height: 17px; }
.kpi .lbl { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); min-width: 0; }
.kpi .val { font-size: 25px; font-weight: 700; line-height: 1.1; }

/* ── badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--surface-ok); color: var(--on-ok); }
.badge.warn { background: var(--surface-warn); color: var(--on-warn); }
.badge.danger { background: var(--surface-danger); color: var(--on-danger); }
.badge.info { background: var(--surface-info); color: var(--on-info); }
.badge.accent { background: var(--surface-accent); color: var(--on-accent); }

/* ── tabela ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; max-width: 100%; border-radius: 11px; border: 1px solid var(--border); }
table { border-collapse: collapse; width: 100%; }
thead tr { background: var(--surface-2); }
th { text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }

/* larguras da tabela de clientes por CLASSE — inline venceria a media query.
   table-layout AUTO + coluna de ações em width:1%/nowrap: a coluna pega o
   min-content dos botões e o resto sobra pro contato. Com `fixed` a célula não
   cresce e os botões vazam pra fora do card (corte silencioso). */
.tbl-clientes { width: 100%; }
.tbl-clientes th:nth-child(1), .tbl-clientes td:nth-child(1) { width: 30%; min-width: 190px; }
.tbl-clientes th:nth-child(2), .tbl-clientes td:nth-child(2) { width: 14%; }
.tbl-clientes th:nth-child(4), .tbl-clientes td:nth-child(4),
.tbl-clientes th:nth-child(5), .tbl-clientes td:nth-child(5) { width: 1%; white-space: nowrap; }
.tbl-clientes th:nth-child(7), .tbl-clientes td:nth-child(7) { width: 1%; }
.cel-empresa { min-width: 0; overflow-wrap: anywhere; }
.cel-acoes { white-space: nowrap; text-align: right; }
.cel-acoes .btn { margin-left: 5px; }
.cel-acoes .btn.sm svg { display: none; }
@media (min-width: 1400px) { .cel-acoes .btn.sm svg { display: block; } }
.nowrap { white-space: nowrap; }
.submeta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 1100px) { .tbl-clientes { min-width: 720px; } }

/* ── consulta ────────────────────────────────────────────────────────────── */
.searchbox { display: flex; gap: 10px; flex-wrap: wrap; }
.searchbox .f { flex: 1 1 260px; min-width: 0; }
.searchbox input { font-size: 17px; padding: 13px 15px; letter-spacing: .02em; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; font-weight: 600; font-size: 13px; }
.tab.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.result-op { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.result-op .opico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-info); color: var(--on-info); flex: 0 0 auto; }
.result-op .opico svg { width: 24px; height: 24px; }
.result-op .opname { font-size: 20px; font-weight: 700; min-width: 0; overflow-wrap: break-word; }
.result-op .opnum { color: var(--muted); font-size: 13px; }
.deflist { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.deflist div { min-width: 0; }
.deflist dt { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
.deflist dd { margin: 0; overflow-wrap: break-word; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 0; color: var(--muted); font-size: 12px; margin-top: 10px; }
.meta span { white-space: nowrap; }
.meta span + span::before { content: "·"; margin: 0 7px; }

/* ── SUP: tabela larga, rola dentro do card em tela estreita ─────────────── */
.tbl-sup { width: 100%; }
.tbl-sup th:nth-child(1), .tbl-sup td:nth-child(1) { width: 1%; white-space: nowrap; }
.tbl-sup th:nth-child(4), .tbl-sup td:nth-child(4),
.tbl-sup th:nth-child(5), .tbl-sup td:nth-child(5) { width: 1%; white-space: nowrap; }
.tbl-sup th:nth-child(7), .tbl-sup td:nth-child(7),
.tbl-sup th:nth-child(8), .tbl-sup td:nth-child(8) { width: 1%; white-space: nowrap; }
/* prestadora tem nomes quilométricos ("SEM FRONTEIRAS - INTERNET BANDA LARGA"):
   sem teto ela empurra a tabela pra fora e a 1ª coluna some atrás do scroll */
.tbl-sup td:nth-child(6) { max-width: 190px; overflow-wrap: anywhere; }
.tbl-sup th:nth-child(3), .tbl-sup td:nth-child(3) { max-width: 150px; overflow-wrap: anywhere; }
@media (max-width: 1100px) { .tbl-sup { min-width: 900px; } }

/* ── admin: usuários, perfis, convites ──────────────────────────────────── */
.userchip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.userchip b { display: block; overflow-wrap: anywhere; }
img.avatar { object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 84px; height: 84px; font-size: 26px; }
.tbl-usuarios th:nth-child(5), .tbl-usuarios td:nth-child(5) { width: 1%; white-space: nowrap; }
@media (max-width: 900px) { .tbl-usuarios { min-width: 640px; } }

.perfilcard { display: flex; flex-direction: column; gap: 8px; min-height: 190px; }
.perfiltop { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.perfiltop b { font-size: 15px; }
.perfilcard .chips { display: flex; flex-wrap: wrap; gap: 5px; }
/* rótulo de permissão é frase, não etiqueta: sem isto o badge nowrap vaza o card */
.perfilcard .chips .badge { white-space: normal; text-align: left; }
.perfilfoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 10px; flex-wrap: wrap; }
.perfilfoot .btn { margin-left: 5px; }

.permgrupo { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.permline { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 13.5px; }
.permline input { width: auto; flex: 0 0 auto; }

/* dropzone: upload de arquivo nunca é <input type=file> cru */
.fotorow { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center;
  padding: 16px; border: 1.5px dashed var(--border); border-radius: 12px; background: var(--surface-2);
  cursor: pointer; color: var(--muted); font-size: 13px; min-width: 210px;
}
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--primary); color: var(--text); outline: none; }
.dropzone svg { width: 22px; height: 22px; }
.dropzone b { color: var(--primary); }

/* ── login / público ─────────────────────────────────────────────────────── */
.authwrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 22px; background: linear-gradient(135deg, var(--bg), var(--surface-2)); }
.authcard { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.authcard .brand { color: var(--text); padding: 0 0 18px; }
.authcard .brand-txt span { color: var(--muted); }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.linkbtn { background: none; border: none; color: var(--primary); cursor: pointer; font-weight: 600; padding: 0; font-size: 13px; }
.formerr { background: var(--surface-danger); color: var(--on-danger); padding: 9px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 12px; }
.formok { background: var(--surface-ok); color: var(--on-ok); padding: 9px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 12px; }

/* ── modal / toast ───────────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(2,6,23,.55); display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 15px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal header { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal header .x { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 2px 6px; }
.modal .body { padding: 18px; }
.modal footer { display: flex; gap: 9px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 9px; z-index: 200; max-width: min(360px, calc(100vw - 36px)); }
.toast { padding: 11px 15px; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13.5px; font-weight: 600; }
.toast.ok { background: var(--surface-ok); color: var(--on-ok); border-color: transparent; }
.toast.err { background: var(--surface-danger); color: var(--on-danger); border-color: transparent; }
.toast.info { background: var(--surface-info); color: var(--on-info); border-color: transparent; }

/* ── código / docs ───────────────────────────────────────────────────────── */
pre.code { background: var(--code-bg); color: var(--code-on); padding: 14px; border-radius: 11px; overflow-x: auto; font-size: 12.5px; margin: 0 0 14px; }
pre.code code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.keybox { display: flex; align-items: center; gap: 10px; background: var(--code-bg); color: var(--code-on); padding: 12px 14px; border-radius: 11px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
.keybox button { flex: 0 0 auto; }
.docsec h3 { font-size: 15px; margin: 22px 0 8px; }
.docsec h3:first-child { margin-top: 0; }
.docsec p { color: var(--muted); margin: 0 0 10px; }

/* ── responsivo ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .topbar { display: flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 35; }
  .content { padding: 18px 16px 48px; }
}
@media (max-width: 480px) {
  .content { padding: 14px 12px 44px; }
  .sechead h1 { font-size: 19px; }
  .sechead .acts { margin-left: 0; width: 100%; }
  .sechead .acts .btn { flex: 1 1 auto; justify-content: center; }
  .result-op .opname { font-size: 17px; }
  .kpi .val { font-size: 22px; }
}
