/* Painel SBC-SPEED. Azul-petróleo (cabo/central telefônica) como destaque; fontes do sistema (CSP bloqueia fontes externas). */
:root {
  --bg: #F3F5F7; --surface: #FFFFFF; --surface-2: #F7F9FA; --ink: #16202A; --muted: #56636F; --line: #D5DCE3;
  --accent: #0E6E74; --accent-ink: #FFFFFF; --accent-soft: #DDEFEF;
  --ok: #1B7F4B; --ok-soft: #DFF2E7; --warn: #8A5300; --warn-soft: #FBEBD3; --err: #B3261E; --err-soft: #F9DEDC;
  --side: #102A30; --side-ink: #D7E7E8; --side-muted: #8FB2B5; --side-active: #1C434A;
  --radius: 10px; --radius-sm: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1A21; --surface: #16242D; --surface-2: #1B2C36; --ink: #E6EDF2; --muted: #9AAAB6; --line: #2A3B47;
    --accent: #4FB8BF; --accent-ink: #062226; --accent-soft: #163C42;
    --ok: #6FD39C; --ok-soft: #173A29; --warn: #F2B65A; --warn-soft: #3D2E14; --err: #F2B8B5; --err-soft: #4A1F1C;
    --side: #0E2A2F; --side-ink: #D7E7E8; --side-muted: #8FB2B5; --side-active: #1A4950;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1A21; --surface: #16242D; --surface-2: #1B2C36; --ink: #E6EDF2; --muted: #9AAAB6; --line: #2A3B47;
  --accent: #4FB8BF; --accent-ink: #062226; --accent-soft: #163C42;
  --ok: #6FD39C; --ok-soft: #173A29; --warn: #F2B65A; --warn-soft: #3D2E14; --err: #F2B8B5; --err-soft: #4A1F1C;
  --side: #0E2A2F; --side-ink: #D7E7E8; --side-muted: #8FB2B5; --side-active: #1A4950;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.25rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); font-size: .875rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 30; background: var(--surface); padding: 6px 10px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.spacer { flex: 1; }

/* ---------- marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; font-size: 1.05rem; }
/* três barras de sinal: o assunto do sistema (chamadas saindo pela rede móvel) */
.brand-mark { width: 18px; height: 16px; flex: none;
  background: linear-gradient(currentColor, currentColor) 0 100% / 4px 6px no-repeat,
              linear-gradient(currentColor, currentColor) 7px 100% / 4px 11px no-repeat,
              linear-gradient(currentColor, currentColor) 14px 100% / 4px 16px no-repeat; color: var(--accent); }

/* ---------- login ---------- */
#login-view { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); padding: 28px; }
.brand-login { font-size: 1.3rem; margin-bottom: 2px; }
.login-card .brand-mark { color: var(--accent); }
.login-card label { margin-top: 14px; }

/* ---------- estrutura: menu lateral + conteúdo ---------- */
#app-view { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
#sidebar { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#sidebar .brand { padding: 0 10px; color: #fff; }
#sidebar .brand-mark { color: #6CC9CF; }
#tabs { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .78rem; color: var(--side-muted); padding: 14px 10px 4px; }
#tabs button { all: unset; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--side-ink); font-size: .93rem; }
#tabs button svg { width: 18px; height: 18px; flex: none; opacity: .85; }
#tabs button:hover { background: var(--side-active); }
#tabs button[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #6CC9CF; }
#tabs button:focus-visible { outline: 2px solid #6CC9CF; outline-offset: 1px; }

/* trilho de chipeiras: estado de cada uma, sempre à vista */
#rail { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding: 14px 10px 0; }
#rail h2 { font-size: .78rem; font-weight: 600; color: var(--side-muted); margin-bottom: 8px; }
#rail ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#rail li { display: flex; align-items: center; gap: 8px; font-size: .85rem; min-width: 0; }
#rail .gw-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rail .gw-state { font-size: .75rem; color: var(--side-muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #7F9FA3; }
.dot.ok { background: #4CC38A; } .dot.warn { background: #F2B65A; } .dot.err { background: #F0726B; }

#shell { min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; }
#who { color: var(--muted); font-size: .875rem; }
main { padding: 20px 24px 40px; max-width: 1240px; width: 100%; }
main > section, #cl-list, #cl-detail { display: flex; flex-direction: column; gap: 16px; }
#cd-back { align-self: flex-start; }
#menu-btn { display: none; }

/* ---------- cartões ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card > .card-head:not(:first-child) { margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
/* Resumo: a tabela por chipeira (5 colunas) pede mais largura que a de recusas */
#tab-resumo .grid2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
@media (max-width: 1100px) { #tab-resumo .grid2 { grid-template-columns: 1fr; } }

/* indicadores: o número é o protagonista */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.kpi .v { font-size: 1.85rem; font-weight: 650; line-height: 1.15; }
.kpi .k { color: var(--muted); font-size: .85rem; }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); } .kpi.err .v { color: var(--err); }

/* ---------- tabelas ---------- */
.tw { overflow-x: auto; margin: 0 -2px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--surface-2); }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.num, td.num { text-align: right; }
td > span { display: inline-flex; gap: 6px; flex-wrap: wrap; }
td.empty { color: var(--muted); font-size: .9rem; padding: 14px 10px; }

