/* =============================================================================
   app.css — estilos do painel do nc-admin.

   - Cores e espaçamentos em variáveis (:root). O tema escuro redefine só as
     variáveis: segue o sistema operacional, e o botão ◐ força claro/escuro
     (atributo data-theme no <html>, lembrado no navegador).
   - Cores dos gráficos e de estado (bom/atenção/grave/crítico) seguem uma
     paleta validada para daltonismo; estado sempre vem com texto ou ícone,
     nunca só a cor.
   - Sem fontes externas: fonte do sistema.
   - @media print no fim: a página "Relatório" sai limpa na impressão/PDF.
   ============================================================================= */

:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-hover: #ecebe6;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;

  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-soft: #e6f0fc;
  --accent-text: #1c5cab;

  /* Paleta categórica (ordem fixa) e de estado */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --good: #0ca30c;
  --good-text: #006300;
  --good-soft: #e3f4e3;
  --warn: #fab219;
  --warn-text: #8a5a00;
  --warn-soft: #fdf3dc;
  --serious: #ec835a;
  --serious-text: #9c3d17;
  --serious-soft: #fcebe3;
  --critical: #d03b3b;
  --critical-text: #a32727;
  --critical-soft: #fbe6e6;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.18);
  --sidebar-w: 236px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --surface-hover: #2a2a28;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: #15263b;
    --accent-text: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good-text: #0ca30c;
    --good-soft: #142914;
    --warn-text: #fab219;
    --warn-soft: #2e2511;
    --serious-text: #ec835a;
    --serious-soft: #2f1d15;
    --critical-text: #e66767;
    --critical-soft: #331818;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-hover: #2a2a28;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: #15263b;
  --accent-text: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --good-text: #0ca30c;
  --good-soft: #142914;
  --warn-text: #fab219;
  --warn-soft: #2e2511;
  --serious-text: #ec835a;
  --serious-soft: #2f1d15;
  --critical-text: #e66767;
  --critical-soft: #331818;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* --- Base ------------------------------------------------------------------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Layout ----------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); padding: 4px 8px 12px; }
.brand:hover { text-decoration: none; }
.brand-lg { font-size: 22px; padding: 0 0 4px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent) url("favicon.svg") center / cover;
}
nav .nav-group { margin: 14px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
nav a:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
nav a.active { background: var(--accent-soft); color: var(--accent-text); }
nav a .ico { width: 18px; text-align: center; opacity: 0.85; }
nav a .count {
  margin-left: auto; font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 999px;
  background: var(--critical); color: #fff; line-height: 18px;
}
.sidebar-foot { margin-top: auto; padding: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 24px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; gap: 6px; align-items: center; color: var(--muted); min-width: 0; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { opacity: 0.5; }
.crumbs .here { color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.user { color: var(--text-2); font-weight: 500; padding: 0 6px; }
.btn.menu-toggle { display: none; }
.view { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; outline: none; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--text-2); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt { margin-top: 16px; }

/* --- Cartões e números ------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0; }
.card-head .hint { margin-left: auto; }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 8px 0 0; }

.stat { padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.stat .foot { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hero { font-size: 48px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }

.meter { height: 8px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; min-width: 60px; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter.warn { background: var(--warn-soft); } .meter.warn > span { background: var(--warn); }
.meter.crit { background: var(--critical-soft); } .meter.crit > span { background: var(--critical); }
.usage-cell { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.usage-cell .meter { flex: 1; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* --- Selos de estado --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge.plain::before { display: none; }
.badge.good { background: var(--good-soft); color: var(--good-text); border-color: transparent; }
.badge.good::before { background: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); border-color: transparent; }
.badge.warn::before { background: var(--warn); }
.badge.serious { background: var(--serious-soft); color: var(--serious-text); border-color: transparent; }
.badge.serious::before { background: var(--serious); }
.badge.crit { background: var(--critical-soft); color: var(--critical-text); border-color: transparent; }
.badge.crit::before { background: var(--critical); }
.badge.info { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.info::before { background: var(--accent); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-2); font-size: 12px; font-family: var(--mono); color: var(--text-2); margin: 1px 2px 1px 0; }

/* --- Botões e formulários ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); background: var(--critical); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-only { width: 34px; padding: 0; }
.btn .spin, .spin {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 10px; min-height: 34px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: auto; min-height: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { color: var(--critical-text); background: var(--critical-soft); padding: 8px 10px; border-radius: var(--radius-sm); margin: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .search { min-width: 240px; }

/* --- Tabelas ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface); position: sticky; top: 0; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { opacity: 0.7; margin-left: 4px; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr.clickable { cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 12px; color: var(--muted); }

/* --- Abas ------------------------------------------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: none; background: none; font: inherit; color: var(--text-2); padding: 10px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* --- Alertas (lista) --------------------------------------------------------- */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-top: 1px solid var(--border); }
.alert-list li:first-child { border-top: none; }
.alert-list .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.callout { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); display: flex; gap: 10px; }
.callout.warn { background: var(--warn-soft); }
.callout.crit { background: var(--critical-soft); }
.callout.good { background: var(--good-soft); }

/* --- Passos do job (linha do tempo) ----------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: none; }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; background: var(--axis); justify-self: center; }
.timeline .done .dot { background: var(--good); }
.timeline .failed .dot, .timeline .compensation_failed .dot { background: var(--critical); }
.timeline .running .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.timeline .compensated .dot, .timeline .skipped .dot { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.35; } }
pre.json {
  margin: 6px 0 0; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm);
  font: 12px/1.45 var(--mono); overflow: auto; max-height: 360px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* --- Gráficos ---------------------------------------------------------------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.10; }
.chart .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart .label { fill: var(--text-2); font-size: 12px; }
.chart .value { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar-hit { fill: transparent; }
.chart .bar-row:hover .bar-bg { fill: var(--surface-hover); }
.chart .bar-bg { fill: transparent; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  font-size: 12px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip .t-title { color: var(--muted); margin-bottom: 2px; }
.tooltip .t-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.spark { display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; }

/* --- Avisos e modais --------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start;
  animation: slide-in 0.18s ease-out;
}
.toast .grow { min-width: 0; overflow-wrap: anywhere; }
.toast .title { font-weight: 600; }
.toast.good { border-left: 4px solid var(--good); }
.toast.crit { border-left: 4px solid var(--critical); }
.toast.info { border-left: 4px solid var(--accent); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
  border: 1px solid var(--border);
}
.modal.wide { max-width: 860px; }
.modal-head { padding: 18px 20px 0; display: flex; align-items: center; gap: 10px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 14px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 0 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }
.secret-box { display: flex; gap: 8px; align-items: center; }
.secret-box code { flex: 1; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); overflow-wrap: anywhere; }

/* --- Login ------------------------------------------------------------------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--accent-soft), transparent 60%),
    var(--page);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card p { margin: 0 0 6px; }

/* --- Carregando -------------------------------------------------------------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-hover), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); min-height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px; }

/* --- Telas menores ----------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 50; left: 0; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .btn.menu-toggle { display: inline-flex; }
  .view { padding: 16px; }
  .topbar { padding: 0 16px; }
  .user { display: none; }
  .grid-4, .grid-3, .grid-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .toolbar input, .toolbar select, .toolbar .search { min-width: 0; width: 100%; }
}

/* --- Impressão (página Relatório → PDF) -------------------------------------- */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .view { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  th { position: static; }
  /* tabela larga: tudo visível e menor no papel */
  .table-wrap { overflow: visible; }
  table { font-size: 10px; }
  th, td { padding: 4px 6px; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
