/* RevLink Hub — Super Admin console.
 *
 * Full-dark operator console (shared design system §9.4), authored in plain CSS
 * (no build step — "Painel: FastAPI + Jinja2 + htmx, sem build step de
 * frontend"). The oklch tokens are the fleet's exact navy+blue palette; the auth
 * surfaces are a full-dark console on the --sidebar* tokens, the authed shell is
 * a dark rail + bluish off-white canvas with white cards. Inter is not loadable
 * offline, so the system font stack stands in; numbers are tabular. All
 * user-facing copy is PT-BR (DR-14). Class names mirror the Jinja templates.
 */

:root {
  --radius: 0.5rem;

  /* Canvas + ink */
  --background: oklch(0.951 0.007 261);   /* bluish off-white #eceff4 */
  --foreground: oklch(0.145 0 0);         /* near-black */
  --card: oklch(1 0 0);                    /* white */

  /* Navy brand ink */
  --primary: oklch(0.261 0.036 264);       /* #1b2436 */
  --primary-foreground: oklch(0.985 0 0);

  /* Control surfaces */
  --secondary: oklch(0.915 0.008 260);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.945 0.006 260);
  --muted-foreground: oklch(0.50 0.01 262);

  /* Accent blue — brand mark + CTA on dark */
  --accent: oklch(0.561 0.178 260);        /* #2f6fdb */
  --accent-foreground: oklch(0.985 0 0);

  /* Semantic */
  --destructive: oklch(0.45 0.18 25);      /* garnet */
  --destructive-foreground: oklch(0.985 0 0);
  --success: oklch(0.52 0.15 156);         /* forest */
  --success-foreground: oklch(0.985 0 0);
  --warning: oklch(0.78 0.16 70);          /* amber */
  --warning-foreground: oklch(0.205 0 0);
  --warning-ink: oklch(0.52 0.13 70);      /* amber, darkened for text on white */

  /* One unified navy border */
  --border: oklch(0.87 0.03 264);
  --input: oklch(0.87 0.03 264);
  --ring: oklch(0.261 0.036 264);

  /* Dark rail */
  --sidebar: oklch(0.261 0.036 264);
  --sidebar-foreground: oklch(0.74 0.02 262);
  --sidebar-primary: oklch(0.60 0.18 260);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.319 0.045 266);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(0.339 0.047 266);
  --sidebar-ring: oklch(0.60 0.18 260);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

h1 { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.small { font-size: 0.8125rem; }
.muted { color: var(--muted-foreground); }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ── Wordmark ──────────────────────────────────────────────────────────────── */
.wordmark { display: inline-flex; align-items: baseline; gap: 0.5rem; }
.wordmark-name { font-weight: 800; letter-spacing: -0.02em; font-size: 1.5rem; }
.wordmark-tag {
  text-transform: uppercase; letter-spacing: 0.25em; font-size: 0.6875rem;
  font-weight: 600; color: var(--muted-foreground);
}
.wordmark-lg .wordmark-name { font-size: 2rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  border: 1px solid transparent; border-radius: calc(var(--radius) - 2px);
  padding: 0.625rem 1rem; font: inherit; font-weight: 600; font-size: 0.9375rem;
  cursor: pointer; text-decoration: none; transition: background-color 0.15s, border-color 0.15s;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.06);
}
.btn-block { width: 100%; }
.btn-accent { background: var(--accent); color: var(--accent-foreground); }
.btn-accent:hover { background: color-mix(in oklch, var(--accent) 90%, black); }
.btn-outline-dark {
  background: var(--sidebar-accent); color: var(--sidebar-primary-foreground);
  border-color: var(--sidebar-border);
}
.btn-outline-dark:hover { background: color-mix(in oklch, var(--sidebar-accent) 80%, white); }

