/* Central — cada sistema é uma fibra do código de cores ABNT. */
/* Fontes hospedadas no próprio painel (Barlow, licença OFL) */
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/barlow-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/barlow-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/barlow-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Semi Condensed'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/barlow-semi-condensed-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Semi Condensed'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/barlow-semi-condensed-latin-600-normal.woff2') format('woff2'); }
:root {
  --bg: #E9EDF1;
  --surface: #FFFFFF;
  --sunken: #DFE4EA;
  --ink: #18222E;
  --ink-2: #44505F;
  --muted: #667283;
  --line: #CFD6DE;
  --line-strong: #AEB8C4;
  --focus: #2F6FDB;
  --danger: #C13A32;
  --danger-soft: #FBEAE8;
  --ok: #23824A;
  --primary: #18222E;
  --primary-ink: #FFFFFF;
  --pulse: rgba(255, 255, 255, .9);
  --radius: 6px;
  --side-w: 252px;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-cond: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F151C;
    --surface: #161E27;
    --sunken: #0B1015;
    --ink: #E3E8EE;
    --ink-2: #B3BDC9;
    --muted: #8692A1;
    --line: #25303C;
    --line-strong: #3A4757;
    --focus: #6FA0F0;
    --danger: #F0705F;
    --danger-soft: #36171340;
    --ok: #4CC27A;
    --primary: #E3E8EE;
    --primary-ink: #0F151C;
    --pulse: rgba(255, 255, 255, .95);
    color-scheme: dark;
  }
  [data-fiber="9"] { --fiber: #3E4754; --fiber-edge: #7D8A99; }
}

