:root {
  --atlas-brand: #1f4d80;
  --atlas-sidebar-w: 250px;

  /* Surface tokens — swapped wholesale under [data-bs-theme="dark"] below so
     the custom .atlas-* chrome tracks Bootstrap's own dark theming. */
  --atlas-surface: #fff;
  --atlas-border: #e5e7eb;
  --atlas-border-soft: #eef0f2;
  --atlas-nav-text: #374151;
  --atlas-nav-text-hover: #111827;
  --atlas-nav-hover-bg: #f3f4f6;
  --atlas-nav-muted: #9ca3af;
  --atlas-active-bg: rgba(31, 77, 128, 0.1);
  --atlas-active-text: var(--atlas-brand);
  --atlas-soon-bg: #eef0f2;
  --atlas-soon-text: #6b7280;
}

[data-bs-theme="dark"] {
  --atlas-surface: #1a1d21;
  --atlas-border: #2c3034;
  --atlas-border-soft: #2c3034;
  --atlas-nav-text: #adb5bd;
  --atlas-nav-text-hover: #f8f9fa;
  --atlas-nav-hover-bg: #2c3034;
  --atlas-nav-muted: #6c757d;
  --atlas-active-bg: rgba(138, 180, 232, 0.16);
  --atlas-active-text: #8ab4e8;
  --atlas-soon-bg: #2c3034;
  --atlas-soon-text: #adb5bd;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  margin: 0;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* ── App shell: fixed-width left sidebar + fluid main column ────────────── */
.atlas-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.atlas-sidebar {
  --bs-offcanvas-width: var(--atlas-sidebar-w);
  width: var(--atlas-sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--atlas-surface);
  border-right: 1px solid var(--atlas-border);
}

.atlas-sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--atlas-border-soft);
}

.atlas-brand {
  color: var(--atlas-brand);
  font-weight: 600;
  font-size: 1.15rem;
  text-decoration: none;
}
.atlas-brand:hover { color: var(--atlas-brand); }

.atlas-sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem;
}

.atlas-sidebar-footer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--atlas-border-soft);
}

/* ── Account menu (top-right) ──────────────────────────────────────────── */
.atlas-usermenu-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 2rem;
  color: var(--atlas-nav-text);
}
.atlas-usermenu-btn:hover { background: var(--atlas-nav-hover-bg); }
.atlas-usermenu-name { font-size: 0.9rem; font-weight: 500; }
.atlas-usermenu-caret { font-size: 0.75rem; color: var(--atlas-nav-muted); }

.atlas-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}
.atlas-avatar-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--atlas-brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}
.atlas-usermenu .dropdown-menu { min-width: 14rem; }

/* ── Theme toggle (next to the account menu) ───────────────────────────── */
.atlas-theme-btn {
  border: none;
  background: none;
  color: var(--atlas-nav-text);
  padding: 0.35rem 0.55rem;
  border-radius: 0.4rem;
  font-size: 1.1rem;
  line-height: 1;
}
.atlas-theme-btn:hover { background: var(--atlas-nav-hover-bg); color: var(--atlas-nav-text); }

/* ── Nav links & collapsible groups ────────────────────────────────────── */
.atlas-nav .nav-link,
.atlas-nav-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 0.4rem;
  background: none;
  color: var(--atlas-nav-text);
  font-size: 0.92rem;
}
.atlas-nav .nav-link:hover,
.atlas-nav-group:hover {
  background: var(--atlas-nav-hover-bg);
  color: var(--atlas-nav-text-hover);
}
.atlas-nav .bi {
  font-size: 1.05rem;
  width: 1.2rem;
  text-align: center;
  flex: none;
}
.atlas-nav-link span { flex: 1 1 auto; }

.atlas-nav-group { cursor: pointer; }
.atlas-nav-caret {
  font-size: 0.8rem !important;
  transition: transform 0.15s ease;
}
.atlas-nav-group.collapsed .atlas-nav-caret { transform: rotate(-90deg); }

.atlas-nav-children {
  margin: 0.1rem 0 0.35rem;
  padding-left: 0.85rem;
}
.atlas-nav-children .nav-link {
  font-size: 0.88rem;
  padding: 0.4rem 0.75rem;
}

.atlas-nav-link.active {
  background: var(--atlas-active-bg);
  color: var(--atlas-active-text);
  font-weight: 600;
}

/* Coming-soon stubs read as muted until their page lands. */
.atlas-nav-stub { color: var(--atlas-nav-muted); }
.atlas-nav-soon {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--atlas-soon-bg);
  color: var(--atlas-soon-text);
  margin-left: auto;
}
.atlas-nav-stub.active { color: var(--atlas-active-text); background: var(--atlas-active-bg); }

/* ── Main column ───────────────────────────────────────────────────────── */
.atlas-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.atlas-topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0.5rem 1rem;
  background: var(--atlas-surface);
  border-bottom: 1px solid var(--atlas-border);
}
.atlas-topbar-spacer { flex: 1 1 auto; }

/* Blazor circuit error banner — hidden until Blazor toggles it on. */
#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0.75rem 1.25rem;
  background: #dc3545;
  color: #fff;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.2);
}
#blazor-error-ui .reload { color: #fff; text-decoration: underline; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* Blazor reconnect overlay — shown while a dropped circuit reconnects; on
   terminal failure (new deploy) blazor-reconnect-reload.js reloads the page. */
#components-reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 1050;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
#components-reconnect-modal .components-reconnect-box {
  background: var(--atlas-surface);
  color: var(--atlas-nav-text);
  border: 1px solid var(--atlas-border);
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* ── Device status dot ─────────────────────────────────────────────────── */
.atlas-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
  background: #adb5bd;
}
.atlas-status-dot.green { background: #198754; }
.atlas-status-dot.yellow { background: #ffc107; }
.atlas-status-dot.red { background: #dc3545; }

/* Spin a Bootstrap icon while a background action runs (e.g. Refresh in flight). */
.atlas-spin {
  display: inline-block;
  animation: atlas-spin 0.8s linear infinite;
}
@keyframes atlas-spin { to { transform: rotate(360deg); } }

/* The only scroll region: fills the main column below the fixed topbar and
   scrolls internally, so the sidebar + topbar stay put. min-height:0 lets a
   flex child shrink below content size so overflow actually engages. */
.atlas-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  padding: 1.25rem 1.5rem;
}

/* Grid flex-fill — see ADR 2026-06-08-back-office-grid-layout. A single-grid
   page opts its content area into a no-scroll flex column; the grid (a
   .atlas-grid-scroll wrapper) takes the slack, so its header pins to the top
   and the pagination after it pins to the bottom while only the body scrolls.
   Height-agnostic: the grid fills whatever box it's in (flex:1 here, or a
   fixed-height container on multi-grid pages). */
.atlas-content--fill {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.atlas-grid-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  /* A line marking the bottom edge of the scroll window (mirrors the sticky
     header's bottom divider). */
  border-bottom: 1px solid var(--atlas-border);
}
/* Small gap so the pager's rounded corners clear the scroll-window line. */
.atlas-grid-pager {
  margin-top: 2px;
}
.atlas-grid-scroll table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--atlas-surface);
  box-shadow: inset 0 -1px 0 var(--atlas-border);
}
