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

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'ss01', 'cv11';
}

a { color: inherit; text-decoration: none; }

button { cursor: pointer; font: inherit; color: inherit; border: none; background: none; }

input, textarea, select {
  font: inherit;
  outline: none;
  background: none;
  border: none;
  color: var(--text);
}

code, kbd, pre, .mono { font-family: var(--font-mono); }

::selection { background: var(--accent-fill); color: var(--text); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ─── App shell ─────────────────────────────────────────────────────────── */
.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;   /* the room for the scrollbar is always kept: short and long pages and tabs line up */
}
/* The top bar is added by shell.js; until then its room is kept, so the page does not move down when it comes */
.main-content:not(:has(> .topbar))::before { content: ''; display: block; height: 52px; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
/* Switching pages: the browser keeps showing the old page until the new one can be drawn and cross-fades
   the two. The sidebar is a layer of its own, so it stays put instead of flashing. */
@view-transition { navigation: auto; }
.rail { view-transition-name: rail; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .12s; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

.rail {
  flex: 0 0 var(--rail-width);
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
  position: relative;
  z-index: 40;
  min-height: 0;
}

.sb-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
}
.rail-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rail-logo img { width: 32px; height: 32px; object-fit: contain; display: block; }
.sb-brand { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sb-brand-name { font-weight: 500; color: var(--text); }
.sb-brand-host { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sb-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px 12px;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.sb-item svg { flex-shrink: 0; color: var(--muted); width: 16px; height: 16px; }
.sb-item > span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item:hover { background: var(--hover); color: var(--text); }
.sb-item.active { background: var(--hover); color: var(--text); }
.sb-item.active svg { color: var(--text); }

.sb-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 8px 6px;
  font-size: 12px;
  color: var(--faint);
}
.sb-count { font-family: var(--font-mono); font-size: 11px; }
.sb-section-end { display: inline-flex; align-items: center; gap: 6px; }
.sb-add { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; color: var(--faint); }
.sb-add:hover { color: var(--text); background: var(--hover); }
.sb-add svg { width: 13px; height: 13px; }
/* Sections that fold away */
.sb-fold { padding-left: 2px; }
.sb-fold-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; color: inherit;
}
.sb-fold-btn:hover { color: var(--text-2); }
.sb-fold { justify-content: flex-start; gap: 2px; }
.sb-fold .sb-section-end { margin-left: auto; }
.sb-section-link, .sb-section-label { font: inherit; color: inherit; }
.sb-section-link { display: inline-flex; align-items: center; gap: 3px; }
.sb-section-link::after { content: '→'; opacity: 0; transform: translateX(-3px); transition: opacity var(--transition), transform var(--transition); }
.sb-section-link:hover { color: var(--text); }
.sb-section-link:hover::after { opacity: 1; transform: none; }
.sb-fold-btn svg { width: 12px; height: 12px; transform: rotate(90deg); transition: transform var(--transition); }
.sb-fold.folded .sb-fold-btn svg { transform: rotate(0deg); }
.sb-fold.folded + .sb-list { display: none; }
.sb-settings-links[hidden] { display: none; }
.sb-more { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px 2px; font-size: 12px; color: var(--muted); }
.sb-more:hover { color: var(--text); }
.sb-more svg { width: 12px; height: 12px; }
.sb-item-count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.sb-project-mark { display: inline-grid; place-items: center; width: 14px; color: var(--muted); flex: none; }

.sb-list { display: flex; flex-direction: column; gap: 1px; }
.sb-list .menu-item { min-height: 30px; padding: 4px 8px; font-size: 13px; }
.sb-list .menu-item-meta { font-size: 10px; }

.sb-help { display: flex; gap: 4px; padding: 6px 10px; border-top: 1px solid var(--line); }
.sb-help .sb-item { flex: 1; min-width: 0; min-height: 30px; padding: 4px 8px; justify-content: center; font-size: 12.5px; }

.sb-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.sb-user {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.sb-user:hover, .sb-user[aria-expanded="true"] { background: var(--hover); }
.sb-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sb-user-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11px; color: var(--muted); }
.sb-user-role:empty::before { content: ' a0'; }   /* keeps its line before the role is known */
.rail-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--hover);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sb-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}
.sb-icon-btn:hover { background: var(--hover); color: var(--text); }

