/* ============================================================
   The app shell: navy rail, white topbar, light canvas.

   The rail is the only dark surface in the product. Everything
   else is a light working surface. That contrast is what makes
   navigation and content read as two different things.
   ============================================================ */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 160ms ease;
}

.shell.is-collapsed {
  grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr);
}

/* ---------- Rail ---------- */

.rail {
  background: var(--rail);
  color: var(--ink-on-dark);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 30;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  color: var(--ink-inverse);
  font-weight: 600;
  font-size: var(--text-md);
  white-space: nowrap;
}

.rail-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--s3) var(--s3);
  scrollbar-width: none;              /* the rail is a fixed list, not a document */
}

.rail-nav::-webkit-scrollbar { display: none; }

.rail-group { margin-top: var(--s4); }

.rail-group:first-child { margin-top: 0; }

.rail-group-label {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-on-dark-dim);
  padding: 0 var(--s3);
  margin-bottom: var(--s1);
  white-space: nowrap;
}

.rail-link {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 7px var(--s3);
  border-radius: var(--r-md);
  color: var(--ink-on-dark);
  font-size: var(--text-md);
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}

.rail-link:hover {
  background: var(--rail-hover);
  color: var(--ink-inverse);
  text-decoration: none;
}

/* The active item is the one place the accent appears on the rail.
   The icon follows via currentColor -- no second asset, no JS. */
.rail-link.is-active {
  background: var(--accent);
  color: var(--ink-inverse);
  font-weight: 500;
}

.rail-link.is-active:hover { background: var(--accent-hover); }

/* Not yet available. Visible, but honest about it -- a nav item that
   silently does nothing is worse than one that says why. */
.rail-link.is-pending {
  color: var(--ink-on-dark-dim);
}

.rail-foot {
  border-top: 1px solid var(--rail-border);
  padding: var(--s3);
}

.rail-collapse {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-on-dark-dim);
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
}

.rail-collapse:hover {
  background: var(--rail-hover);
  color: var(--ink-inverse);
}

/* ---------- Collapsed state ---------- */

.shell.is-collapsed .rail-label,
.shell.is-collapsed .rail-group-label,
.shell.is-collapsed .rail-brand-text {
  display: none;
}

.shell.is-collapsed .rail-link,
.shell.is-collapsed .rail-collapse,
.shell.is-collapsed .rail-brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.shell.is-collapsed .rail-group {
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--rail-border);
}

.shell.is-collapsed .rail-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.shell.is-collapsed .rail-collapse .icon {
  transform: rotate(180deg);
}

/* ---------- Main column ---------- */

.shell-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: var(--topbar-h);
  padding: var(--s3) var(--s6);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-toggle {
  display: none;   /* desktop collapses from the rail foot */
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  padding: var(--s2);
  border-radius: var(--r-md);
}

.topbar-toggle:hover { background: var(--surface-sunken); }

.topbar-heading {
  flex: 1 1 auto;
  min-width: 0;          /* without this a flex child refuses to shrink */
  overflow: hidden;
}

.topbar-title {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-subtitle {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex: 0 1 auto;
  min-width: 0;
}

.topbar-picker { min-width: 220px; }

.topbar-stamp {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--text-xs);
  color: var(--ink-muted);
  white-space: nowrap;
}

.stamp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}

.topbar-icon-btn {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  padding: var(--s2);
  border-radius: var(--r-md);
  display: inline-flex;
}

.topbar-icon-btn:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

/* The count is the live open-anomaly count. It is the same number the
   alerts panel shows -- not a decorative badge. */
.bell-count {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.bell-count:empty { display: none; }

.bell-panel {
  position: absolute;
  top: calc(var(--topbar-h) - 6px);
  right: var(--s6);
  width: 340px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  z-index: 40;
}

.bell-panel[hidden] { display: none; }

.bell-panel-head {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
  font-weight: 600;
}

.bell-item {
  display: flex;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}

.bell-item:last-child { border-bottom: 0; }

.bell-item-title { font-size: var(--text-sm); }

.bell-item-meta {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.topbar-profile {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--text-sm);
  color: var(--ink);
  white-space: nowrap;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex: none;
}

/* ---------- Content ---------- */

.content {
  flex: 1;
  min-width: 0;
  padding: var(--s6);
}

/* ---------- Empty state ----------
   An empty screen is an invitation to act, not an apology. */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s10) var(--s6);
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
}

.empty-state .icon {
  width: 28px;
  height: 28px;
  color: var(--ink-faint);
}

.empty-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.empty-body {
  font-size: var(--text-md);
  color: var(--ink-muted);
  max-width: 46ch;
}

/* ---------- Scrim (mobile drawer) ---------- */

.rail-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .shell,
  .shell.is-collapsed {
    grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr);
  }

  .rail-label,
  .rail-group-label,
  .rail-brand-text { display: none; }

  .rail-link,
  .rail-collapse,
  .rail-brand { justify-content: center; padding-left: 0; padding-right: 0; }

  /* The heading gives way before the controls do -- a truncated title is
     recoverable, a truncated dataset picker is not. */
  .topbar-heading { flex: 1 1 0; }
  .topbar-picker { min-width: 150px; }
  .topbar-subtitle,
  .topbar-stamp { display: none; }
  .topbar-profile span { display: none; }
}

@media (max-width: 760px) {
  /* Mobile: the rail leaves the flow entirely and slides over. */
  .shell,
  .shell.is-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--rail-w);
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .shell.is-open .rail { transform: translateX(0); }
  .shell.is-open .rail-scrim { display: block; }

  .shell .rail-label,
  .shell .rail-group-label,
  .shell .rail-brand-text { display: block; }

  .shell .rail-link,
  .shell .rail-collapse,
  .shell .rail-brand {
    justify-content: flex-start;
    padding-left: var(--s3);
    padding-right: var(--s3);
  }

  .rail-foot { display: none; }

  .topbar-toggle { display: inline-flex; }
  .topbar { padding: var(--s3) var(--s4); gap: var(--s3); }
  .topbar-subtitle { display: none; }
  .topbar-picker { min-width: 130px; }
  .topbar-profile span { display: none; }
  .bell-panel { right: var(--s3); width: calc(100vw - var(--s6)); }

  .content { padding: var(--s4); }
}

/* Nothing may widen the page. Wide content scrolls inside its own container. */
.shell {
  max-width: 100%;
}

.shell-main,
.content,
.page {
  max-width: 100%;
  overflow-x: hidden;
}
.card { overflow-x: hidden; }