/* --- Design system (base: enzo.html) — cores em OKLCH, tipografia Geist ---- */

@font-face {
  font-family: "Geist";
  src: url("/fonts/geist-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  src: url("/fonts/geist-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;

  --bg: oklch(0.945 0.002 250);
  --surface: oklch(1 0 0);
  --surface-glass: oklch(1 0 0 / 0.86);
  --surface-2: oklch(0.965 0.002 250);
  --surface-3: oklch(0.935 0.004 250);
  --border: oklch(0.9 0.004 250);
  --border-strong: oklch(0.855 0.006 250);

  --text: oklch(0.25 0.012 250);
  --text-muted: oklch(0.48 0.012 250);
  --text-faint: oklch(0.6 0.01 250);

  --primary: oklch(0.53 0.18 253);
  --primary-hover: oklch(0.47 0.18 253);
  --primary-soft: oklch(0.53 0.18 253 / 0.12);
  --primary-contrast: oklch(0.99 0.01 253);

  --success: oklch(0.55 0.16 150);
  --success-soft: oklch(0.55 0.16 150 / 0.13);
  --warning: oklch(0.62 0.14 78);
  --warning-soft: oklch(0.62 0.14 78 / 0.14);
  --danger: oklch(0.54 0.2 25);
  --danger-soft: oklch(0.54 0.2 25 / 0.12);
  --info-soft: oklch(0.53 0.18 253 / 0.1);

  --shadow-sm: 0 1px 2px oklch(0.4 0.01 250 / 0.06);
  --shadow-md: 0 1px 2px oklch(0.4 0.01 250 / 0.06), 0 14px 34px oklch(0.4 0.01 250 / 0.09);
  --shadow-lg: 0 1px 2px oklch(0.4 0.01 250 / 0.08), 0 24px 60px oklch(0.4 0.01 250 / 0.16);

  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-w: 256px;
  --font: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Tema escuro: pelo sistema, salvo quando o usuario fixou o tema claro. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: oklch(0.2 0.006 250);
    --surface: oklch(0.255 0.008 250);
    --surface-glass: oklch(0.255 0.008 250 / 0.82);
    --surface-2: oklch(0.295 0.008 250);
    --surface-3: oklch(0.33 0.008 250);
    --border: oklch(0.35 0.008 250);
    --border-strong: oklch(0.42 0.01 250);

    --text: oklch(0.97 0.004 250);
    --text-muted: oklch(0.79 0.008 250);
    --text-faint: oklch(0.65 0.01 250);

    --primary: oklch(0.72 0.15 253);
    --primary-hover: oklch(0.79 0.14 253);
    --primary-soft: oklch(0.72 0.15 253 / 0.18);
    --primary-contrast: oklch(0.18 0.04 253);

    --success: oklch(0.78 0.15 152);
    --success-soft: oklch(0.78 0.15 152 / 0.18);
    --warning: oklch(0.83 0.14 82);
    --warning-soft: oklch(0.83 0.14 82 / 0.18);
    --danger: oklch(0.7 0.19 25);
    --danger-soft: oklch(0.7 0.19 25 / 0.16);
    --info-soft: oklch(0.72 0.15 253 / 0.14);

    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
    --shadow-md: 0 1px 2px oklch(0 0 0 / 0.3), 0 16px 40px oklch(0 0 0 / 0.32);
    --shadow-lg: 0 1px 2px oklch(0 0 0 / 0.4), 0 28px 64px oklch(0 0 0 / 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: oklch(0.2 0.006 250);
  --surface: oklch(0.255 0.008 250);
  --surface-glass: oklch(0.255 0.008 250 / 0.82);
  --surface-2: oklch(0.295 0.008 250);
  --surface-3: oklch(0.33 0.008 250);
  --border: oklch(0.35 0.008 250);
  --border-strong: oklch(0.42 0.01 250);

  --text: oklch(0.97 0.004 250);
  --text-muted: oklch(0.79 0.008 250);
  --text-faint: oklch(0.65 0.01 250);

  --primary: oklch(0.72 0.15 253);
  --primary-hover: oklch(0.79 0.14 253);
  --primary-soft: oklch(0.72 0.15 253 / 0.18);
  --primary-contrast: oklch(0.18 0.04 253);

  --success: oklch(0.78 0.15 152);
  --success-soft: oklch(0.78 0.15 152 / 0.18);
  --warning: oklch(0.83 0.14 82);
  --warning-soft: oklch(0.83 0.14 82 / 0.18);
  --danger: oklch(0.7 0.19 25);
  --danger-soft: oklch(0.7 0.19 25 / 0.16);
  --info-soft: oklch(0.72 0.15 253 / 0.14);

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 1px 2px oklch(0 0 0 / 0.3), 0 16px 40px oklch(0 0 0 / 0.32);
  --shadow-lg: 0 1px 2px oklch(0 0 0 / 0.4), 0 28px 64px oklch(0 0 0 / 0.45);
}

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

/* O atributo `hidden` precisa vencer as classes que definem `display`
   (.alert, .field, #root); sem isto, elementos ocultos continuam visiveis. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background 400ms ease, color 400ms ease;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.018em; }
p { margin: 0 0 0.75rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--text); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- Boot ---------------------------------------------------------------- */

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.boot__spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Layout -------------------------------------------------------------- */

#root { display: flex; min-height: 100vh; }
#root[data-view="auth"] .sidebar,
#root[data-view="auth"] .topbar { display: none; }
#root[data-view="auth"] .shell { margin-left: 0; }
#root[data-view="auth"] .view { display: grid; place-items: center; padding: 1.5rem; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 1rem 0.75rem;
  background: var(--surface); border-right: 1px solid var(--border);
}

/* A marca ocupa a largura util do menu, nao um canto dele.
 *
 * A barra tem 256px com 0.75rem de recuo de cada lado; o lockup (1591x610)
 * preenche essa largura e fica com cerca de 80px de altura. O escudo sozinho e'
 * retrato — enchendo a mesma largura passaria de 230px de altura e empurraria a
 * navegacao para fora da tela. Por isso aqui e' o lockup, e o escudo fica para
 * onde o espaco e' realmente pequeno (favicon, cartoes de 2FA). */
.sidebar__brand { display: block; padding: 0.35rem 0.25rem 1.1rem; }
.brand__mark {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 11px; background: var(--primary); color: var(--primary-contrast);
  font-weight: 700; font-size: 15px;
}
.brand__name { font-weight: 650; letter-spacing: -0.02em; }
.brand__dot { color: var(--primary); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav__group { padding: 0.9rem 0.65rem 0.3rem; font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.nav__item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 0.65rem; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item { position: relative; }
.nav__item[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav__item[aria-current="page"]::before {
  content: ""; position: absolute; left: -0.75rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav__item svg { width: 18px; height: 18px; flex: none; }

.sidebar__foot { border-top: 1px solid var(--border); padding-top: 0.6rem; }
/* Seletor de tema: pilula com tres opcoes, a que vale fica em relevo.
 *
 * Tres estados visiveis de uma vez, e nao um botao que cicla: ciclando, o
 * rotulo diz o que esta valendo mas nao o que vem depois — para chegar em
 * "escuro" era preciso clicar e ver no que deu. Aqui a escolha e' direta.
 *
 * Os `margin`, `padding` e `min-width` sao reset: <fieldset> vem com margem
 * lateral de 2px e um padding proprio do navegador. */
.tema {
  display: flex; gap: 2px;
  margin: 0 auto; padding: 3px; min-width: 0; width: max-content;
  border: 1px solid var(--border); border-radius: 999px;
  /* Pista `--bg` e botao `--surface`: e' o unico par que fica mais claro no
   * selecionado nos DOIS temas. A escala nao e' monotona — no claro
   * `--surface-2` e' mais escuro que `--surface`, no escuro e' mais claro —
   * entao usar `--surface-2` na pista deixava o selecionado AFUNDADO no escuro,
   * o contrario do que a forma promete. */
  background: var(--bg);
}
.tema__op {
  display: grid; place-items: center; width: 36px; height: 30px;
  border: 1px solid transparent; border-radius: 999px;
  cursor: pointer; color: var(--text-faint);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.tema__op:hover { color: var(--text-muted); }
.tema__op svg { width: 17px; height: 17px; }
.tema__op:has(input:checked) {
  background: var(--surface); color: var(--text);
  border-color: var(--border); box-shadow: var(--shadow-sm);
}

/* O foco mora no <input>, que esta escondido em `.sr-only`. Sem trazer o anel
   para a opcao, quem navega por teclado nao ve onde esta. */
.tema__op:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }

.shell { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1.5rem; min-height: 60px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 17px; }
.topbar__spacer { flex: 1; }
/* `.topbar .topbar__menu` e nao `.topbar__menu` por causa de uma colisao de
 * especificidade: o botao e' `class="icon-btn topbar__menu"`, e `.icon-btn`
 * ({ display: grid }) esta mais abaixo neste arquivo. Como as duas regras
 * valiam 0-1-0, a de baixo ganhava e o menu aparecia TAMBEM no desktop, com a
 * barra lateral ja aberta ao lado. O descendente sobe para 0-2-0 e a regra
 * passa a valer onde quer que `.icon-btn` esteja. */
.topbar .topbar__menu { display: none; }

.view { padding: 1.5rem; flex: 1; outline: none; }
.view__inner { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(6, 9, 15, 0.5); z-index: 35; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  #root[data-sidebar="open"] .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .shell { margin-left: 0; }
  .topbar .topbar__menu { display: grid; }
  .view { padding: 1rem; }
}

/* --- Usuario no topo ----------------------------------------------------- */

.user-chip { display: flex; align-items: center; gap: 0.6rem; }
.user-chip__info { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.user-chip__name { font-size: 13px; font-weight: 600; }
.user-chip__role { font-size: 12px; color: var(--text-muted); }
@media (max-width: 560px) { .user-chip__info { display: none; } }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; object-fit: cover;
  background: var(--surface-3); display: grid; place-items: center;
  font-size: 13px; font-weight: 650; color: var(--text-muted);
  border: 1px solid var(--border);
}
.avatar--lg { width: 64px; height: 64px; font-size: 22px; }
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

/* --- Cartoes ------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.card__head {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.card__title { font-size: 15px; }
.card__desc { font-size: 13px; color: var(--text-muted); margin: 0.15rem 0 0; }
.card__body { padding: 1.25rem; }
.card__body--flush { padding: 0; }
.card__foot { padding: 0.9rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.page-head__text h2 { font-size: 20px; }
.page-head__text p { color: var(--text-muted); font-size: 14px; margin: 0.2rem 0 0; }

/* --- Estatisticas -------------------------------------------------------- */

.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { padding: 1.1rem 1.25rem; }
.stat__label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.stat__value { font-size: 30px; font-weight: 640; letter-spacing: -0.035em; margin-top: 0.3rem; }
.stat__hint { font-size: 12.5px; color: var(--text-muted); margin-top: 0.15rem; }

/* --- Botoes -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.5rem 0.9rem; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { opacity: 0.88; background: var(--danger); }
.btn--ghost { border-color: transparent; background: none; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: 0.32rem 0.6rem; font-size: 13px; }
.btn--block { width: 100%; }
.btn--google { background: var(--surface); color: var(--text); font-weight: 600; padding: 0.65rem 1rem; }
.btn--google svg { width: 18px; height: 18px; stroke: none; }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 8px; border: 1px solid transparent; background: none;
  color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* --- Formularios --------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.field__label { font-size: 13px; font-weight: 600; }
.field__hint { font-size: 12.5px; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%; padding: 0.55rem 0.7rem; font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px;
}
.input:focus, .select:focus, .textarea:focus,
.btn:focus-visible, .nav__item:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
.input::placeholder { color: var(--text-faint); }

.code-input {
  font-family: var(--mono); font-size: 26px; letter-spacing: 0.4em;
  text-align: center; padding: 0.7rem 0.5rem 0.7rem 0.9rem;
}

.toolbar { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.toolbar .input, .toolbar .select { width: auto; min-width: 180px; }

/* --- Selecao multipla (menu suspenso) ------------------------------------- */

.mselect { position: relative; }
.mselect--empty {
  padding: 0.55rem 0.7rem; border: 1px dashed var(--border-strong);
  border-radius: 8px; color: var(--text-faint); font-size: 13.5px;
}

.mselect__trigger {
  display: flex; align-items: center; gap: 0.5rem; width: 100%; min-height: 40px;
  padding: 0.4rem 0.6rem 0.4rem 0.7rem; font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface); text-align: left; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 8px;
}
.mselect__trigger:hover { border-color: var(--text-faint); }
.mselect__trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.mselect[data-open="true"] .mselect__trigger { border-color: var(--primary); }

.mselect__value { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; flex: 1; min-width: 0; }
.mselect__value--empty { color: var(--text-faint); }

.mselect__chevron { width: 16px; height: 16px; flex: none; color: var(--text-muted); transition: transform 0.15s ease; }
.mselect[data-open="true"] .mselect__chevron { transform: rotate(180deg); }

.mselect__panel {
  margin-top: 0.35rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.mselect__search { border: none; border-bottom: 1px solid var(--border); border-radius: 0; }
.mselect__search:focus { outline: none; border-bottom-color: var(--primary); }

.mselect__list { max-height: 240px; overflow-y: auto; padding: 0.25rem; }

.mselect__option {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.5rem 0.6rem; border-radius: 8px; cursor: pointer;
}
.mselect__option:hover { background: var(--surface-2); }
.mselect__option input { margin-top: 0.15rem; flex: none; }
.mselect__option-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }
.mselect__option-name { font-size: 14px; font-weight: 550; }
.mselect__option-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }
.mselect__option:has(input:checked) { background: var(--primary-soft); }
.mselect__option:has(input:checked) .mselect__option-name { color: var(--primary); }

.mselect__noresult { padding: 1rem 0.6rem; text-align: center; color: var(--text-faint); font-size: 13px; }

/* --- Tabelas ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-faint);
  padding: 0.65rem 1.25rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.cell-user { display: flex; align-items: center; gap: 0.6rem; }
.cell-user__name { font-weight: 550; }
.cell-user__email { font-size: 12.5px; color: var(--text-muted); }
.cell-actions { display: flex; gap: 0.35rem; justify-content: flex-end; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* --- Distintivos --------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-muted);
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--info { background: var(--info-soft); color: var(--primary); }
.badge-list { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* --- Estados ------------------------------------------------------------- */

.empty { padding: 3rem 1.5rem; text-align: center; color: var(--text-muted); }
.empty__title { font-weight: 600; color: var(--text); margin-bottom: 0.2rem; }
.skeleton { height: 14px; border-radius: 6px; background: var(--surface-3); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.alert {
  display: flex; gap: 0.6rem; padding: 0.75rem 0.9rem; border-radius: var(--radius);
  font-size: 13.5px; border: 1px solid transparent; margin-bottom: 1rem;
}
.alert--error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert--warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert--info { background: var(--info-soft); color: var(--text); border-color: var(--border); }
.alert--success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }

/* --- Autenticacao -------------------------------------------------------- */

.auth-card { width: 100%; max-width: 420px; padding: 2rem; text-align: center; }
.auth-card .brand__mark { width: 44px; height: 44px; font-size: 20px; margin: 0 auto 1rem; }
.auth-card h2 { font-size: 21px; }
.auth-card > p { color: var(--text-muted); font-size: 14px; margin-top: 0.4rem; }
.auth-card form { margin-top: 1.5rem; text-align: left; }
.auth-foot { margin-top: 1.5rem; font-size: 12.5px; color: var(--text-faint); }

.qr {
  width: 200px; height: 200px; margin: 0 auto; padding: 10px;
  background: #fff; border-radius: 12px; border: 1px solid var(--border);
}
.qr svg { width: 100%; height: 100%; stroke: none; }

.secret-box {
  font-family: var(--mono); font-size: 13.5px; letter-spacing: 0.08em; word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.6rem 0.75rem; text-align: center;
}

.recovery-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45rem;
  font-family: var(--mono); font-size: 13.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.85rem;
}
.recovery-grid span { text-align: center; }
.recovery-grid span.used { text-decoration: line-through; opacity: 0.45; }

.steps { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; justify-content: center; }
.step { width: 30px; height: 3px; border-radius: 2px; background: var(--border-strong); }
.step[data-on="1"] { background: var(--primary); }

/* --- Matriz de permissoes ------------------------------------------------ */

.matrix th.matrix__role { text-align: center; }

/* Grupos recolhiveis por categoria dentro da matriz */
.matrix__group td { background: var(--surface-2); }
.matrix__group td:first-child { padding: 0; }
.matrix__rootbox { accent-color: var(--primary); }
.matrix__toggle {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.6rem 1.25rem; border: none; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 650; color: var(--text); text-align: left;
}
.matrix__toggle:hover { background: var(--surface-3); }
.matrix__toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.matrix__chevron {
  width: 16px; height: 16px; flex: none; color: var(--text-muted);
  transition: transform 0.15s ease;
}
.matrix__toggle[aria-expanded="true"] .matrix__chevron { transform: rotate(90deg); }
.matrix td.matrix__cell { text-align: center; }
.matrix tbody td:first-child { min-width: 240px; }
.perm__name { font-weight: 550; }
.perm__key { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.5; }

/* --- Modal --------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(6, 9, 15, 0.55); padding: 1rem; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); margin: auto;
}
.modal--wide { max-width: 760px; }

/* Modal de tela cheia: para o editor, onde o documento e' o trabalho e nao um
 * detalhe a confirmar. A altura vem em cadeia — modal, corpo, editor e a caixa
 * de texto —, e cada elo precisa de `min-height: 0` porque item de flex nao
 * encolhe abaixo do proprio conteudo sem isso, e a caixa estouraria a janela em
 * vez de rolar por dentro. */
.modal--cheio {
  max-width: none;
  width: calc(100vw - 2rem);
  height: calc(100vh - 2rem);
  display: flex; flex-direction: column;
}
.modal--cheio .modal__body {
  flex: 1; min-height: 0; max-height: none; overflow: hidden;
  display: flex; flex-direction: column;
}
.modal--cheio .editor { flex: 1; min-height: 0; }
.modal--cheio .editor__texto,
.modal--cheio .editor__previa { flex: 1; min-height: 0; max-height: none; }
.modal__head { display: flex; align-items: flex-start; gap: 0.75rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal__title { font-size: 16px; }
.modal__desc { font-size: 13px; color: var(--text-muted); margin: 0.15rem 0 0; }
.modal__body { padding: 1.25rem; max-height: min(65vh, 640px); overflow-y: auto; }
.modal__foot { display: flex; gap: 0.6rem; justify-content: flex-end; padding: 1rem 1.25rem; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* --- Editor de documento -------------------------------------------------- */

.editor { display: flex; flex-direction: column; gap: 0.6rem; }
.editor__estado { min-height: 1.25em; }
.editor__texto {
  min-height: min(58vh, 520px);
  font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  resize: vertical;
  /* `pre` e nao `pre-wrap`: markdown de peca tem tabela, e quebrar a linha na
     largura da caixa desalinha justamente a tabela que a pessoa esta editando. */
  white-space: pre; overflow-x: auto;
}

/* Barra de formatacao: escreve Markdown na caixa, nao estiliza HTML. O arquivo
   continua sendo o .md que a indexacao le e que o download entrega. */
.editor__barra {
  display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap;
  padding: 0.35rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.editor__fmt, .editor__aba {
  min-width: 32px; height: 30px; padding: 0 0.5rem;
  border: 1px solid transparent; border-radius: 7px; background: none; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 550;
}
.editor__fmt:hover, .editor__aba:hover { background: var(--surface); color: var(--text); }
.editor__fmt:focus-visible, .editor__aba:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.editor__aba[aria-pressed="true"] {
  background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm);
}
.editor__sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 0.3rem; }

/* Previa: o mesmo desenho que vai para o papel. */
.editor__previa {
  min-height: min(58vh, 520px); max-height: min(58vh, 520px); overflow-y: auto;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  /* Caminho de arquivo e URL dentro de `code` nao tem espaco para quebrar: sem
     isto a previa ganha rolagem lateral no celular, e o texto sai da tela. */
  overflow-wrap: break-word;
}
.editor__previa code, .editor__previa a { overflow-wrap: anywhere; }
.editor__previa h2 { font-size: 20px; margin: 1.2rem 0 0.5rem; }
.editor__previa h3 { font-size: 16px; margin: 1rem 0 0.4rem; }
.editor__previa h4, .editor__previa h5, .editor__previa h6 { font-size: 14px; margin: 0.9rem 0 0.3rem; }
.editor__previa p { margin: 0 0 0.7rem; }
.editor__previa ul, .editor__previa ol { margin: 0 0 0.7rem; padding-left: 1.4rem; }
.editor__previa li { margin-bottom: 0.2rem; }
.editor__previa blockquote {
  margin: 0 0 0.7rem; padding: 0.1rem 0 0.1rem 0.9rem;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}
.editor__previa code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 0 0.25em; border-radius: 4px; }
.editor__previa hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Existe so para a impressao. Ver o bloco @media print abaixo. */
.editor__impressao { display: none; }

/* --- Impressao ------------------------------------------------------------
 *
 * Imprime o DOCUMENTO, nao a aplicacao. Sem isto sairia a barra lateral, o
 * cabecalho e o fundo escurecido do modal — e o texto sairia truncado na
 * primeira pagina, porque navegador imprime de <textarea> so a parte visivel.
 * Dai o `.editor__impressao`: mesmo conteudo, em fluxo normal, que pagina.
 */
@media print {
  @page { margin: 2cm; }

  body > *:not(#modal-root) { display: none !important; }

  #modal-root .modal-backdrop {
    position: static; display: block; background: none; padding: 0; overflow: visible;
  }
  #modal-root .modal {
    max-width: none; margin: 0; border: 0; border-radius: 0;
    box-shadow: none; background: #fff; animation: none;
  }
  .modal__head, .modal__foot, .editor__barra, .editor__estado,
  .editor__texto, .editor__previa, .editor .field__hint,
  .editor .row { display: none !important; }
  .modal__body { padding: 0; max-height: none; overflow: visible; }

  /* Sai o documento formatado, e nao os asteriscos do Markdown. */
  .editor__impressao {
    display: block; color: #000; font-size: 11pt; line-height: 1.55;
  }
  .editor__impressao h2 { font-size: 15pt; margin: 14pt 0 6pt; }
  .editor__impressao h3 { font-size: 13pt; margin: 12pt 0 5pt; }
  .editor__impressao p { margin: 0 0 8pt; text-align: justify; }
  .editor__impressao ul, .editor__impressao ol { margin: 0 0 8pt; padding-left: 18pt; }
  .editor__impressao blockquote {
    margin: 0 0 8pt; padding-left: 10pt; border-left: 2pt solid #999; color: #333;
  }
  .editor__impressao a { color: #000; text-decoration: underline; }
  .editor__impressao h2, .editor__impressao h3 { break-after: avoid; }
  .editor__impressao blockquote, .editor__impressao li { break-inside: avoid; }
}

/* --- Avisos flutuantes --------------------------------------------------- */

/* Barra de versao desatualizada. Acima dos avisos flutuantes e centralizada:
   nao e' notificacao de passagem, e' um estado da aba. */
.atualizacao {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 95;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  max-width: min(560px, calc(100vw - 2rem));
  padding: 0.7rem 0.8rem 0.7rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); font-size: 13.5px;
}

.toasts { position: fixed; bottom: 1rem; right: 1rem; z-index: 90; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(380px, calc(100vw - 2rem)); }
.toast {
  display: flex; gap: 0.6rem; align-items: flex-start;
  padding: 0.7rem 0.9rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: 13.5px;
  animation: toast-in 0.18s ease-out;
}
.toast--error { border-left: 3px solid var(--danger); }
.toast--success { border-left: 3px solid var(--success); }
.toast--info { border-left: 3px solid var(--primary); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* --- Utilitarios --------------------------------------------------------- */

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.pagination { display: flex; gap: 0.5rem; align-items: center; justify-content: flex-end; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

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

/* ── Utilitarios de layout ─────────────────────────────────────────────────
 *
 * Existem porque o CSP deste app e' `style-src 'self'` — sem `unsafe-inline`.
 * Um `style="..."` num elemento e' silenciosamente BLOQUEADO: o navegador
 * registra a violacao no console e a regra simplesmente nao vale. Nao da para
 * ver o defeito olhando a tela, so o layout sai errado.
 *
 * Afrouxar o CSP para `unsafe-inline` resolveria em uma linha e abriria a porta
 * que a politica existe para fechar. Estas classes sao o preco de manter a
 * porta fechada.
 */
.u-m-0 { margin: 0; }
.u-mb-0 { margin-bottom: 0; }
.u-mt-1 { margin: 0.35rem 0 0; }
.u-mt-2 { margin: 0.5rem 0 0; }
.u-mt-3 { margin: 0.6rem 0 0; }
.u-mt-4 { margin: 0.9rem 0 0; }
.u-mt-5 { margin: 1rem 0 0; }
.u-mt-5-mb-1 { margin: 1rem 0 0.35rem; }
.u-min-w-0 { min-width: 0; }
.u-self-end { align-self: flex-end; }
.u-cresce { flex: 1 1 280px; margin-bottom: 0; }

/* Listas de limitacoes dentro de cartao. */
.u-lista { margin: 0; padding-left: 1.15rem; }
.u-lista-mt { margin: 0.6rem 0 0; padding-left: 1.15rem; }

/* Texto de fonte juridica: quebras preservadas, sem estourar o cartao. */
.u-texto { white-space: pre-wrap; }
.u-texto-fonte { white-space: pre-wrap; overflow-wrap: anywhere; }
.u-texto-resultado {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font: inherit;
}

/* Marcadores do markdown minimo dos textos da base. */
.md-cit {
  display: block;
  border-left: 2px solid var(--border-strong);
  padding-left: 0.7rem;
  margin: 0.25rem 0;
  color: var(--text-muted);
}
.md-item {
  display: block;
  padding-left: 1rem;
  text-indent: -0.6rem;
}
.md-item::before {
  content: "· ";
  color: var(--text-faint);
}

/* ── Marca ─────────────────────────────────────────────────────────────────
 *
 * Quatro arquivos: B=branco, P=preto, G=com o texto ("Maiques Alves advogados
 * associados"), sem G=so o escudo.
 *
 * A troca e' por CSS e nao por JavaScript de proposito: o tema e' aplicado no
 * `<html>` antes do primeiro render, entao o logo certo aparece junto com o
 * resto — sem o piscar de trocar a imagem depois que a tela ja pintou.
 *
 * A cascata espelha a dos tokens de cor (linha 64): claro por padrao, escuro
 * pelo sistema quando o usuario nao fixou "claro", e escuro sempre que ele
 * fixou "escuro".
 */
.logo { display: block; height: auto; }
.logo--escuro { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo--claro { display: none; }
  :root:not([data-theme="light"]) .logo--escuro { display: block; }
}
:root[data-theme="dark"] .logo--claro { display: none; }
:root[data-theme="dark"] .logo--escuro { display: block; }

/* Lockup completo: so na entrada, onde ha espaco e a identidade importa. */
.logo-lockup { width: 100%; max-width: 260px; margin: 0 auto 1.25rem; }

/* Escudo sozinho: onde o espaco e' pequeno de verdade. */
.logo-marca { height: 38px; width: auto; flex: none; }

/* Lockup no menu lateral: largura cheia do bloco da marca. */
.logo-menu { width: 100%; max-width: 100%; }
.auth-card .logo-marca { height: 52px; margin: 0 auto 1rem; }
