/* ==========================================================================
   layout.css — the application shell.
   Navy top product nav (#topbar) + Account-settings sidebar + content column,
   mirroring the RightSpend "Settings → AI Agents" prototype.
   ========================================================================== */

/* ------------------------------- top nav -------------------------------- */
/* NOTE: this element keeps the id `topbar` — router.js toggles `.hidden` on it
   to hide the whole chrome on the login screen. */

.topnav {
  position: sticky;
  top: 0;
  z-index: var(--rs-z-topnav);
  display: flex;
  align-items: center;
  gap: var(--rs-5);
  height: var(--rs-topnav-h);
  padding: 0 var(--rs-6);
  background: var(--rs-navy);
  color: var(--rs-on-navy);
}

/* The brand lockup: white RIGHT + cyan SPEND inside a 2px white outline. */
.logo {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  border: 2px solid #fff;
  border-radius: var(--rs-r-sm);
  padding: 4px 8px;
  font-family: var(--rs-font-brand);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .5px;
  line-height: 1;
}
.logo b { color: #fff; font-weight: 700; }
.logo span { color: var(--rs-cyan); font-weight: 700; }

.topnav-links { display: flex; align-items: center; gap: var(--rs-1); }
.topnav-link {
  padding: 8px 14px;
  border-radius: var(--rs-r-md);
  font-size: var(--rs-fs-base);
  font-weight: 500;
  color: var(--rs-on-navy-2);
  text-decoration: none;
  transition: background var(--rs-dur-2) var(--rs-ease), color var(--rs-dur-2) var(--rs-ease);
}
.topnav-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.topnav-link.is-active { color: #fff; font-weight: 600; }

/* Hamburger — only shown once the sidebar becomes a drawer (≤1023px). */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--rs-r-md);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
}
.nav-toggle:hover { background: rgba(255, 255, 255, .16); }

/* Connection status chip.
   main.js:84 overwrites className with exactly "conn" / "conn ok" /
   "conn down", so ALL styling must hang off those three combinations —
   never add a persistent design class to #conn-status in the markup. */
.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--rs-r-pill);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .16);
  font-size: var(--rs-fs-xs);
  font-weight: 600;
  color: var(--rs-on-navy-2);
  white-space: nowrap;
}
.conn::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rs-p400);
  animation: rs-pulse 1.6s var(--rs-ease) infinite;
}
.conn.ok { color: #8FE7B4; }
.conn.ok::before { background: var(--rs-good); animation: none; }
.conn.down {
  color: #FFB4B4;
  background: rgba(220, 38, 38, .16);
  border-color: rgba(220, 38, 38, .32);
}
.conn.down::before { background: var(--rs-bad); }

@keyframes rs-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .35; transform: scale(.7); }
}

