/* ==========================================================================
   Base + application shell (sidebar, header, content frame)
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-body);
  font: 400 var(--text-base)/1.45 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; flex: none; }
code, pre, .mono { font-family: var(--font-mono); }
.mono { font-size: .96em; letter-spacing: -.01em; }
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 14px 0; }

::selection { background: var(--accent-soft); color: var(--text); }

/* DS-G: one visible focus ring for every focusable element (keyboard only). */
:focus-visible { outline: var(--focus-width) solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
.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; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* Utilities */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.strong { font-weight: 600; color: var(--text); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.gap-4 { gap: 4px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mb-12 { margin-bottom: 12px; }
.label {
  font: 650 var(--text-2xs)/1.2 var(--font-sans);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- App frame ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  transition: grid-template-columns .2s var(--ease);
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--chrome);
  color: var(--chrome-text);
  border-right: 1px solid var(--chrome-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--header-h); padding: 0 14px;
  border-bottom: 1px solid var(--chrome-border);
  color: var(--chrome-title); text-decoration: none; flex: none;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 28px; height: 28px; flex: none; border-radius: 7px;
  background: linear-gradient(145deg, #3b74ee, #1b3f9c);
  display: grid; place-items: center; color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand__name { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.brand__sub { font-size: 9px; letter-spacing: .055em; text-transform: uppercase; color: var(--chrome-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 8px 12px; scrollbar-color: var(--chrome-border) transparent; }
.nav__group + .nav__group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--chrome-border); }
.nav__label {
  font: 650 9.5px/1 var(--font-sans); letter-spacing: .11em; text-transform: uppercase;
  color: var(--chrome-muted); padding: 4px 8px 7px; white-space: nowrap;
}
.nav__item {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 8px; border-radius: var(--radius-control);
  color: var(--chrome-text); text-decoration: none; font-size: var(--text-sm); font-weight: 500;
  position: relative; white-space: nowrap;
  transition: background var(--dur), color var(--dur);
}
.nav__item:hover { background: var(--chrome-hover); color: var(--chrome-title); text-decoration: none; }
.nav__item svg { color: var(--chrome-muted); transition: color var(--dur); }
.nav__item:hover svg { color: var(--chrome-text); }
.nav__item[aria-current="page"] { background: var(--chrome-active-bg); color: var(--chrome-active-fg); font-weight: 600; }
.nav__item[aria-current="page"] svg { color: var(--chrome-accent); }
.nav__item[aria-current="page"]::before {
  content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--chrome-accent);
}
.nav__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav__badge {
  font: 650 10px/1 var(--font-mono); padding: 3px 5px; border-radius: 3px;
  background: rgba(255, 255, 255, .08); color: var(--chrome-text);
}
.nav__badge--alert { background: var(--sev-critical); color: #fff; }

.sidebar__foot {
  flex: none; border-top: 1px solid var(--chrome-border); padding: 8px;
  display: flex; align-items: center; gap: 8px; color: var(--chrome-muted); font-size: var(--text-2xs);
}
.sidebar__foot .env { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__toggle {
  width: 28px; height: 28px; border-radius: var(--radius-control); border: 0; background: transparent;
  color: var(--chrome-muted); display: grid; place-items: center; flex: none;
}
.sidebar__toggle:hover { background: var(--chrome-hover); color: #fff; }

.app[data-sidebar="collapsed"] .brand { padding: 0; justify-content: center; }
.app[data-sidebar="collapsed"] .brand__text,
.app[data-sidebar="collapsed"] .nav__label,
.app[data-sidebar="collapsed"] .nav__text,
.app[data-sidebar="collapsed"] .nav__badge,
.app[data-sidebar="collapsed"] .sidebar__foot .env { display: none; }
.app[data-sidebar="collapsed"] .nav__item { justify-content: center; padding: 0; }
.app[data-sidebar="collapsed"] .nav__item[aria-current="page"]::before { left: -8px; }
.app[data-sidebar="collapsed"] .sidebar__foot { justify-content: center; }

/* ---------- Main column ---------- */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }

.header {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 var(--gutter);
  background: var(--raised);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
}
.crumb { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 0 1 auto; white-space: nowrap; color: var(--text); font-weight: 600; font-size: var(--text-sm); }
.crumb__icon {
  width: 24px; height: 24px; border-radius: var(--radius-control); flex: none;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-soft-fg);
}
.crumb__desc { color: var(--text-muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header__spacer { flex: 1; min-width: 8px; }

.searchbox {
  display: flex; align-items: center; gap: 8px; height: 30px; flex: 0 1 260px; min-width: 38px; padding: 0 8px 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--sunken);
  color: var(--text-faint); font-size: var(--text-sm); text-align: left;
}
.searchbox:hover { border-color: var(--text-faint); color: var(--text-muted); }
.searchbox > span:first-of-type { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kbd {
  font: 600 10px/1 var(--font-mono); padding: 3px 5px; border-radius: 3px; flex: none; white-space: nowrap;
  border: 1px solid var(--border); background: var(--raised); color: var(--text-muted);
}

.scope {
  display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px 0 6px; max-width: 300px; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--raised);
  font-size: var(--text-sm); color: var(--text); font-weight: 550;
}
.scope:hover { border-color: var(--text-faint); background: var(--hover); }
.scope__avatar, .tenant-avatar {
  width: 20px; height: 20px; border-radius: 5px; flex: none; display: grid; place-items: center;
  font: 700 9.5px/1 var(--font-sans); color: #fff; letter-spacing: .02em;
}
.scope__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope__label { font: 650 9.5px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--text-faint); }

.trial-chip {
  display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 4px 0 10px; white-space: nowrap; flex: none;
  border-radius: var(--radius-control); background: var(--warning-soft); color: var(--warning);
  font-size: var(--text-xs); font-weight: 600; border: 1px solid color-mix(in oklab, var(--warning-solid) 35%, transparent);
}
.icon-btn {
  width: 30px; height: 30px; border-radius: var(--radius-control); border: 1px solid transparent; background: transparent;
  color: var(--text-muted); display: grid; place-items: center; flex: none; position: relative;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-soft-fg); }
.icon-btn__dot {
  position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--sev-critical); box-shadow: 0 0 0 2px var(--raised);
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast); font: 700 10.5px/1 var(--font-sans); letter-spacing: .02em; border: 0;
}
.avatar--sm { width: 22px; height: 22px; font-size: 9px; }
.avatar--lg { width: 40px; height: 40px; font-size: 14px; }
.userbtn { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 2px 4px 2px 2px; border-radius: 999px; flex: none; white-space: nowrap; }
.userbtn:hover { background: var(--hover); }
.userbtn__name { font-size: var(--text-sm); font-weight: 600; color: var(--text); white-space: nowrap; }
.userbtn__role { font-size: 10px; color: var(--text-faint); letter-spacing: .05em; text-transform: uppercase; }

.content {
  flex: 1; min-height: 0; overflow: auto;
  padding: 16px var(--gutter) 28px;
  position: relative;
}
.content--fill { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 16px; }
.table-host--fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.table-host--fill > .table-card { flex: 1; min-height: 0; }
.table-host--fill > .table-card > .table-scroll { flex: 1; min-height: 0; }

/* Banner under header (suspended tenant, read-only role, ...) */
.sysbar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 7px var(--gutter);
  font-size: var(--text-xs); border-bottom: 1px solid var(--border);
}
.sysbar--warn { background: var(--warning-soft); color: var(--warning); }
.sysbar--danger { background: var(--negative-soft); color: var(--negative); }
.sysbar--info { background: var(--info-soft); color: var(--info); }
.sysbar--shadow { background: var(--shadow-mode-bg); color: var(--shadow-mode-fg); border-bottom-color: var(--shadow-mode-line); }
.sysbar > span { line-height: 1.4; }
.sysbar .btn { flex: none; }