/* etiquetas de situação: sempre com texto, nunca só cor */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); } .badge.muted { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

/* ---------- formulários e botões ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
input, select { font: inherit; padding: 7px 10px; width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); min-height: 38px; }
input:focus, select:focus { border-color: var(--accent); }
form.row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-top: 12px; }
form.row .f { min-width: 140px; }
form.row input, form.row select { width: auto; min-width: 140px; }
form.stack { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.row-title { width: 100%; }
button, .btn-link { font: inherit; font-size: .9rem; padding: 7px 14px; min-height: 36px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
button.danger:hover { background: var(--err-soft); border-color: var(--err); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); border-color: var(--line); }
button.wide { width: 100%; margin-top: 18px; }
.btn-link { display: inline-flex; align-items: center; text-decoration: none; color: var(--accent); border-color: var(--accent); }
.icon-btn { padding: 6px; min-height: 36px; min-width: 36px; display: inline-grid; place-items: center; background: transparent; border-color: transparent; }
.icon-btn svg { width: 20px; height: 20px; }
.pager { display: inline-flex; gap: 6px; }
/* Autenticação da rota: duas opções lado a lado, como um interruptor */
fieldset.seg { border: 0; padding: 0; margin: 0; display: inline-flex; flex-wrap: wrap; align-items: flex-end; gap: 0; }
fieldset.seg legend { font-size: .85rem; font-weight: 600; padding: 0; margin-bottom: 4px; }
fieldset.seg label { margin: 0; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; min-height: 38px; padding: 0 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
fieldset.seg label:first-of-type { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
fieldset.seg label:last-of-type { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }
fieldset.seg label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
form.row fieldset.seg input { width: auto; min-width: 0; min-height: 0; margin: 0; accent-color: var(--accent); }
/* Lista de rotas: ações numa linha só (a tabela rola para o lado no celular); segunda linha discreta na célula */
#rt-body td > span { flex-wrap: nowrap; }
td .sub { display: block; color: var(--muted); font-size: .8rem; }
/* Campos da conta do tronco: linha própria, com recuo marcando que pertencem a "Por registro" */
.row-group { width: 100%; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
  padding: 10px 0 2px 12px; border-left: 3px solid var(--accent-soft); }
/* Rotas permitidas do cliente: etiquetas marcáveis */
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tags label { margin: 0; display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font-weight: 500; cursor: pointer; }
.tags label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.tags label:has(input:disabled) { cursor: default; }
.tags input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.tags .muted { font-weight: 400; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); font: .9rem/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ---------- mensagens e alertas ---------- */
.msg { margin: 0; min-height: 0; font-size: .92rem; }
.msg:empty { display: none; }
.msg.err, .msg.ok, .msg.warn { padding: 8px 12px; border-radius: var(--radius-sm); border-left: 4px solid; }
.msg.err { background: var(--err-soft); color: var(--err); } .msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
#login-msg { margin-top: 12px; }
#alerts:empty { display: none; }
#alerts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.alert { margin: 0; padding: 9px 12px; border-radius: var(--radius-sm); border-left: 5px solid; font-weight: 600; font-size: .92rem;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.alert.critical { border-color: var(--err); background: var(--err-soft); color: var(--err); }
.alert.warning { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }

/* ---------- celular: menu vira gaveta ---------- */
@media (max-width: 860px) {
  #app-view { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%);
    transition: transform .18s ease, visibility 0s linear .18s; visibility: hidden; }
  /* fechada, a gaveta sai também da ordem do Tab (visibility), não só da tela */
  #sidebar.open { transform: none; visibility: visible; transition: transform .18s ease; }
  /* Resumo no celular: Chipeira, ASR e ACD cabem sem rolar para o lado */
  #tab-resumo .grid2 > .card:first-child th:nth-child(2), #tab-resumo .grid2 > .card:first-child td:nth-child(2),
  #tab-resumo .grid2 > .card:first-child th:nth-child(3), #tab-resumo .grid2 > .card:first-child td:nth-child(3) { display: none; }
  /* Rotas no celular: nome, situação e chamadas à vista; destino e autenticação ficam no Editar */
  #tab-rotas th:nth-child(2), #rt-body td:nth-child(2), #tab-rotas th:nth-child(3), #rt-body td:nth-child(3) { display: none; }
  /* Destinos no celular: nome, ação e situação à vista; prefixos e clientes ficam no Editar */
  #tab-destinos th:nth-child(3), #ds-body td:nth-child(3), #tab-destinos th:nth-child(5), #ds-body td:nth-child(5) { display: none; }
  #scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.4); }
  #menu-btn { display: inline-grid; }
  #topbar { padding: 10px 12px; gap: 8px; }
  #who { display: none; }
  main { padding: 14px 12px 32px; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  form.row .f, form.row input, form.row select { min-width: 0; width: 100%; }
  form.row .f { flex: 1 1 100%; }
  .row-group .f { flex: 1 1 100%; min-width: 0; }
  .row-group input { width: 100%; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { #sidebar { transition: none; } }

/* Destinos: campo de prefixos mais largo */
form.row .f-wide { flex: 1 1 280px; }
form.row .f-wide input { width: 100%; }

/* 2FA: chave para digitar no aplicativo; tela de ativação um pouco mais larga que o login */
pre.secret { font-size: 1.15rem; letter-spacing: .08em; text-align: center; user-select: all; }
.setup-card { width: min(520px, 100%); }
.setup-card h1 { margin: 14px 0 8px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 14px; }
label.check input { width: auto; min-height: 0; accent-color: var(--accent); }
#mfa-setup { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