/* Código de cores ABNT (fibras 1–12) */
[data-fiber="1"]  { --fiber: #2E9D57; }
[data-fiber="2"]  { --fiber: #E3B819; }
[data-fiber="3"]  { --fiber: #F4F6F8; --fiber-edge: #9AA6B2; }
[data-fiber="4"]  { --fiber: #2F6FDB; }
[data-fiber="5"]  { --fiber: #D63A3A; }
[data-fiber="6"]  { --fiber: #8350C6; }
[data-fiber="7"]  { --fiber: #8A5A34; }
[data-fiber="8"]  { --fiber: #E688AE; }
[data-fiber="9"]  { --fiber: #232A33; --fiber-edge: #6B7787; }
[data-fiber="10"] { --fiber: #7D8996; }
[data-fiber="11"] { --fiber: #EE8A25; }
[data-fiber="12"] { --fiber: #22B3C0; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.boot { padding: 40px; color: var(--muted); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Botões e campos ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.quiet { border-color: transparent; background: transparent; padding: 0 10px; color: var(--ink-2); }
.btn.quiet:hover { background: var(--sunken); color: var(--ink); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 14px; }
.btn svg { width: 17px; height: 17px; flex: none; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.field { display: grid; gap: 5px; margin-bottom: 16px; align-content: start; }
.field > label, .field > .label { font-weight: 500; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
input:disabled { background: var(--sunken); color: var(--muted); }
textarea { min-height: 72px; resize: vertical; }
.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--primary); flex: none; }
.error-msg { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 9px 12px; margin: 0 0 16px; font-size: 14px; }
.code-input { font-family: var(--font-cond); font-size: 26px !important; letter-spacing: .35em; text-align: center; }

/* ── Telas de entrada ──────────────────────────────────────────────── */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 400px; }
.gate-mark { display: grid; gap: 5px; margin-bottom: 28px; }
.gate-mark span { display: block; height: 4px; border-radius: 2px; background: var(--fiber); }
.gate-mark span:nth-child(1) { width: 100%; }
.gate-mark span:nth-child(2) { width: 82%; }
.gate-mark span:nth-child(3) { width: 64%; }
.gate h1 { font-family: var(--font-cond); font-weight: 600; font-size: 30px; line-height: 1.1; margin: 0 0 6px; }
.gate p.lead { color: var(--ink-2); margin: 0 0 24px; }
.gate form .btn.primary { width: 100%; justify-content: center; min-height: 44px; margin-top: 4px; }
.qr { display: grid; place-items: center; background: #fff; border-radius: var(--radius); padding: 12px; width: max-content; margin: 0 auto 14px; border: 1px solid var(--line); }
.qr svg { display: block; width: 188px; height: 188px; }
.secret { font-family: var(--font-cond); font-size: 17px; letter-spacing: .08em; text-align: center; word-break: break-all; color: var(--ink-2); margin: 0 0 20px; }

/* ── Estrutura ─────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.shell.collapsed { --side-w: 66px; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px 12px 8px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-cond); font-weight: 600; font-size: 21px; }
.brand-mark { display: grid; gap: 3px; width: 22px; }
.brand-mark span { height: 3px; border-radius: 2px; background: var(--fiber); }
.side nav { display: grid; gap: 1px; }
.nav-group { font-size: 13px; color: var(--muted); padding: 16px 10px 4px; font-weight: 500; }
.nav-item {
  display: flex; align-items: center; gap: 11px; min-height: 36px; padding: 0 10px;
  border-radius: var(--radius); text-decoration: none; color: var(--ink-2);
}
.nav-item:hover { background: var(--sunken); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--sunken); color: var(--ink); font-weight: 500; }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .ext { width: 14px; height: 14px; color: var(--muted); flex: none; }
.nav-item .glyph { width: 18px; height: 18px; flex: none; display: grid; place-items: center; color: var(--muted); }
.nav-item .glyph svg { width: 18px; height: 18px; }
.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 1px; }
.who { padding: 6px 10px 8px; font-size: 14px; }
.who b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: 13px; }
.shell.collapsed .label, .shell.collapsed .nav-group, .shell.collapsed .who, .shell.collapsed .brand-name, .shell.collapsed .nav-item .ext { display: none; }
.shell.collapsed .nav-item { justify-content: center; padding: 0; }
.shell.collapsed .side-head { flex-direction: column; padding: 0 0 12px; }

/* Tubo da fibra: aceso = cor cheia; apagado = só contorno; sem endereço = tracejado */
.tube { width: 5px; height: 18px; border-radius: 3px; flex: none; background: var(--fiber); box-shadow: inset 0 0 0 1px var(--fiber-edge, transparent); }
.tube[data-state="down"] { background: transparent; box-shadow: inset 0 0 0 1.5px var(--fiber); }
.tube[data-state="idle"] { background: transparent; box-shadow: none; border: 1.5px dashed var(--line-strong); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  min-height: 60px; display: flex; align-items: center; gap: 14px;
  padding: 10px 28px; border-bottom: 1px solid var(--line);
}
.top h1 { font-family: var(--font-cond); font-weight: 600; font-size: 24px; line-height: 1.15; margin: 0; flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.top h1 .sub { font-family: var(--font); font-weight: 400; font-size: 15px; color: var(--muted); }
.menu-btn { display: none; }
.content { padding: 26px 28px 60px; max-width: 1180px; width: 100%; }
.content.full { max-width: none; padding: 0; flex: 1; display: flex; flex-direction: column; }
.lead { color: var(--ink-2); margin: 0 0 22px; max-width: 70ch; }
h2.section { font-family: var(--font-cond); font-weight: 600; font-size: 19px; margin: 36px 0 12px; }

/* ── Início: fios dos sistemas ─────────────────────────────────────── */
.summary { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.summary p { margin: 0; flex: 1; min-width: 240px; color: var(--ink-2); }
.summary p strong { color: var(--ink); font-weight: 600; }
.strands { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.strand {
  display: grid; grid-template-columns: minmax(150px, 210px) minmax(0, 1fr) 132px;
  align-items: center; gap: 22px; padding: 14px 20px; text-decoration: none;
}
.strand + .strand { border-top: 1px solid var(--line); }
.strand:hover { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
.strand-name b { display: block; font-weight: 600; font-size: 16px; }
.strand-name span { color: var(--muted); font-size: 13px; }
.strand-name .down { color: var(--danger); font-weight: 500; }
.fiber { position: relative; display: flex; gap: 2px; height: 8px; align-items: center; overflow: hidden; border-radius: 4px; }
.seg { flex: 1; height: 6px; border-radius: 1px; background: var(--fiber); box-shadow: inset 0 0 0 1px var(--fiber-edge, transparent); }
.seg.dim { opacity: .4; }
.seg.cut { background: transparent; box-shadow: inset 0 0 0 1.5px var(--danger); }
.seg.none { height: 0; border-top: 2px dotted var(--line-strong); background: none; box-shadow: none; }
@media (prefers-color-scheme: dark) {
  .seg.lit { box-shadow: 0 0 6px color-mix(in srgb, var(--fiber) 55%, transparent), inset 0 0 0 1px var(--fiber-edge, transparent); }
}
.strand[data-state="lit"] .fiber::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -20%; width: 18%;
  background: linear-gradient(90deg, transparent, var(--pulse), transparent);
  opacity: .75; pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .strand[data-state="lit"] .fiber::after { animation: light 4.2s linear infinite; animation-delay: var(--delay, 0s); }
}
@keyframes light { to { left: 102%; } }
.metrics { text-align: right; font-size: 14px; line-height: 1.3; }
.metrics b { font-family: var(--font-cond); font-weight: 600; font-size: 18px; }
.metrics span { display: block; color: var(--muted); font-size: 13px; }
.legend { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }
.idle-list { margin-top: 26px; color: var(--ink-2); }
.idle-list ul { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.idle-list li > a, .idle-list li > span {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 10px;
  border: 1px dashed var(--line-strong); border-radius: 20px; text-decoration: none; font-size: 14px;
}
.idle-list li > a:hover { border-color: var(--ink-2); }

/* ── Tabelas ───────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
td .cell-title { display: flex; align-items: center; gap: 10px; font-weight: 500; }
td .cell-sub { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12.5px; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.tag.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.tag.bad { color: var(--danger); background: var(--danger-soft); }
.muted { color: var(--muted); }
.empty { padding: 34px 20px; text-align: center; color: var(--ink-2); }
.empty p { margin: 0 0 14px; }

/* ── Formulários de gestão ─────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 22px; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: none; padding: 0; margin: 0 0 30px; max-width: 760px; }
legend { font-family: var(--font-cond); font-weight: 600; font-size: 19px; padding: 0; margin-bottom: 4px; }
fieldset > p.hint { color: var(--muted); margin: 0 0 16px; font-size: 14px; max-width: 64ch; }
.swatches { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; }
.swatch label {
  display: grid; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; background: var(--surface);
}
.swatch label i { display: block; height: 6px; border-radius: 3px; background: var(--fiber); box-shadow: inset 0 0 0 1px var(--fiber-edge, transparent); }
.swatch input:checked + label { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.swatch input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }
.access-list { display: grid; gap: 6px; margin-top: 6px; }
.access-row { display: flex; align-items: center; gap: 12px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.access-row .check { flex: 1; align-items: center; }
.access-row .check input { margin: 0; }
.access-row select { width: auto; min-height: 32px; padding: 3px 8px; font-size: 14px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 6px; max-width: 760px; }
.form-actions .push { margin-left: auto; }
.inline-result { margin: 0 0 18px; font-size: 14px; }
.callout { border: 1px solid var(--line-strong); border-radius: 8px; padding: 16px 18px; background: var(--surface); margin-bottom: 22px; }
.callout h3 { margin: 0 0 6px; font-family: var(--font-cond); font-weight: 600; font-size: 18px; }
.keybox { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.keybox code { flex: 1; padding: 9px 11px; background: var(--sunken); border-radius: var(--radius); font-size: 14px; word-break: break-all; }
pre.example { background: var(--sunken); border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; font-size: 13px; margin: 8px 0 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters > * { width: auto; min-width: 170px; }
.more { display: flex; justify-content: center; padding: 16px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 22px; margin: 0 0 30px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* ── Sistema aberto ────────────────────────────────────────────────── */
.app-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.frame { flex: 1; border: 0; width: 100%; min-height: calc(100vh - 61px); background: var(--surface); }
.frame-note { padding: 8px 28px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.blocked { padding: 34px 28px; max-width: 760px; }
.blocked h2 { font-family: var(--font-cond); font-weight: 600; font-size: 22px; margin: 0 0 8px; }
.blocked p { color: var(--ink-2); margin: 0 0 20px; max-width: 64ch; }
.facts-row { display: flex; gap: 34px; flex-wrap: wrap; margin: 26px 0 0; padding-top: 20px; border-top: 1px solid var(--line); }
.facts-row div span { display: block; color: var(--muted); font-size: 13px; }
.facts-row div b { font-family: var(--font-cond); font-weight: 600; font-size: 22px; }

/* ── Avisos e diálogo ──────────────────────────────────────────────── */
#toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 360px;
  background: var(--primary); color: var(--primary-ink); border-radius: var(--radius);
  padding: 11px 16px; font-size: 14px; opacity: 0; transform: translateY(8px);
  transition: opacity .18s, transform .18s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.bad { background: var(--danger); color: #fff; }
dialog { border: 1px solid var(--line-strong); border-radius: 10px; padding: 22px 24px; max-width: 420px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 16, 22, .45); }
dialog h3 { margin: 0 0 8px; font-family: var(--font-cond); font-weight: 600; font-size: 20px; }
dialog p { margin: 0 0 20px; color: var(--ink-2); }
dialog .row-actions { justify-content: flex-end; }

/* ── Celular ───────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell, .shell.collapsed { grid-template-columns: minmax(0, 1fr); --side-w: 280px; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: var(--side-w); transform: translateX(-102%); transition: transform .2s; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 16, 22, .45); }
  .shell.collapsed .label, .shell.collapsed .nav-group, .shell.collapsed .who, .shell.collapsed .brand-name { display: revert; }
  .shell.collapsed .nav-item { justify-content: flex-start; padding: 0 10px; }
  .collapse-btn { display: none; }
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 20px 16px 48px; }
  .strand { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; padding: 14px 16px; }
  .strand .fiber { grid-column: 1 / -1; grid-row: 2; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .swatches { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .frame-note, .blocked { padding-left: 16px; padding-right: 16px; }
  .filters > * { flex: 1; min-width: 140px; }
}