/* ---------- Page head ---------- */

.page-head {
  display: flex; align-items: flex-end; gap: 26px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px; min-height: 42px; flex: none;
}
.page-title {
  font-size: var(--text-2xl); font-weight: 680; letter-spacing: -.018em; line-height: 1.2;
  color: var(--text); margin: 0 0 9px; white-space: nowrap; display: flex; align-items: center; gap: 10px;
}
.page-head__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; padding-bottom: 7px; }

.tabs {
  display: flex; gap: 2px; align-self: flex-end; min-width: 0; overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); padding-right: 22px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 10px 9px; margin-bottom: -1px;
  color: var(--text-muted); font-weight: 550; font-size: var(--text-base);
  border: 0; border-bottom: 2px solid transparent; background: transparent;
  white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: color var(--dur), border-color var(--dur);
}
.tab:hover { color: var(--text); text-decoration: none; }
/* Long names (e.g. a 60-character root domain) are cut with an ellipsis; the full name is in the title. */
.tab > span:not(.count) { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab svg { opacity: .85; }
.tab__sep { width: 1px; height: 16px; background: var(--border); align-self: center; margin: 0 6px 2px; flex: none; }
.count {
  font: 650 var(--text-2xs)/1 var(--font-mono); padding: 3px 6px; border-radius: var(--radius-xs);
  background: var(--neutral-soft); color: var(--neutral-fg);
}
.tab[aria-selected="true"] .count { background: var(--accent-soft); color: var(--accent-soft-fg); }
.count.is-zero { color: var(--text-faint); background: transparent; box-shadow: inset 0 0 0 1px var(--border-subtle); }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; flex: none; }
.toolbar__spacer { flex: 1; }

