/* ==========================================================================
   wCloakShield — design tokens
   Superfícies e paleta de série vêm da paleta de referência validada
   (6 checks, light e dark). Não troque um hex sem revalidar.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* superfícies */
  --plane:       #0d0d0d;
  --surface-1:   #1a1a19;
  --surface-2:   #232321;
  --surface-3:   #2c2c2a;

  /* tinta */
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;

  /* chrome de gráfico */
  --grid:     #2c2c2a;
  --baseline: #383835;
  --border:   rgba(255, 255, 255, 0.10);

  /* série categórica — ordem fixa, nunca ciclada */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;

  /* status — reservado, nunca reusado como série */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --plane:     #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ed;
  --surface-3: #e8e7e2;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --grid:     #e1e0d9;
  --baseline: #c3c2b7;
  --border:   rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  --shadow: 0 10px 30px rgba(11, 11, 11, 0.10);
}

/* ========================================================================== */

* { box-sizing: border-box; }

/* `display: grid/flex` nas classes abaixo vence o [hidden] padrão do UA */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--series-1); }

::selection { background: color-mix(in oklab, var(--series-1) 40%, transparent); }

/* --- auth ----------------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1000px 500px at 50% -10%, color-mix(in oklab, var(--series-1) 14%, transparent), transparent 70%),
    var(--plane);
}

.auth-panel {
  width: 100%;
  max-width: 400px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-brand strong { display: block; font-size: 16px; }
.auth-brand span { font-size: 12px; color: var(--text-muted); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; margin-bottom: 18px; }
.tab {
  flex: 1; background: transparent; border: 0; color: var(--text-secondary);
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px;
}
.tab.is-on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

.auth-form { display: grid; gap: 13px; }

/* --- campos --------------------------------------------------------------- */

.field { display: grid; gap: 5px; align-content: start; }
.field > span { font-size: 12px; color: var(--text-secondary); }
.field > small { font-size: 11px; color: var(--text-muted); }

/* caixa de marcação com a mesma altura de um input, para alinhar nas linhas */
.check-box {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 11px; min-height: 37px; cursor: pointer;
}
.check-box:hover { border-color: var(--text-muted); }
.check-box input { width: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--series-1); }
.check-box em { font-style: normal; font-size: 13px; color: var(--text-secondary); }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font: inherit;
  width: 100%;
  min-width: 0;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--series-1) 25%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { min-height: 140px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: right 14px center, right 9px center; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

/* --- botões --------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: 13px;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--series-1); border-color: transparent; color: #fff; }
.btn-primary:hover { background: color-mix(in oklab, var(--series-1) 85%, #000); }
.btn-danger { color: var(--critical); }
.btn-danger:hover { background: color-mix(in oklab, var(--critical) 16%, var(--surface-2)); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  width: 30px; height: 30px; border-radius: var(--radius-sm); cursor: pointer; font: inherit;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }

/* --- shell ---------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 16px 16px 12px; font-weight: 600; }
.brand span { flex: 1; }
.sidebar-close { display: none; }

.project-picker { padding: 0 16px 12px; border-bottom: 1px solid var(--border); }

/* align-content: start é essencial — sem ele o grid distribui a altura livre
   entre as linhas e os itens do menu ficam espalhados pela coluna inteira. */
.nav { padding: 12px 10px; display: grid; gap: 2px; align-content: start; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-size: 13px;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.is-on { background: color-mix(in oklab, var(--series-1) 16%, transparent); color: var(--text-primary); }
.nav a.is-on svg { color: var(--series-1); }
.nav svg { width: 16px; height: 16px; flex: none; color: var(--text-muted); }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 14px 10px 4px; }
.nav-group:first-child { padding-top: 2px; }

/* escurece o conteúdo atrás do menu quando ele vira overlay no mobile */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 70; animation: fade .12s ease-out; }

.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.sidebar-foot .btn { margin-left: auto; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface-1) 70%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; }
.crumbs { flex: 1; min-width: 0; }
.crumbs h1 { font-size: 16px; }
.crumbs p { font-size: 12px; color: var(--text-muted); }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.chip {
  font-size: 12px; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 99px; padding: 3px 11px;
  background: var(--surface-2);
}

.view { padding: 24px; max-width: 1240px; width: 100%; margin: 0 auto; }
.view:focus { outline: none; }

/* --- cards ---------------------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14px; }
.card-head p { font-size: 12px; color: var(--text-muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > .field { flex: 1 1 170px; }
.row.end { justify-content: flex-end; }

/* --- stat tiles ----------------------------------------------------------- */

.stat {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat .label { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.1; }
.stat .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat .spark { margin-top: 10px; }

/* --- tabelas -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 500; font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-1); position: sticky; top: 0;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in oklab, var(--surface-2) 60%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 6px; }

.empty { padding: 34px 18px; text-align: center; color: var(--text-muted); font-size: 13px; }
.empty strong { display: block; color: var(--text-secondary); font-size: 14px; margin-bottom: 4px; font-weight: 500; }

/* --- badges & status ------------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 2px 9px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.badge.good     { color: var(--good);     background: color-mix(in oklab, var(--good) 14%, transparent); }
.badge.warning  { color: var(--warning);  background: color-mix(in oklab, var(--warning) 14%, transparent); }
.badge.serious  { color: var(--serious);  background: color-mix(in oklab, var(--serious) 14%, transparent); }
.badge.critical { color: var(--critical); background: color-mix(in oklab, var(--critical) 14%, transparent); }
.badge.neutral::before { background: var(--text-muted); }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; background: var(--surface-2);
  padding: 2px 6px; border-radius: 5px; word-break: break-all;
}
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 90px; }
.progress > i { display: block; height: 100%; background: var(--series-1); border-radius: 99px; transition: width .3s; }

/* --- notas ---------------------------------------------------------------- */

.note {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2); border-left: 2px solid var(--series-1);
  padding: 10px 13px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.note.warn { border-left-color: var(--warning); }

/* --- gráficos ------------------------------------------------------------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); }
.axis-label { font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.series-label { font-size: 12px; fill: var(--text-secondary); }
.value-label { font-size: 12px; fill: var(--text-primary); font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.chart-tip {
  position: absolute; pointer-events: none; opacity: 0; transform: translate(-50%, -100%);
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 11px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 5;
  transition: opacity .1s;
}
.chart-tip b { display: block; margin-bottom: 4px; font-weight: 500; color: var(--text-primary); }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.chart-tip .tip-row span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-primary); }

/* --- toasts --------------------------------------------------------------- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-left-width: 3px;
  border-radius: var(--radius-sm); padding: 11px 15px; font-size: 13px;
  box-shadow: var(--shadow); max-width: 400px;
  animation: slide-in .16s ease-out;
}
.toast.ok   { border-left-color: var(--good); }
.toast.err  { border-left-color: var(--critical); }
.toast.info { border-left-color: var(--series-1); }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } }

/* --- modal ---------------------------------------------------------------- */

.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90;
  display: grid; place-items: center; padding: 20px;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { font-size: 15px; flex: 1; }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* --- skeleton ------------------------------------------------------------- */

.skel { background: var(--surface-2); border-radius: var(--radius-sm); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.skel-line { height: 12px; margin-bottom: 9px; }
.skel-block { height: 180px; }

/* --- responsivo ----------------------------------------------------------- */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 80;
    transform: translateX(-100%); transition: transform .18s ease-out;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .sidebar-close, .menu-btn { display: inline-grid; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

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