/* Menu button in the top bar — only on small screens */
.nav-toggle {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  flex-shrink: 0;
}
.nav-toggle:hover { background: var(--hover); color: var(--text); }

/* ─── Flyouts & menus ───────────────────────────────────────────────────── */
.flyout {
  position: fixed;
  left: calc(var(--rail-width) + 8px);
  width: 260px;
  max-height: min(70vh, 520px);
  display: none;
  flex-direction: column;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--pop);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: pop-in 120ms ease;
}
.flyout.open { display: flex; }

@keyframes pop-in {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: none; }
}

.flyout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 8px;
  font-size: 12px;
  color: var(--muted);
}
.flyout-count { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.flyout-scroll { overflow-y: auto; min-height: 0; }
.flyout-empty { padding: 10px 8px; font-size: 12px; color: var(--muted); }

.flyout-user {
  display: flex;
  flex-direction: column;
  padding: 8px 8px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.flyout-user-name { font-weight: 500; }
.flyout-user-role { font-size: 12px; color: var(--muted); }
.flyout-version { padding: 8px 8px 2px; margin-top: 6px; border-top: 1px solid var(--line); font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.flyout-version:empty { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.menu-item:hover, .menu-item.active { background: var(--hover); color: var(--text); }
.menu-item svg { flex-shrink: 0; color: var(--muted); }
.menu-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item-meta { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.menu-item--danger, .menu-item--danger svg { color: var(--red); }
.menu-item--danger:hover { background: var(--red-bg); color: var(--red); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.dot--halo { box-shadow: 0 0 0 4px var(--halo, transparent); }

/* ─── Session timer (account menu) ──────────────────────────────────────── */
.session-timer-bar { padding: 4px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.session-timer-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.session-timer-track { height: 2px; background: var(--line-strong); border-radius: 2px; overflow: hidden; }
.session-timer-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 1s linear, background .5s ease; }

/* ─── Top bar ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 18px 48px 0;
  background: var(--bg);
}

.topbar-crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.topbar-crumbs a:hover { color: var(--text); }
.topbar-crumbs [aria-current="page"] { color: var(--text-2); }
.crumb-sep { color: var(--faint); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions:empty { display: none; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  min-width: 300px;
  padding: 0 8px 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--muted);
  transition: border-color var(--transition), color var(--transition);
}
.search-trigger:hover { border-color: var(--line-strong); color: var(--text-2); }
.search-trigger-text { flex: 1; text-align: left; }

kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: var(--hover);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ─── Page layout ───────────────────────────────────────────────────────── */
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 48px 72px;
}

/* ─── Command palette ───────────────────────────────────────────────────── */
.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding-top: 14vh;
  background: var(--scrim);
}
.palette-backdrop.open { display: flex; }

.palette {
  width: min(600px, calc(100vw - 32px));
  /* A fixed height: the box must not grow and shrink with the number of results while you type */
  height: min(440px, 60vh);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--pop);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: palette-in 140ms ease;
}
@keyframes palette-in {
  from { opacity: 0; transform: translateY(-6px) scale(.99); }
  to   { opacity: 1; transform: none; }
}

.palette-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 50px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.palette-input input { flex: 1; font-size: 15px; color: var(--text); }
/* The field fills the whole row: the square outline every focused input gets would float inside the rounded
   palette. The row shows the focus instead. */
.palette-input input:focus-visible { outline: none; box-shadow: none; }
.palette-input:focus-within { color: var(--text-2); border-bottom-color: var(--line-strong); }
.palette-input input::placeholder { color: var(--faint); }

.palette-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.palette-group { padding: 10px 10px 4px; font-size: 11px; color: var(--faint); letter-spacing: .02em; }
.palette-empty { padding: 28px; text-align: center; color: var(--muted); }

.palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-align: left;
}
.palette-item.selected { background: var(--hover); color: var(--text); }
.palette-lead { width: 16px; display: flex; justify-content: center; color: var(--muted); }
.palette-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-meta { font-size: 12px; color: var(--faint); }

/* ─── Small screens ─────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-lg);
    z-index: 120;
  }
  body.nav-open .rail { transform: none; }
  .nav-toggle { display: inline-flex; }
}

@media (max-width: 720px) {
  .topbar { padding: 14px 16px 0; }
  .search-trigger { min-width: 0; }
  .search-trigger-text, .search-trigger kbd { display: none; }
  .page { padding: 24px 16px 48px; }
}

.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;
}

/* ─── In-page dropdown menus ────────────────────────────────────────────── */
.menu-wrap { position: relative; display: inline-flex; }
.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 280px;
  display: none;
  flex-direction: column;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--pop);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  z-index: 50;
}
.menu-wrap.open .dropdown { display: flex; animation: drop-in 120ms ease; }
@keyframes drop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.dropdown .menu-item { align-items: flex-start; padding: 8px 10px; }
.dropdown .menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-item-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.menu-item-text > span { color: var(--text); }
.menu-item-text small { font-size: 12px; color: var(--muted); line-height: 1.4; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 2px; }
.dropdown-label { padding: 6px 10px 4px; font-size: 12px; color: var(--faint); }