/* ═══ Auth: full-dark operator console (§9.4) ════════════════════════════════ */
body.auth-page {
  background: var(--sidebar); color: var(--sidebar-foreground);
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 3rem 1.5rem;
}
.auth-glow {
  pointer-events: none; position: fixed; top: -10rem; right: -10rem;
  width: 32.5rem; height: 32.5rem; z-index: 0;
  background: radial-gradient(circle at center,
    color-mix(in oklch, var(--accent) 18%, transparent), transparent 70%);
}
.auth-wrap {
  position: relative; z-index: 1; width: 100%; max-width: 28rem;
  display: flex; flex-direction: column; gap: 1.75rem;
}
.auth-brand { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-brand .wordmark-name { color: var(--sidebar-primary-foreground); }
.auth-brand .wordmark-tag { color: var(--sidebar-foreground); }
.auth-seal {
  display: inline-flex; align-items: center; gap: 0.375rem; width: fit-content;
  color: var(--sidebar-primary); font-size: 0.6875rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.2em;
}
.auth-card {
  position: relative; width: 100%; border-radius: var(--radius);
  border: 1px solid var(--sidebar-border);
  background: color-mix(in oklch, var(--sidebar-accent) 40%, transparent);
  backdrop-filter: blur(6px); padding: 1.75rem;
  box-shadow: 0 20px 40px oklch(0 0 0 / 0.35);
}
.auth-title { margin: 0; font-size: 1.375rem; font-weight: 700; color: var(--sidebar-primary-foreground); }
.auth-sub { margin: 0.5rem 0 0; font-size: 0.875rem; color: var(--sidebar-foreground); }
.auth-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.field { display: flex; flex-direction: column; }
.auth-label {
  display: block; margin-bottom: 0.375rem; font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.02em; color: color-mix(in oklch, var(--sidebar-foreground) 85%, white);
}
.auth-field {
  width: 100%; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--sidebar-border); background: var(--sidebar-accent);
  color: var(--sidebar-primary-foreground); padding: 0.625rem 0.75rem;
  font: inherit; font-size: 0.9375rem;
}
.auth-field::placeholder { color: color-mix(in oklch, var(--sidebar-foreground) 40%, transparent); }
.auth-field:focus-visible { outline-color: var(--sidebar-ring); border-color: var(--sidebar-ring); }
.code-field {
  font-variant-numeric: tabular-nums; letter-spacing: 0.5em; text-align: center;
  font-size: 1.125rem;
}
.code-field::placeholder { letter-spacing: normal; }
.auth-erro {
  margin-top: 1.5rem; border-radius: calc(var(--radius) - 2px);
  border: 1px solid color-mix(in oklch, var(--destructive) 40%, transparent);
  background: color-mix(in oklch, var(--destructive) 20%, transparent);
  color: var(--sidebar-primary-foreground); padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
}
.auth-back {
  display: inline-block; margin-top: 1.25rem; font-size: 0.875rem;
  color: var(--sidebar-foreground); text-decoration: underline; text-underline-offset: 4px;
}
.auth-back:hover { color: var(--sidebar-primary-foreground); }
.auth-back:focus-visible { outline-color: var(--sidebar-ring); }

/* Enrollment QR */
.enroll-qr { display: flex; justify-content: center; margin-top: 1.5rem; }
.enroll-qr img {
  width: 12rem; height: 12rem; background: #fff; padding: 0.5rem;
  border-radius: calc(var(--radius) - 2px); display: block;
}
.enroll-key { margin-top: 1rem; font-size: 0.8125rem; }
.enroll-key summary { cursor: pointer; color: var(--sidebar-foreground); }
.enroll-key summary:hover { color: var(--sidebar-primary-foreground); }
.enroll-code {
  display: block; margin-top: 0.75rem; font-family: var(--font-mono);
  word-break: break-all; color: var(--sidebar-primary-foreground);
  background: var(--sidebar); border: 1px solid var(--sidebar-border);
  border-radius: calc(var(--radius) - 2px); padding: 0.625rem 0.75rem;
  letter-spacing: 0.08em;
}

