/* Painel de administracao: tema escuro por padrao, claro opcional (html[data-theme="light"]).
   Contrastes conferidos (WCAG AA) nas duas paletas. A cor de destaque vem de brand.js
   (variaveis --brand-accent e --brand-accent-light, definidas pelo app.js). */

:root {
  color-scheme: dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --topbar-h: 56px;
  --sidebar-w: 248px;
  --rail-w: 64px;

  --bg: #0a0f0d;
  --surface: #111814;
  --surface-2: #17211b;
  --surface-3: #1d2922;
  --border: #25322b;
  --border-strong: #34463c;
  --control-border: #58705f;
  --text: #e9f1ec;
  --muted: #9db0a5;

  --accent: var(--brand-accent, #34d399);
  --accent-ink: #04140c; /* texto sobre o destaque; ajuste se trocar a cor por uma bem diferente */
  --accent-pct: 14%;
  --accent-soft: rgb(52 211 153 / 0.14);

  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #60a5fa;
  --ok-bg: rgb(74 222 128 / 0.16);
  --warn-bg: rgb(251 191 36 / 0.16);
  --bad-bg: rgb(248 113 113 / 0.16);
  --info-bg: rgb(96 165 250 / 0.16);

  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.3);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f0f4f1;
  --surface-3: #e7ede9;
  --border: #dbe3de;
  --border-strong: #c3cec7;
  --control-border: #76877c;
  --text: #0e1a14;
  --muted: #4c5f55;

  --accent: var(--brand-accent-light, #047857);
  --accent-ink: #ffffff;
  --accent-pct: 10%;
  --accent-soft: rgb(4 120 87 / 0.1);

  --ok: #0c6e38;
  --warn: #7a4a00;
  --bad: #b42318;
  --info: #1a55bd;
  --ok-bg: rgb(12 110 56 / 0.12);
  --warn-bg: rgb(122 74 0 / 0.12);
  --bad-bg: rgb(180 35 24 / 0.12);
  --info-bg: rgb(26 85 189 / 0.12);

  --shadow: 0 1px 2px rgb(16 40 28 / 0.08), 0 10px 30px rgb(16 40 28 / 0.12);
}

@supports (color: color-mix(in srgb, red 10%, blue)) {
  :root { --accent-soft: color-mix(in srgb, var(--accent) var(--accent-pct), transparent); }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { flex: none; display: block; }
.mono { font-family: var(--mono); font-size: 12px; }
.sub { color: var(--muted); }
.noscript { padding: 16px; margin: 16px; border: 1px solid var(--bad); border-radius: var(--r); }
.skip {
  position: absolute; left: 8px; top: -56px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.skip:focus { top: 8px; }

/* ---------- estrutura: barra superior + menu lateral + conteudo ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
  height: 100vh;
  height: 100dvh;
}
.app[data-sidebar="rail"] { grid-template-columns: var(--rail-w) minmax(0, 1fr); }

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.top-spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; border-radius: var(--r-sm); }
.logo {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 13px; letter-spacing: 0.02em;
}
.brand-name { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-name .sep, .brand-name .product { color: var(--muted); font-size: 14px; }
.clock { display: flex; gap: 8px; align-items: baseline; color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.clock .time { color: var(--text); font-weight: 600; font-size: 14px; }
.iconbtn {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 9px; color: var(--text);
}
.iconbtn:hover { background: var(--surface-2); border-color: var(--border); }

.sidebar {
  grid-area: side;
  display: flex; flex-direction: column;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
}
.nav { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.nav > li { min-width: 0; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 40px; padding: 8px 12px;
  border-radius: 9px;
  color: var(--muted); text-decoration: none; font-weight: 550;
}
a.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item.is-soon { cursor: default; opacity: 0.82; }
.nav-label { flex: 1; min-width: 0; line-height: 1.25; overflow-wrap: anywhere; }
.nav-item .badge { flex: none; height: 20px; padding: 0 7px; font-size: 11px; }
.nav-item .badge::before { display: none; }
.nav-divider { margin: 10px 12px; border: 0; border-top: 1px solid var(--border); }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.sidebar-foot .btn { width: 100%; justify-content: flex-start; color: var(--muted); }

.main { grid-area: main; overflow: auto; padding: 24px clamp(16px, 3vw, 32px) 56px; outline: none; }
.view { max-width: 1360px; margin: 0 auto; }
.backdrop { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 30; background: rgb(0 0 0 / 0.55); }

/* menu recolhido (so no desktop): fica uma faixa de icones */
@media (min-width: 901px) {
  .app[data-sidebar="rail"] .nav-label,
  .app[data-sidebar="rail"] .nav-item .badge,
  .app[data-sidebar="rail"] .sidebar-foot .btn-label { display: none; }
  .app[data-sidebar="rail"] .nav-item { justify-content: center; padding: 8px; }
  .app[data-sidebar="rail"] .nav-item[aria-current="page"]::before { left: -10px; }
  .app[data-sidebar="rail"] .nav-item .nav-dot { display: block; }
  .app[data-sidebar="rail"] .sidebar-foot .btn { justify-content: center; padding: 0; }
  .app[data-sidebar="rail"] .nav-divider { margin: 10px 8px; }
}
.nav-dot { display: none; position: absolute; top: 7px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--surface); }

/* ---------- cabecalho de pagina e cartoes ---------- */
.page-h { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-h h1 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; margin-bottom: 4px; outline: none; }
.page-h .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-h h2 { font-size: 14px; font-weight: 650; }
.card-b { padding: 16px; }
.grid-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); margin-bottom: 16px; }
.stack { display: grid; gap: 16px; }
.mb { margin-bottom: 16px; }
.note { margin-top: 12px; font-size: 12.5px; max-width: 90ch; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.stat { padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.stat-l { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-v { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-hint { color: var(--muted); font-size: 12.5px; min-height: 1.4em; }
.stat-hint.ok { color: var(--ok); }
.stat-hint.warn { color: var(--warn); }
.stat-hint.bad { color: var(--bad); }

/* ---------- botoes, campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input {
  height: 34px; padding: 0 10px; min-width: 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--control-border); border-radius: var(--r-sm);
}
.input::placeholder { color: var(--muted); opacity: 1; }
.input:focus-visible { border-color: var(--accent); outline-offset: 0; }
.field { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .input { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar .grow { flex: 1 1 220px; }
.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { width: 100%; padding-left: 34px; }

/* ---------- selos (cor + texto), alertas, medidores ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  color: var(--muted); background: var(--surface-3);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.lg { height: 28px; padding: 0 12px; font-size: 13px; }
.badge.plain::before { display: none; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--r); }
.alert.ok { border-left-color: var(--ok); }
.alert.warn { border-left-color: var(--warn); }
.alert.bad { border-left-color: var(--bad); }
.alert.info { border-left-color: var(--info); }
.alert .icon { margin-top: 1px; }
.alert.ok .icon { color: var(--ok); } .alert.warn .icon { color: var(--warn); } .alert.bad .icon { color: var(--bad); } .alert.info .icon { color: var(--info); }
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#conn-banner { margin-bottom: 16px; }

.meter { height: 6px; min-width: 72px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s ease; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

.empty { display: grid; justify-items: center; gap: 6px; padding: 36px 16px; text-align: center; color: var(--muted); }
.empty strong { color: var(--text); font-size: 14px; }
.empty p { max-width: 52ch; }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* ---------- tabelas densas ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.tall { max-height: 68vh; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 7px 12px; text-align: left; vertical-align: middle; white-space: nowrap; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.wrap { white-space: normal; min-width: 220px; max-width: 420px; overflow-wrap: anywhere; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; }
.cell-strong { font-weight: 600; }
.table .actions-col { text-align: right; width: 1%; }
/* o botao de acao fica sempre a vista, mesmo com rolagem horizontal */
.table th.actions-col, .table td.actions-col { position: sticky; right: 0; background: var(--surface); border-left: 1px solid var(--border); }
.table th.actions-col { z-index: 2; }
.table tbody tr:hover td.actions-col { background: var(--surface-2); }
.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.th-sort { display: inline-flex; align-items: center; gap: 6px; padding: 0; background: none; border: 0; color: inherit; font: inherit; font-weight: inherit; cursor: pointer; border-radius: 4px; }
.th-sort:hover { color: var(--text); }
.th-sort .arrow::after { content: ""; display: block; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: 0; }
th[aria-sort="ascending"] .th-sort .arrow::after { border-bottom: 5px solid currentColor; opacity: 1; }
th[aria-sort="descending"] .th-sort .arrow::after { border-top: 5px solid currentColor; opacity: 1; }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--text); }

/* ---------- aviso rapido ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(92vw, 380px); }
.toast { padding: 10px 14px; border-radius: var(--r); background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 13px; }
.toast.ok { border-left: 3px solid var(--ok); }
.toast.bad { border-left: 3px solid var(--bad); }
.toast.warn { border-left: 3px solid var(--warn); }

/* ---------- tela de entrada ---------- */
.login {
  position: fixed; inset: 0; z-index: 70; overflow: auto;
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(900px 480px at 50% -8%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card { width: min(420px, 100%); display: grid; gap: 10px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 700; }
.login-card h1 { font-size: 22px; letter-spacing: -0.015em; }
.login-card label { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-card .input { height: 40px; }
.login-card .btn { height: 40px; margin-top: 6px; }
.form-error { color: var(--bad); font-size: 13px; }

/* ---------- telas menores ---------- */
@media (max-width: 1500px) { .hide-lg { display: none; } }
@media (max-width: 1100px) { .hide-md { display: none; } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .sidebar {
    position: fixed; z-index: 40; top: var(--topbar-h); bottom: 0; left: 0;
    width: min(86vw, 300px);
    transform: translateX(-104%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    box-shadow: var(--shadow);
  }
  .app[data-drawer="open"] .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease; }
  .nav-item[aria-current="page"]::before { left: -10px; }
  #collapse-btn { display: none; }
  .clock .date { display: none; }
  .hide-sm { display: none; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand-name .sep, .brand-name .product { display: none; }
  #logout-btn .btn-label { display: none; }
  #logout-btn { padding: 0 8px; }
  .clock .time { font-size: 13px; }
  .main { padding: 16px 12px 48px; }
  .stat-v { font-size: 24px; }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .badge.lg { padding: 0 9px; font-size: 12px; }
}
@media (max-width: 420px) { #status-pill { max-width: 128px; overflow: hidden; text-overflow: ellipsis; } .clock { display: none; } }

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

/* quem esta logado (barra de cima) e titulos de bloco do painel */
.whoami { font-size: 13px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .whoami { display: none; } }
.section-h { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }

.mt { margin-top: 16px; }

/* ---- listas (lib/list.js): filtros, paginacao, linha clicavel, gaveta de detalhe ---- */
.field.inline { display: inline-grid; grid-auto-flow: row; gap: 4px; }
.field.inline .input { min-width: 130px; width: auto; }
.pager { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border); }
.pager-btns { display: inline-flex; gap: 8px; }
.pad { padding: 16px; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow); z-index: 61; display: flex; flex-direction: column; }
.drawer[hidden], .drawer-backdrop[hidden] { display: none; }
.drawer-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-t { font-size: 17px; letter-spacing: -0.01em; margin: 0; overflow-wrap: anywhere; }
.drawer-b { padding: 16px 18px 28px; overflow: auto; display: grid; gap: 16px; align-content: start; }
.drawer-b h3 { font-size: 12.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 6px 0 -4px; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: var(--surface-2); border: 1px solid var(--border); }
.poster { width: 100%; max-height: 360px; object-fit: contain; border-radius: 10px; background: var(--surface-2); }

/* Marca e conta (usuarios do admin, backup, marca): o nome vira link para "Minha conta"; o logo pode ser imagem. */
a.whoami { text-decoration: none; border-radius: var(--r-sm); }
a.whoami:hover, a.whoami:focus-visible { color: var(--text); text-decoration: underline; }
.logo { overflow: hidden; }
.logo .logo-img { width: 100%; height: 100%; object-fit: contain; display: block; }
