:root {
  --bg:        #0b1020;
  --bg-2:      #121a33;
  --panel:     #151d38;
  --panel-2:   #1b2547;
  --line:      #26325c;
  --text:      #e7ecff;
  --muted:     #93a0c8;
  --primary:   #4f7cff;
  --primary-2: #3a63d8;
  --ok:        #2fbf71;
  --warn:      #f0a92a;
  --err:       #ef4d6a;
  --info:      #34c3e8;
  --radius:    12px;
  --shadow:    0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

/* Regra de autor vence a folha do navegador: sem isto, o `display:grid` de
   #app e .login-wrap anula o atributo `hidden` e as duas telas se sobrepõem. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .6rem; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- login */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1000px 600px at 20% -10%, #1c2a5c 0%, var(--bg) 60%);
}
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 2rem; box-shadow: var(--shadow);
}
.login-logo { font-size: 40px; text-align: center; }
.login-card h1 { text-align: center; margin-bottom: .1rem; }
.login-card > p { text-align: center; margin: 0 0 1.4rem; }
.login-card label { display: block; margin-bottom: .9rem; font-size: 13px; color: var(--muted); }

/* --------------------------------------------------------- estrutura */
#app { display: grid; grid-template-columns: 244px 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.15rem 1.2rem; font-weight: 700; }
.brand-icon { font-size: 20px; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: .4rem .6rem; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: 9px;
  color: var(--muted); cursor: pointer; font-size: 14px; user-select: none;
}
.nav-item i { font-style: normal; width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active i { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--line); padding: .8rem 1rem; }
.saldo-box { display: flex; flex-direction: column; margin-bottom: .6rem; }
.saldo-box strong { font-size: 22px; line-height: 1.2; }
.user-box { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }

main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: .8rem; padding: .9rem 1.4rem;
  border-bottom: 1px solid var(--line); background: rgba(11,16,32,.8);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 17px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.live { color: var(--muted); font-size: 11px; }
.live.on { color: var(--ok); }
.view { padding: 1.4rem; max-width: 1400px; width: 100%; }

/* ---------------------------------------------------------- controles */
input, select, textarea {
  width: 100%; padding: .58rem .7rem; margin-top: .25rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
label { display: block; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 14px; margin: .35rem 0; }
.check input { width: auto; margin: 0; accent-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem .95rem; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: rgba(239,77,106,.12); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: .4rem; }
.btn.sm { padding: .3rem .6rem; font-size: 12.5px; }
.iconbtn { background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.linkbtn { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }

/* ------------------------------------------------------------- blocos */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem;
}
.card > h3 { display: flex; align-items: center; gap: .5rem; }
.card-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .9rem; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row { display: flex; gap: .7rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .shrink { flex: 0 0 auto; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; line-height: 1.25; }
.stat .sub { color: var(--muted); font-size: 12.5px; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.err .value { color: var(--err); }
.stat.info .value { color: var(--info); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }
/* Precisa rolar nos dois eixos e ter altura máxima, senão o `th` sticky
   nunca gruda: o wrapper vira o scrollport e cresce junto com o conteúdo. */
.table-wrap { overflow: auto; max-height: 72vh; border-radius: var(--radius); border: 1px solid var(--line); }
.table-wrap table { min-width: 640px; }
.table-wrap th { background: var(--bg-2); position: sticky; top: 0; z-index: 1; }

.chip {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.ok    { color: var(--ok);   border-color: rgba(47,191,113,.4);  background: rgba(47,191,113,.12); }
.chip.warn  { color: var(--warn); border-color: rgba(240,169,42,.4);  background: rgba(240,169,42,.12); }
.chip.err   { color: var(--err);  border-color: rgba(239,77,106,.4);  background: rgba(239,77,106,.12); }
.chip.info  { color: var(--info); border-color: rgba(52,195,232,.4);  background: rgba(52,195,232,.12); }
.badge {
  background: var(--err); color: #fff; border-radius: 999px;
  padding: 0 .4rem; font-size: 11px; font-weight: 700; margin-left: auto;
}

.alert { padding: .7rem .9rem; border-radius: 9px; margin: .6rem 0; font-size: 13.5px; border: 1px solid; }
.alert.error { background: rgba(239,77,106,.1); border-color: rgba(239,77,106,.4); color: #ffb9c5; }
.alert.ok    { background: rgba(47,191,113,.1); border-color: rgba(47,191,113,.4); color: #a6f0c8; }
.alert.info  { background: rgba(79,124,255,.1); border-color: rgba(79,124,255,.4); color: #c3d3ff; }
.alert.warn  { background: rgba(240,169,42,.1); border-color: rgba(240,169,42,.4); color: #ffdf9e; }

.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--info)); transition: width .4s; }

.pill-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.pager { display: flex; gap: .5rem; align-items: center; justify-content: flex-end; margin-top: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

.counter { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: .4rem; }
.counter b { color: var(--text); }
.counter.over b { color: var(--warn); }

.copy-field { display: flex; gap: .4rem; align-items: center; }
.copy-field input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* -------------------------------------------------------------- toasts */
/* pointer-events:none no container — ele cobre o canto inferior direito, onde
   ficam os botões do modal, e engolia os cliques enquanto um toast estava vivo. */
#toasts {
  position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column;
  gap: .5rem; z-index: 200; pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--primary);
  padding: .7rem .9rem; border-radius: 9px; box-shadow: var(--shadow);
  max-width: 380px; font-size: 13.5px; animation: slidein .22s ease; pointer-events: auto;
}
.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn{ border-left-color: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }

/* --------------------------------------------------------------- modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(4,7,18,.7); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 150; padding: 1rem;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.3rem; width: min(620px, 100%); max-height: 88dvh; overflow: auto; box-shadow: var(--shadow);
}
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.1rem; }

/* -------------------------------------------------------------- gráfico */
/* height:auto + proporção preservada no SVG: com preserveAspectRatio="none" os
   rótulos saíam esticados no desktop e ilegíveis no celular. */
.chart { width: 100%; height: auto; }
.chart .bar { fill: var(--primary); }
.chart .bar.ok { fill: var(--ok); }
.chart text { fill: var(--muted); font-size: 10px; }
.chart line { stroke: var(--line); }

/* ------------------------------------------------------------ mobile */
.only-mobile { display: none; }
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 100; width: 260px; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-block; }
  .view { padding: 1rem; }
}
