/* ==========================================================================
   Cerberus — components this product needs and LogPose did not.

   Everything here resolves to the shared token layer: no literal colour, no
   literal radius. If a value looks arbitrary it is a bug, not a decision.

   Four families:
     .perm-*     the permission catalog / policy editor (checkbox tree)
     .pill-*     level and status pills (read / write / delete / admin)
     .card-*     the entity cards used by Policies, Groups and Services
     .sim-*      the simulator's question-and-verdict panel
   ========================================================================== */

/* ------------------------------------------------------------------ layout */
.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 22px; flex-wrap: wrap;
}
.page-head .page-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-head h1 { font-size: var(--fs-2xl); letter-spacing: -0.024em; }
.page-head .page-sub { color: var(--fg-muted); font-size: var(--fs-md); max-width: 68ch; }
.page-head .page-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }

.crumb {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-faint); font-size: var(--fs-xs); font-weight: 550;
  margin-bottom: 10px;
}
.crumb a { color: var(--fg-muted); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------------- cards */
.card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
}
a.card:hover {
  text-decoration: none;
  border-color: var(--accent-edge);
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  color: var(--fg-strong); font-weight: 620; letter-spacing: -0.012em;
}
.card-title .lucide { color: var(--fg-faint); }
/* The raw key, shown next to a curated policy's label only in technical mode
   -- the business-facing view never needs to know a policy has a key at all. */
.card-key {
  font-family: var(--font-mono); font-weight: 400; font-size: var(--fs-2xs);
  color: var(--fg-faint); letter-spacing: 0;
}
.card-desc { color: var(--fg-muted); font-size: var(--fs-sm); line-height: 1.45; }
.card-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: auto; padding-top: 8px;
  color: var(--fg-faint); font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.card-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------------- pills */
/* Level is the one dimension the whole product is organised by, so it gets a
   consistent colour everywhere: catalogue, policy editor, person detail. */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 21px; padding: 0 8px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  color: var(--fg-muted);
  font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill[data-level="read"]   { color: var(--info); border-color: color-mix(in oklab, var(--info) 34%, transparent); }
.pill[data-level="write"]  { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 34%, transparent); }
.pill[data-level="delete"] { color: var(--bad);  border-color: color-mix(in oklab, var(--bad) 34%, transparent); }
.pill[data-level="admin"]  { color: var(--accent); border-color: var(--accent-edge); background: var(--accent-wash); }
.pill-managed { color: var(--accent); border-color: var(--accent-edge); background: var(--accent-wash); }
/* The curated policies from policies.yaml -- the ones meant to be granted,
   as opposed to the mechanical per-resource fallback (.pill-managed). */
.pill-curated { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 34%, transparent); }
.pill-service { font-family: var(--font-mono); letter-spacing: 0; }
.pill-ok  { color: var(--ok);  border-color: color-mix(in oklab, var(--ok) 34%, transparent); }
.pill-bad { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 34%, transparent); }

.pill-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* --------------------------------------------------------- permission tree */
/* The policy editor. Deliberately not a list of endpoints: an admin grants
   "Portioning / write", and only expands a row when they want to know exactly
   which URLs that means. */
.perm-group {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  overflow: hidden;
  margin-bottom: 12px;
}
.perm-group-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  font-weight: 620; color: var(--fg-strong);
}
.perm-group-head .svc-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--svc-color, var(--fg-faint));
}
.perm-group-head .spacer { flex: 1; }

.perm-resource { border-bottom: 1px solid var(--line); }
.perm-resource:last-child { border-bottom: none; }
.perm-resource-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px 5px;
  color: var(--fg-muted);
  font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
}

.perm-row {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background-color var(--t-instant) var(--ease-out);
}
.perm-row:hover { background: var(--bg-raised); }
.perm-row input[type="checkbox"] { margin-top: 2px; accent-color: var(--accent); width: 15px; height: 15px; }
.perm-row-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.perm-row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.perm-key {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  color: var(--fg-strong); font-weight: 550;
}
.perm-label { color: var(--fg-muted); font-size: var(--fs-sm); }
.perm-routes {
  display: none;
  margin: 4px 0 0; padding: 7px 9px;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: var(--fs-2xs);
  color: var(--fg-faint); line-height: 1.7;
}
.perm-routes.is-open { display: block; }
.perm-routes .m { color: var(--fg-muted); font-weight: 600; }