/* Check indicator for toggle items (downtime / update mode) */
.menu-check {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  flex-shrink: 0;
}
.btn-mode.active-maintenance .menu-check { background: var(--red); border-color: var(--red); box-shadow: 0 0 0 3px var(--red-halo); }
.btn-mode.active-update .menu-check      { background: var(--yellow); border-color: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-halo); }

/* Account menu opens above the user button, inside the sidebar */
.flyout--bottom { left: 10px; width: calc(var(--rail-width) - 20px); }
.dropdown--wide { min-width: 340px; }
.menu-item--danger .menu-item-text > span { color: var(--red); }

/* ─── Notifications: bell, popover and inbox rows ───────────────────────── */
.bell-btn {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color var(--transition), color var(--transition);
}
.bell-btn:hover, .bell-btn[aria-expanded="true"] { border-color: var(--line-strong); color: var(--text); }
.bell-btn[data-open="1"] { color: var(--text-2); }
.bell-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--bg);
}
.bell-badge[hidden] { display: none; }

.notif-pop {
  position: fixed;
  width: min(400px, calc(100vw - 16px));
  max-height: min(75vh, 560px);
  display: none;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--pop);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  z-index: 70;
  animation: drop-in 120ms ease;
}
.notif-pop.open { display: flex; }
.notif-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}
.notif-open-count { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--red); }
.notif-pop-link { font-size: 12px; font-weight: 400; color: var(--muted); }
.notif-pop-link:hover { color: var(--text); }
.notif-pop-list { overflow-y: auto; min-height: 0; padding: 4px; }
.notif-pop-all {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-2);
  text-align: center;
}
.notif-pop-all:hover { color: var(--text); background: var(--hover); }
.notif-empty { padding: 20px 14px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.notif {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  color: inherit;
  position: relative;
}
a.notif:hover { background: var(--hover); }
.notif-sev {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--faint);
}
.notif[data-sev="critical"] .notif-sev { background: var(--red); box-shadow: 0 0 0 3px var(--red-halo); }
.notif[data-sev="warning"] .notif-sev  { background: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-halo); }
.notif[data-sev="resolved"] .notif-sev { background: var(--green); box-shadow: 0 0 0 3px var(--green-halo); }
.notif[data-sev="info"] .notif-sev     { background: var(--text-2); }
.notif-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.notif-title { color: var(--text); font-size: 13px; line-height: 1.4; }
.notif--unread .notif-title { font-weight: 500; }
.notif--unread::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.notif-state {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--red-border);
  color: var(--red);
  font-size: 11px;
  font-weight: 400;
  vertical-align: 1px;
}
.notif-state--muted { border-color: var(--line-strong); color: var(--muted); }
.notif-msg { font-size: 12.5px; color: var(--text-2); line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.notif-msg--clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-meta { font-size: 11.5px; color: var(--muted); }

.notif-list { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.notif-list .notif + .notif { border-top: 1px solid var(--line); border-radius: 0; }
.notif-list .notif { padding: 14px 12px; }