/* -------------------------------- shell --------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--rs-sidebar-w) minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - var(--rs-topnav-h));
}

.sidebar {
  position: sticky;
  top: var(--rs-topnav-h);
  align-self: start;
  height: calc(100vh - var(--rs-topnav-h));
  overflow-y: auto;
  padding: var(--rs-6) var(--rs-3);
  background: var(--rs-surface);
  border-right: 1px solid var(--rs-line);
}

.side-group { margin-bottom: var(--rs-6); }
.side-label {
  margin: 0 0 6px;
  padding: 0 10px;
  font-size: var(--rs-fs-2xs);
  font-weight: 700;
  letter-spacing: var(--rs-track-caps);
  text-transform: uppercase;
  color: var(--rs-p500);
}
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: none;
  border-radius: var(--rs-r-md);
  background: transparent;
  font-family: var(--rs-font-sans);
  font-size: var(--rs-fs-base);
  font-weight: 500;
  color: var(--rs-ink-2);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--rs-dur-2) var(--rs-ease), color var(--rs-dur-2) var(--rs-ease);
}
.side-item:hover { background: var(--rs-p100); color: var(--rs-navy); }
.side-item.is-active { background: #E8F2FB; color: var(--rs-navy); font-weight: 600; }
.side-item .icon { width: 17px; height: 17px; color: var(--rs-p500); }
.side-item.is-active .icon { color: var(--rs-cyan-deep); }

/* Live ingestion widget in the sidebar's second group. */
.side-widget {
  padding: 10px 12px;
  border: 1px solid var(--rs-line);
  border-radius: var(--rs-r-lg);
  background: var(--rs-p50);
  font-size: var(--rs-fs-sm);
  color: var(--rs-ink-3);
}
.side-widget .swi { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-widget .swi + .swi { margin-top: 6px; }
.side-widget b { font-family: var(--rs-font-brand); color: var(--rs-navy); }
.side-widget .swi.is-bad b { color: var(--rs-bad); }

.sidebar-scrim { display: none; }

/* ------------------------------- content -------------------------------- */

.content {
  min-width: 0;
  padding: var(--rs-6) var(--rs-7) var(--rs-10);
}
.content-inner { max-width: var(--rs-content-max); margin: 0 auto; }

/* The brand's wrapper min-width is honoured only where it cannot introduce a
   horizontal scrollbar — enforcing it unconditionally would break mobile.
   The threshold must clear the wrapper (1080) PLUS the sidebar (220) and the
   content's side padding (2 x 32) plus the scrollbar, i.e. ~1380; 1400 keeps a
   margin. A lower breakpoint silently scrolls every screen sideways. */
@media (min-width: 1400px) {
  .content-inner { min-width: var(--rs-wrapper-min); }
}

/* ---------------------------- page header band -------------------------- */
/* Each screen owns its own .page-header, so switching screens switches the
   breadcrumb/title/actions for free — no JS bookkeeping. */

.page-header {
  padding-bottom: var(--rs-5);
  margin-bottom: var(--rs-6);
  border-bottom: 1px solid var(--rs-line);
}
.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--rs-fs-sm);
  margin-bottom: 8px;
}
.crumbs a { color: var(--rs-ink-3); text-decoration: none; }
.crumbs a:hover { color: var(--rs-navy); text-decoration: underline; }
.crumb-sep { color: var(--rs-p400); }
.crumb-current { color: var(--rs-ink-2); font-weight: 500; }

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--rs-5);
  flex-wrap: wrap;
}
.page-header-main { min-width: 0; }
.page-title-row { display: flex; align-items: center; gap: var(--rs-3); flex-wrap: wrap; }
.page-title { font-size: var(--rs-fs-h1); }
.page-actions { display: flex; align-items: center; gap: var(--rs-2); flex-wrap: wrap; }

/* ============================== responsive ============================== */

/* Tablet + phone: the sidebar becomes an off-canvas drawer. */
@media (max-width: 1023px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--rs-topnav-h);
    bottom: 0;
    height: auto;
    width: 260px;
    z-index: var(--rs-z-drawer);
    transform: translateX(-100%);
    transition: transform var(--rs-dur-3) var(--rs-ease);
    box-shadow: var(--rs-sh-raised);
  }
  body.nav-open .sidebar { transform: none; }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: var(--rs-topnav-h) 0 0;
    z-index: calc(var(--rs-z-drawer) - 1);
    background: rgba(13, 42, 78, .38);
  }
  .sidebar-scrim[hidden] { display: none; }

  .content { padding: var(--rs-5) var(--rs-5) var(--rs-9); }
}

@media (max-width: 767px) {
  .topnav { gap: var(--rs-2); padding: 0 var(--rs-3); height: 64px; }
  /* The only product link duplicates the sidebar's "AI Agents" item, which is
     reachable from the drawer — so nothing is lost by dropping it here. */
  .topnav-links { display: none; }
  /* Collapse the right-hand cluster so it fits a 390px viewport: the status
     chip becomes its colour-coded dot, Log out becomes its icon. */
  .conn { font-size: 0; gap: 0; padding: 7px; }
  .conn::before { width: 8px; height: 8px; }
  #btn-logout { width: 38px; padding: 0; justify-content: center; }
  #btn-logout .btn-label { display: none; }

  .app-shell { min-height: calc(100vh - 64px); }
  .sidebar, .sidebar-scrim { top: 64px; }

  .content { padding: var(--rs-4) var(--rs-4) var(--rs-8); }
  .page-title { font-size: 24px; }
  .page-header-row { flex-direction: column; align-items: stretch; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .lead { font-size: var(--rs-fs-base); }
}

/* The login screen has no chrome: hide the sidebar and let the screen own the
   full viewport. router.js stamps body[data-screen]. */
body[data-screen="screen-login"] .sidebar,
body[data-screen="screen-login"] .sidebar-scrim { display: none; }
body[data-screen="screen-login"] .app-shell { grid-template-columns: minmax(0, 1fr); }
body[data-screen="screen-login"] .content { padding: 0; }
body[data-screen="screen-login"] .content-inner { max-width: none; min-width: 0; }