/* ═══ Authed console shell ═══════════════════════════════════════════════════ */
.console { display: flex; min-height: 100vh; }
.rail {
  width: 15.5rem; flex-shrink: 0; background: var(--sidebar);
  color: var(--sidebar-foreground); border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; padding: 1.75rem 1.125rem;
  position: sticky; top: 0; height: 100vh;
}
.rail-brand {
  display: flex; flex-direction: column; gap: 0.75rem;
  padding-bottom: 1.5rem; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.rail-brand .wordmark-name { color: var(--sidebar-primary-foreground); }
.rail-brand .wordmark-tag { color: var(--sidebar-foreground); }
.sa-pill {
  display: inline-flex; align-items: center; gap: 0.375rem; width: fit-content;
  border-radius: calc(var(--radius) - 2px);
  background: color-mix(in oklch, var(--sidebar-primary) 15%, transparent);
  color: var(--sidebar-primary); padding: 0.25rem 0.5rem;
  font-size: 0.625rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.18em;
}
.rail-nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 0.75rem; border-radius: calc(var(--radius) - 1px);
  color: var(--sidebar-foreground); text-decoration: none; font-weight: 500;
  font-size: 0.9375rem; transition: background-color 0.15s, color 0.15s;
}
.nav-item:hover { background: color-mix(in oklch, var(--sidebar-accent) 60%, transparent); color: var(--sidebar-accent-foreground); }
.nav-item.is-active { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
.nav-item.is-active::before {
  content: ""; position: absolute; left: -1.125rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 1.375rem; border-radius: 0 3px 3px 0; background: var(--sidebar-primary);
}
.nav-item:focus-visible { outline-color: var(--sidebar-ring); }
.rail-foot { border-top: 1px solid var(--sidebar-border); padding-top: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.rail-user {
  font-size: 0.8125rem; color: var(--sidebar-foreground);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.canvas { flex: 1; min-width: 0; padding: 2.25rem clamp(1.25rem, 4vw, 2.5rem); }
.canvas > * { max-width: 1400px; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.page-head-main { min-width: 0; }
.back-link { display: inline-block; margin-bottom: 0.75rem; font-size: 0.8125rem; color: var(--muted-foreground); text-decoration: none; }
.back-link:hover { color: var(--foreground); }
.page-title { font-size: 1.875rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.08; color: var(--foreground); }
.title-rule { margin-top: 0.625rem; height: 3px; width: 2.75rem; border-radius: 999px; background: var(--accent); }
.page-sub { margin: 0.75rem 0 0; font-size: 0.875rem; color: var(--muted-foreground); }
.page-sub .mono { word-break: break-all; }
.page-head-status { flex-shrink: 0; }

/* ── Health strip ─────────────────────────────────────────────────────────── */
.health-strip { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.health-item {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 1rem;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.05);
}
.health-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted-foreground); font-weight: 600; }
.health-value { font-size: 0.9375rem; font-weight: 700; color: var(--foreground); }
.health-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--muted-foreground); flex-shrink: 0; }
.health-ok .health-dot { background: var(--success); box-shadow: 0 0 0 3px color-mix(in oklch, var(--success) 30%, transparent); }
.health-atencao .health-dot { background: var(--warning); }
.health-sem_dados .health-dot { background: var(--muted-foreground); }

