:root {
  --topbar: #242424;
  --topbar-text: #fff;
  --sidebar: #faf9f8;
  --sidebar-w: 260px;
  --canvas: #f5f5f5;
  --card: #ffffff;
  --border: #edebe9;
  --border-strong: #c8c6c4;
  --text: #242424;
  --muted: #605e5c;
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-soft: #ebf3fc;
  --ok: #0e700e;
  --ok-bg: #dff6dd;
  --warn: #8a6116;
  --warn-bg: #fff4ce;
  --danger: #b10e1e;
  --danger-bg: #fde7e9;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0,0,0,.06), 0 0 2px rgba(0,0,0,.04);
  --font: "Segoe UI", "Segoe UI Web (West European)", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Segoe UI Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
button, input, select { font: inherit; }

body.app-ready {
  background: var(--bg, #f5f5f5);
}

/* —— Gate / sign-in (login.html only) —— */
.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, #0f6cbd33, transparent 55%),
    linear-gradient(155deg, #1b1a19 0%, #2b2a29 48%, #f5f5f5 48.2%);
}
.gate-card {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: 12px;
  padding: 1.75rem 1.75rem 1.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  border: 1px solid #00000010;
}
.gate-brand {
  display: flex; align-items: center; gap: .5rem;
  margin: 0; color: var(--accent); font-weight: 600; font-size: .9rem;
}
.gate-brand svg { width: 20px; height: 20px; }
.gate-card h1 { margin: .4rem 0 .5rem; font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; }
.gate-lede { color: var(--muted); font-size: .92rem; line-height: 1.45; margin: 0 0 1.25rem; }
.gate-card label { display: block; margin: .9rem 0 .35rem; font-size: .82rem; font-weight: 600; }
.gate-card input {
  width: 100%; padding: .55rem .7rem;
  border: 1px solid var(--border-strong); border-radius: 4px;
}
.gate-card input:focus { outline: 2px solid #b3d6f5; border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: none; border-radius: 4px; padding: .55rem 1rem; font-weight: 600;
  cursor: pointer; transition: background .12s ease;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; margin-top: .25rem; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border-strong); width: 100%; margin-top: .65rem; }
.btn-secondary:hover { background: #f5f5f5; }
.btn-ghost { background: transparent; color: #fff; border: 0; padding: .35rem .55rem; font-weight: 500; }
.btn-ghost:hover { background: #ffffff18; }
.gate-tenant { margin-top: .75rem; font-size: .78rem; color: var(--muted); word-break: break-all; }
#gate-breakglass { margin-top: 1.25rem; }
#gate-breakglass details { border-top: 1px solid var(--border); padding-top: .9rem; }
#gate-breakglass summary { cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 600; }
.error { color: var(--danger); font-size: .9rem; margin-top: .75rem; }

/* —— Shell —— */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .65rem;
  height: 48px; padding: 0 .75rem 0 .5rem;
  background: var(--topbar); color: var(--topbar-text);
  position: sticky; top: 0; z-index: 30;
}
.top-brand {
  display: inline-flex; align-items: center; gap: .45rem;
  color: #fff; font-weight: 600; text-decoration: none; white-space: nowrap; padding: 0 .35rem;
}
.top-brand:hover { text-decoration: none; opacity: .92; }
.top-brand svg { width: 22px; height: 22px; }
.search {
  flex: 1; max-width: 420px; margin-left: .5rem;
  display: flex; align-items: center; gap: .4rem;
  background: #3b3a39; border-radius: 4px; padding: 0 .55rem; height: 32px;
}
.search svg { width: 14px; height: 14px; opacity: .75; }
.search input {
  flex: 1; border: 0; background: transparent; color: #fff; outline: none; font-size: .88rem;
}
.search input::placeholder { color: #c8c6c4; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .45rem; }
.identity { display: flex; align-items: center; gap: .35rem; max-width: min(420px, 55vw); }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: #3b3a39; color: #f3f2f1; border-radius: 999px;
  padding: .2rem .65rem; font-size: .75rem; font-weight: 600;
}
.chip svg { width: 12px; height: 12px; }
#actor-chip {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
}
.role-switcher {
  display: inline-block;
  appearance: auto;
  -webkit-appearance: menulist;
  border: 1px solid #605e5c;
  cursor: pointer;
  min-width: 8.5rem;
  max-width: 11rem;
  color: #f3f2f1;
  line-height: 1.2;
  background-color: #3b3a39;
  padding: .25rem .5rem;
}
.role-switcher:hover { background-color: #484644; }
.role-switcher option { color: #242424; background: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; background: transparent; border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 4px; cursor: pointer; flex-shrink: 0;
  opacity: .78;
}
.icon-btn:hover { background: #ffffff18; opacity: 1; }
.icon-btn svg { width: 18px; height: 18px; }

.body { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar); border-right: 1px solid var(--border);
  padding: .75rem 0 1.5rem; overflow: auto;
  transition: width .18s ease;
}
.sidebar nav { display: flex; flex-direction: column; gap: .1rem; padding: 0 .5rem; }
.nav-group {
  margin: 0; padding: 0; border: 0;
}
.nav-group > .nav-section {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; justify-content: flex-start; gap: .45rem;
}
.nav-group > .nav-section::-webkit-details-marker { display: none; }
.nav-group > .nav-section::before {
  content: "";
  width: .38rem; height: .38rem; flex-shrink: 0;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  opacity: .7;
  transition: transform .15s ease;
  margin-left: .2rem;
}
.nav-group[open] > .nav-section::before {
  transform: rotate(45deg);
  margin-top: -.1rem;
}
.nav-section {
  margin: .85rem .65rem .25rem; font-size: .68rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.nav-group > .nav-section:hover { color: var(--text); }
.nav-link {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .65rem; border-radius: 4px;
  color: var(--text); text-decoration: none; font-size: .9rem; font-weight: 500;
}
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.nav-link:hover { background: #00000008; text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link.active svg { color: var(--accent); }

.app.nav-collapsed {
  --sidebar-w: 56px;
}
.app.nav-collapsed .sidebar {
  overflow-x: hidden;
}
.app.nav-collapsed .nav-group > .nav-section {
  display: none;
}
.app.nav-collapsed .nav-group {
  display: contents;
}
.app.nav-collapsed .nav-label {
  display: none;
}
.app.nav-collapsed .nav-link {
  justify-content: center;
  padding: .55rem .4rem;
}
.app.nav-collapsed .top-brand {
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main { flex: 1; padding: 1.25rem 1.5rem 2.5rem; overflow: auto; min-width: 0; }
.page-title { margin: 0 0 .35rem; font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; }
.page-sub { margin: 0 0 1.25rem; color: var(--muted); font-size: .92rem; }

.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .85rem; margin-bottom: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: .85rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 .5rem; font-size: 1rem; font-weight: 600; }
.stat-label { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-label svg { width: 14px; height: 14px; }
.stat-value { margin: .35rem 0 0; font-size: 1.65rem; font-weight: 600; letter-spacing: -.03em; }
.stat-hint { margin: .25rem 0 0; font-size: .8rem; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: .25rem; border-radius: 999px; padding: .12rem .5rem; font-size: .72rem; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }

table.data { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data th, table.data td { text-align: left; padding: .65rem .85rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
table.data th { background: #faf9f8; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
table.data tr:last-child td { border-bottom: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.list-plain { margin: 0; padding-left: 1.1rem; }
.list-plain li { margin: .35rem 0; }
.muted { color: var(--muted); }
.section-title { margin: 1.5rem 0 .75rem; font-size: 1.1rem; font-weight: 600; }
.shortcut {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .85rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
}
.shortcut-icon {
  width: 36px; height: 36px; border-radius: 8px; background: var(--accent-soft);
  display: grid; place-items: center; color: var(--accent); flex-shrink: 0;
}
.shortcut-icon svg { width: 18px; height: 18px; }
.shortcut h3 { margin: 0 0 .2rem; font-size: .95rem; }
.shortcut p { margin: 0; font-size: .82rem; color: var(--muted); }

.spark { display: block; margin-top: .35rem; }
.bar-row { display: grid; grid-template-columns: 7rem 1fr 3.5rem; gap: .5rem; align-items: center; margin: .4rem 0; font-size: .82rem; }
.bar-label { color: var(--muted); font-weight: 600; }
.bar-track { height: 8px; background: #edebe9; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-value { text-align: right; color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .45rem .9rem; border-radius: 6px; border: 1px solid transparent;
  font-weight: 600; font-size: .88rem; cursor: pointer; width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: #f3f2f1; }
.api-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.api-toolbar .btn { width: auto; }
.code-block {
  margin: 0; padding: .85rem 1rem; border-radius: var(--radius);
  background: #1b1a19; color: #f3f2f1; font-family: var(--mono); font-size: .78rem;
  line-height: 1.45; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.swagger-host {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem; min-height: 24rem; overflow: auto;
}
.swagger-host .swagger-ui .topbar { display: none; }
.guide-layout { display: grid; grid-template-columns: 220px 1fr; gap: 1.25rem; align-items: start; }
.guide-sidebar {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem; position: sticky; top: .5rem; max-height: calc(100vh - 6rem); overflow: auto;
}
.guide-nav-group { margin-bottom: 1rem; }
.guide-nav-group h3 { margin: 0 0 .4rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.guide-nav-link {
  display: block; padding: .35rem .45rem; border-radius: 4px; color: var(--text);
  font-size: .88rem; text-decoration: none;
}
.guide-nav-link:hover { background: #00000008; text-decoration: none; }
.guide-nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.guide-main { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.guide-toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: .65rem 1rem; margin: 0 0 1rem; padding-bottom: .85rem; border-bottom: 1px solid var(--border);
}
.guide-toolbar .guide-eyebrow { margin: 0; flex: 1 1 12rem; }
.guide-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.guide-article .guide-h { margin: 1.25rem 0 .5rem; }
.guide-article h1.guide-h { margin-top: 0; font-size: 1.45rem; }
.guide-article h2.guide-h { font-size: 1.15rem; }
.guide-eyebrow { margin: 0 0 1rem; font-size: .82rem; color: var(--muted); }
.guide-ul, .guide-ol { margin: .5rem 0 1rem; padding-left: 1.25rem; }
.guide-pre { margin: .75rem 0; }
.guide-pre code { display: block; padding: .85rem 1rem; background: #1b1a19; color: #f3f2f1; border-radius: 6px; font-size: .78rem; overflow: auto; }
.guide-figure {
  margin: 1rem 0 1.25rem; padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: #faf9f8; overflow: hidden;
}
.guide-shot { display: block; width: 100%; height: auto; }
.guide-figure figcaption {
  margin: 0; padding: .45rem .75rem; font-size: .78rem; color: var(--muted);
  border-top: 1px solid var(--border); background: #fff;
}
.search-results { display: flex; flex-direction: column; gap: .5rem; }
.search-hit {
  display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; align-items: baseline;
  padding: .85rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.search-hit:hover { border-color: var(--accent); text-decoration: none; }
.search-hit .badge { grid-row: span 2; }
.search-hit strong { font-size: .95rem; }
.search-hit .muted { grid-column: 2; font-size: .85rem; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 800px) {
  .sidebar {
    position: fixed; inset: 48px auto 0 0; z-index: 25;
    width: min(280px, 86vw);
    transform: translateX(-105%); transition: transform .18s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.12); height: calc(100% - 48px);
  }
  .sidebar.open { transform: translateX(0); }
  .app.nav-collapsed { --sidebar-w: 260px; }
  .app.nav-collapsed .nav-group > .nav-section { display: flex; }
  .app.nav-collapsed .nav-group { display: block; }
  .app.nav-collapsed .nav-label { display: inline; }
  .app.nav-collapsed .nav-link { justify-content: flex-start; padding: .45rem .65rem; }
  .grid-4, .grid-2 { grid-template-columns: 1fr; }
  .search { display: none; }
  .guide-layout { grid-template-columns: 1fr; }
  .guide-sidebar { position: static; max-height: none; }
}
