/*
  Design direction: "the checkpoint" — a gatekeeper console, not a report.
  Dark-first (security consoles are read in dim rooms); deep lapis instead
  of near-black; brass as the single accent (not terracotta, not acid
  green/red) reserved for identity/active-state; red/green stay strictly
  semantic (allow/block), never used as decoration.
  Signature: a thin brass "gate line" — the same stroke marks the login
  threshold and the sidebar brand, tying "you passed the gate" to "you are
  inside" as one visual idea.
*/

:root {
  --bg: #f2f0e6; --surface: #ffffff; --surface-2: #ebe8dc; --line: #dcd8c8;
  --text: #191712; --text-2: #5c574a; --text-3: #8b8570;
  --brass: #a9762a; --brass-tint: #f3e6d1;
  --ok: #1e7a4f; --ok-bg: #e6f4ec;
  --crit: #9c2b26; --crit-bg: #fbeaea;
  --unknown: #8b8570; --unknown-bg: #ece9dd;
  --focus: #a9762a;
  --font-display: "Avenir Next Condensed", "Roboto Condensed", "Segoe UI Semibold", system-ui, sans-serif;
  --font-body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a2b; --surface: #1a2338; --surface-2: #202b45; --line: #2e3a56;
    --text: #eef0f6; --text-2: #a8b3cc; --text-3: #6f7996;
    --brass: #d1a24f; --brass-tint: #2b2416;
    --ok: #6fc793; --ok-bg: #17281f;
    --crit: #e2726a; --crit-bg: #2c1a19;
    --unknown: #6f7996; --unknown-bg: #1c2337;
    --focus: #d1a24f;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--brass-tint); color: var(--text); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

button {
  padding: 8px 16px; border: 1px solid var(--brass); border-radius: 6px;
  background: var(--brass); color: var(--bg); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: filter .15s ease;
}
button:hover { filter: brightness(1.08); }
button:active { filter: brightness(0.95); }
button.secondary { background: transparent; color: var(--brass); }

input[type="text"], input[type="email"], input[type="password"], textarea, select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit;
  transition: border-color .15s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--brass); }
textarea { width: 100%; min-height: 70px; font-family: var(--font-mono); font-size: 12px; }
label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; letter-spacing: .01em; }
.form-row { margin-bottom: 14px; }
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── fundo animado, compartilhado entre login e o app (dobrando a
   densidade no login via login-bg.js) ── */
#gatefield {
  position: fixed; inset: 0; width: 100vw; height: 100vh; display: block;
  z-index: 0; pointer-events: none;
}

/* ── the checkpoint (login) ── */
#login-screen {
  position: relative;
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse 900px 500px at 50% -10%, var(--brass-tint), transparent 60%);
}
.login-card {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  padding: 40px 38px 34px; width: 336px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.35);
  animation: rise .5s cubic-bezier(.16,1,.3,1) both;
}
.login-card::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 48px; height: 3px; background: var(--brass); border-radius: 0 0 3px 3px;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-eyebrow {
  font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 6px;
}
.login-card h1 {
  font-family: var(--font-display); font-weight: 700; letter-spacing: .01em;
  font-size: 24px; margin: 0 0 26px; color: var(--text);
}
.login-card .form-row input { width: 100%; }
.login-card button { width: 100%; margin-top: 10px; }
.login-error { color: var(--crit); font-size: 12.5px; margin-top: 12px; min-height: 16px; }

/* ── shell ── */
#app-shell { position: relative; display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line);
  padding: 22px 0 0; display: flex; flex-direction: column;
}
.sidebar .brand {
  position: relative;
  font-family: var(--font-display); font-weight: 700; letter-spacing: .01em;
  font-size: 16px; padding: 0 22px 16px; margin-bottom: 10px;
}
.sidebar .brand::after {
  content: ""; position: absolute; bottom: 0; left: 22px; width: 32px; height: 3px;
  background: var(--brass); border-radius: 2px;
}
.nav-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--text-2); padding: 10px 22px; font-size: 13px; cursor: pointer;
  border-left: 2px solid transparent; font-family: inherit; font-weight: 500;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--brass); border-left-color: var(--brass); font-weight: 700; background: var(--surface-2); }