/* ── Data card + table ────────────────────────────────────────────────────── */
.data-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.05); overflow: hidden; margin-bottom: 1.5rem;
}
.data-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.875rem 1.375rem; border-bottom: 1px solid var(--border); }
.data-card-title { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; color: var(--foreground); }
.data-card-meta { font-size: 0.8125rem; color: var(--muted-foreground); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--muted); text-align: left; font-size: 0.6875rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted-foreground);
  padding: 0.75rem 1.375rem; white-space: nowrap;
}
.data-table td { padding: 0.75rem 1.375rem; font-size: 0.875rem; color: var(--foreground); border-top: 1px solid var(--border); vertical-align: top; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr:hover td { background: color-mix(in oklch, var(--muted) 50%, transparent); }
.row-link { color: var(--foreground); font-weight: 600; text-decoration: none; }
.row-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.data-table td .muted { margin-left: 0.375rem; font-size: 0.75rem; }

.tag {
  display: inline-block; border-radius: 999px; padding: 0.125rem 0.5rem;
  font-size: 0.6875rem; font-weight: 600; background: var(--secondary);
  color: var(--secondary-foreground);
}
.tag-ok { background: color-mix(in oklch, var(--success) 15%, transparent); color: var(--success); }
.tag-vazio { background: var(--muted); color: var(--muted-foreground); }
.tag-negado_permanente { background: color-mix(in oklch, var(--warning) 25%, transparent); color: var(--warning-ink); }
.tag-falha_transitoria { background: color-mix(in oklch, var(--destructive) 12%, transparent); color: var(--destructive); }

/* ── Status pills ─────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 0.4rem; border-radius: 999px;
  padding: 0.15rem 0.6rem; font-size: 0.6875rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; line-height: 1;
}
.pill::before { content: ""; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pill-sucesso { color: var(--success); background: color-mix(in oklch, var(--success) 15%, transparent); }
.pill-falha { color: var(--destructive); background: color-mix(in oklch, var(--destructive) 12%, transparent); }
.pill-rodando { color: var(--accent); background: color-mix(in oklch, var(--accent) 12%, transparent); }
.pill-rodando::before { animation: pill-pulse 1.4s ease-in-out infinite; box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 35%, transparent); }
.pill-pendente, .pill-cancelada { color: var(--muted-foreground); background: var(--muted); }

@keyframes pill-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ── Run detail ───────────────────────────────────────────────────────────── */
#run-live > * + * { margin-top: 1.5rem; }
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.meta-cell { background: var(--card); padding: 0.875rem 1rem; display: flex; flex-direction: column; gap: 0.375rem; }
.meta-k { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted-foreground); font-weight: 600; }
.meta-v { font-size: 0.875rem; font-weight: 600; color: var(--foreground); font-variant-numeric: tabular-nums; }
.run-erro {
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid color-mix(in oklch, var(--destructive) 30%, transparent);
  background: color-mix(in oklch, var(--destructive) 10%, transparent);
  color: var(--destructive); padding: 0.75rem 0.875rem;
  font-size: 0.875rem; word-break: break-word; font-family: var(--font-mono);
}
.erro-row td { background: color-mix(in oklch, var(--destructive) 6%, transparent); color: var(--destructive); word-break: break-word; }

/* Logs on a dark terminal-style panel (operator console) */
.log-list {
  background: oklch(0.20 0.024 264); color: oklch(0.85 0.01 262);
  padding: 0.75rem 0; font-family: var(--font-mono); font-size: 0.8125rem;
  line-height: 1.6; max-height: 32rem; overflow-y: auto;
}
.log-line {
  display: grid; grid-template-columns: 5.5rem 4.5rem 1fr; gap: 0.75rem;
  padding: 0.2rem 1.375rem;
}
.log-ts { color: color-mix(in oklch, var(--sidebar-foreground) 80%, transparent); font-variant-numeric: tabular-nums; }
.log-nivel { font-weight: 700; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.06em; align-self: center; color: var(--sidebar-primary); }
.log-msg { word-break: break-word; }
.log-warning .log-nivel, .log-warn .log-nivel { color: var(--warning); }
.log-error .log-nivel, .log-critical .log-nivel, .log-fatal .log-nivel { color: oklch(0.70 0.16 25); }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty { padding: 2.5rem 1.5rem; text-align: center; }
.empty-title { margin: 0; font-weight: 600; color: var(--foreground); }
.empty-sub { margin: 0.5rem 0 0; font-size: 0.875rem; color: var(--muted-foreground); }

/* ── Responsive: desk-first, but never a dead nav on a phone ─────────────────── */
@media (max-width: 768px) {
  .console { flex-direction: column; }
  .rail {
    width: 100%; height: auto; position: static; flex-direction: row;
    flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem;
    padding: 1rem 1.25rem; border-right: none; border-bottom: 1px solid var(--sidebar-border);
  }
  .rail-brand { border-bottom: none; padding-bottom: 0; margin-bottom: 0; flex-direction: row; align-items: center; gap: 0.75rem; }
  .rail-nav { flex-direction: row; flex: 1 1 auto; justify-content: flex-start; }
  .nav-item.is-active::before { display: none; }
  .rail-foot { border-top: none; padding-top: 0; flex-direction: row; align-items: center; gap: 0.75rem; margin-left: auto; }
  .rail-user { max-width: 40vw; }
  .canvas { padding: 1.5rem 1.25rem; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .log-line { grid-template-columns: 4.5rem 1fr; }
  .log-nivel { display: none; }
}

@media (max-width: 640px) {
  .auth-glow { width: 22.5rem; height: 22.5rem; top: -8.75rem; right: -8.75rem; }
  .auth-card { padding: 1.375rem; }
}

@media (prefers-reduced-motion: reduce) {
  .pill-rodando::before { animation: none; }
  * { transition: none !important; }
}