/* Entry animation borrowed from Osmedeus (.og-stagger) */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.stagger > * { animation: rise .3s var(--ease) both; }
.stagger > :nth-child(2) { animation-delay: 40ms; }
.stagger > :nth-child(3) { animation-delay: 80ms; }
.stagger > :nth-child(4) { animation-delay: .12s; }
.stagger > :nth-child(n+5) { animation-delay: .16s; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}

@media (max-width: 1180px) {
  .searchbox { width: 38px; padding: 0; justify-content: center; }
  .searchbox { flex: none; width: 38px; }
  .searchbox > span { display: none; }
  .crumb__desc { display: none; }
  .userbtn__meta { display: none; }
}
/* ADR 0025: desktop-first. The half-finished stacking rules for narrow screens were removed; below 1024 px the app
   is replaced by a notice instead (see .narrow-notice). 1024–1279 px stays usable with the compact header above. */
.narrow-notice { display: none; }
@media (max-width: 1023.98px) {
  .narrow-notice { display: grid; }
}
:root.force-narrow .narrow-notice { display: grid; }
.narrow-notice {
  position: fixed; inset: 0; z-index: 140; place-items: center; padding: 24px; background: var(--page); color: var(--text-body); text-align: center;
}
.narrow-notice__card { max-width: 440px; background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-frame); padding: 28px 26px; box-shadow: var(--shadow-lg); }
.narrow-notice__card > svg { margin: 0 auto 12px; color: var(--accent); }
.narrow-notice__card h1 { font-size: var(--text-xl); color: var(--text); margin-bottom: 8px; }
.narrow-notice__card p { margin-top: 8px; font-size: var(--text-sm); }

/* Bare pages (sign-in placeholder): no sidebar, header or banners. */
.app.app--bare { grid-template-columns: minmax(0, 1fr); }
.app--bare .sidebar, .app--bare .header, .app--bare #sysbar { display: none; }

/* ---------- Brand = collapse toggle ---------- */
button.brand { width: 100%; border: 0; background: transparent; text-align: left; font: inherit; cursor: pointer; }
button.brand:hover { background: var(--chrome-hover); }
.brand__mark { width: 30px; height: 30px; border-radius: 8px; background: #fff; box-shadow: 0 0 0 1px var(--chrome-border); object-fit: contain; flex: none; }
.brand__name { font: 800 14px/1.1 var(--font-sans); letter-spacing: .06em; color: var(--chrome-title); }
.brand__sub { font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--chrome-muted); }
.brand__chev { margin-left: auto; color: var(--chrome-muted); display: grid; }
.nav__item[aria-current="page"]::before { background: var(--chrome-accent); }
.sidebar__foot { display: none; }
.app[data-sidebar="collapsed"] .brand__chev { display: none; }
.app[data-sidebar="collapsed"] .nav__item { position: relative; }
.app[data-sidebar="collapsed"] .nav__badge { display: block; position: absolute; top: 3px; right: 5px; padding: 0; width: 8px; height: 8px; font-size: 0; border-radius: 50%; background: #ffb020; }
.app[data-sidebar="collapsed"] .nav__badge--alert { background: #ff4d5e; }