.sidebar-footer { margin-top: auto; padding: 14px 22px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.sidebar-footer #me-email { color: var(--text-2); }
.sidebar-footer .role-badge {
  display: inline-block; padding: 2px 9px; border-radius: 10px; background: var(--brass-tint);
  color: var(--brass); font-size: 10.5px; font-weight: 700; text-transform: uppercase; margin-top: 6px; letter-spacing: .04em;
}

.main { flex: 1; min-width: 0; padding: 32px 40px 60px; }
.main h2 {
  font-family: var(--font-display); font-weight: 700; letter-spacing: .01em;
  font-size: 22px; margin: 0 0 4px;
}
.view-sub { color: var(--text-2); font-size: 13px; margin-bottom: 22px; }

.tenant-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 22px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; }
.stat-tile .n {
  font-family: var(--font-display); font-weight: 700; font-size: 28px;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
.stat-tile .l { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-top: 5px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px 22px; margin-bottom: 22px; }
.card h3 { font-size: 13.5px; font-weight: 700; margin: 0 0 12px; letter-spacing: .01em; }

.audit-filters { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.audit-filters .form-row { margin-bottom: 14px; }
.audit-diff { font-size: 11.5px; color: var(--text-2); font-family: var(--font-mono, monospace); }

.paranoia-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); margin-top: 6px; }
input[type="range"] { width: 100%; accent-color: var(--brass); }
.paranoia-desc { font-size: 13px; color: var(--text-2); margin-top: 10px; min-height: 40px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); padding: 7px 10px; border-bottom: 1px solid var(--line); font-weight: 700;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }

/* larguras fixas por coluna — sem isso, conteúdo comprido numa célula (ex.
   rota longa na tabela de eventos) redimensiona a tabela inteira e empurra
   as outras colunas. Célula estoura com reticências, não com layout. */
table.fixed-cols { table-layout: fixed; }
table.fixed-cols td, table.fixed-cols th {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.fixed-cols th { position: relative; }
/* alça de redimensionamento: arraste a borda direita do cabeçalho pra
   aumentar/diminuir a coluna — largura fixa sozinha corta texto longo
   (ex. mensagem de regra) sem dar jeito de ver o resto. */
.col-resizer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 6px;
  cursor: col-resize; user-select: none; touch-action: none;
}
.col-resizer:hover, .col-resizer:active { background: var(--brass); opacity: .5; }
#events-table th:nth-child(1), #events-table td:nth-child(1) { width: 110px; }
#events-table th:nth-child(2), #events-table td:nth-child(2) { width: 220px; }
#events-table th:nth-child(3), #events-table td:nth-child(3) { width: auto; }
#events-table th:nth-child(4), #events-table td:nth-child(4) { width: 90px; }
#audit-table th:nth-child(1), #audit-table td:nth-child(1) { width: 150px; }
#audit-table th:nth-child(2), #audit-table td:nth-child(2) { width: 160px; }
#audit-table th:nth-child(3), #audit-table td:nth-child(3) { width: 170px; }
#audit-table th:nth-child(4), #audit-table td:nth-child(4) { width: 150px; }
#audit-table th:nth-child(5), #audit-table td:nth-child(5) { width: auto; }
#audit-table th:nth-child(6), #audit-table td:nth-child(6) { width: 110px; }
#audit-table th:nth-child(7), #audit-table td:nth-child(7) { width: 130px; }
#rules-summary-table th:nth-child(1), #rules-summary-table td:nth-child(1) { width: 90px; }
#rules-summary-table th:nth-child(2), #rules-summary-table td:nth-child(2) { width: auto; }
#rules-summary-table th:nth-child(3), #rules-summary-table td:nth-child(3) { width: 130px; }
.badge { padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .01em; }
.badge.block { background: var(--crit-bg); color: var(--crit); }
.badge.allow, .badge.pass { background: var(--ok-bg); color: var(--ok); }
.badge.challenge, .badge.verified { background: var(--unknown-bg); color: var(--unknown); }

.badge.sistema { background: var(--unknown-bg); color: var(--unknown); }
.badge.custom { background: var(--brass-tint); color: var(--brass); }

.health-strip { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.health-strip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: none; }
.health-strip .dot.ok { background: var(--ok); }
.health-strip .dot.down { background: var(--crit); }
.health-strip .empty { font-size: 11.5px; color: var(--text-3); }

.perm-checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.perm-check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); width: auto; margin: 0; }
.perm-check input { margin: 0; }
.perm-pill {
  display: inline-block; padding: 2px 8px; border-radius: 4px; margin: 1px 3px 1px 0;
  background: var(--surface-2); color: var(--text-2); font-size: 11px; font-family: var(--font-mono);
}
details > summary { cursor: pointer; color: var(--brass); font-size: 12.5px; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 10px; }

.msg { font-size: 12.5px; margin-top: 8px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--crit); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── arquitetura ── */
.plane { border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: 16px; background: var(--surface); }
.plane-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin-bottom: 14px; font-weight: 700; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.arrow { color: var(--text-3); font-size: 15px; }
.node { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 7px; padding: 8px 12px; background: var(--bg); font-size: 12.5px; }
.node .label { display: flex; flex-direction: column; }
.node .sub-name { font-size: 10.5px; color: var(--text-3); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; transition: background-color .3s ease; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.down { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-bg); }
.dot.unknown { background: var(--unknown); box-shadow: 0 0 0 3px var(--unknown-bg); }
.stack { display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 860px) {
  #app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 12px 0; }
  .sidebar .brand, .sidebar-footer { display: none; }
  .main { padding: 22px 18px 40px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