/* --------------------------------------------------------------- simulator */
.sim-panel {
  padding: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.sim-form { display: grid; grid-template-columns: 1.4fr 1fr 0.8fr 2fr auto; gap: 10px; align-items: end; }
@media (max-width: 1000px) { .sim-form { grid-template-columns: minmax(0, 1fr); } }

.sim-verdict {
  display: flex; align-items: flex-start; gap: 14px;
  margin-top: 18px; padding: 18px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--bg-sunken);
}
.sim-verdict[data-verdict="allow"] {
  border-color: color-mix(in oklab, var(--ok) 40%, transparent);
  background: color-mix(in oklab, var(--ok) 8%, var(--bg-surface));
}
.sim-verdict[data-verdict="deny"] {
  border-color: color-mix(in oklab, var(--bad) 40%, transparent);
  background: color-mix(in oklab, var(--bad) 8%, var(--bg-surface));
}
.sim-icon { flex: none; margin-top: 1px; }
.sim-verdict[data-verdict="allow"] .sim-icon { color: var(--ok); }
.sim-verdict[data-verdict="deny"]  .sim-icon { color: var(--bad); }
.sim-headline { font-weight: 620; color: var(--fg-strong); font-size: var(--fs-lg); }
.sim-why { margin-top: 6px; color: var(--fg-muted); font-size: var(--fs-sm); line-height: 1.5; }
.sim-why code { font-family: var(--font-mono); color: var(--fg-strong); }

/* ------------------------------------------------------------------ tables */
.doc-table td .sub { display: block; color: var(--fg-faint); font-size: var(--fs-xs); margin-top: 2px; }
.doc-table tr.is-revoked td { opacity: 0.55; }
.cell-actions { text-align: right; white-space: nowrap; }
.mono-cell { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--fg-muted); }

/* ------------------------------------------------------------------- forms */
.form-grid { display: grid; gap: 14px; max-width: 640px; }
.form-row { display: grid; gap: 6px; }
.form-row label { font-size: var(--fs-xs); font-weight: 600; color: var(--fg-muted); }
.form-row .hint { font-size: var(--fs-xs); color: var(--fg-faint); }
textarea.input { min-height: 76px; resize: vertical; font-family: inherit; line-height: 1.5; }

.sticky-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  margin-top: 18px; padding: 12px 16px;
  background: var(--bg-glass);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.sticky-actions .spacer { flex: 1; }
.save-state { color: var(--fg-faint); font-size: var(--fs-xs); }
.save-state[data-state="saved"] { color: var(--ok); }
.save-state[data-state="error"] { color: var(--bad); }

/* ------------------------------------------------------------------- empty */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 54px 24px; text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  color: var(--fg-muted);
}
.empty .lucide { width: 26px; height: 26px; color: var(--fg-faint); }
.empty strong { color: var(--fg-strong); font-weight: 620; }
.empty p { margin: 0; max-width: 52ch; font-size: var(--fs-sm); }

/* ------------------------------------------------------------------ dialog */
.modal-scrim {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg-scrim);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade-in var(--t-fast) var(--ease-out);
}
.modal {
  width: min(560px, 100%);
  max-height: 86vh; overflow-y: auto;
  padding: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  animation: modal-in var(--t-base) var(--ease-expo);
}
.modal h2 { margin-bottom: 4px; }
.modal .modal-sub { color: var(--fg-muted); font-size: var(--fs-sm); margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ toasts */
.toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm); color: var(--fg-strong);
  animation: toast-in var(--t-base) var(--ease-expo);
}
.toast[data-tone="bad"] { border-left-color: var(--bad); }
.toast[data-tone="ok"]  { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------- login */
/* The sign-in page mounts Clerk's own component, so it needs a slot big enough
   for it and nothing else — the card chrome comes from panels.css. */
.clerk-slot { display: flex; justify-content: center; min-height: 380px; }
.login-note {
  max-width: 380px; padding: 11px 13px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--fg-muted); font-size: var(--fs-xs); line-height: 1.55;
}
.login-note code { font-family: var(--font-mono); color: var(--fg-strong); }
