/* ==========================================================================
   layout.css — the application shell.
   Teal top nav, a sidebar for the signed-in role, and the content column.
   ========================================================================== */

/* ------------------------------- 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(--mah-z-topnav);
  display: flex;
  align-items: center;
  gap: var(--mah-5);
  height: var(--mah-topnav-h);
  padding: 0 var(--mah-6);
  background: var(--mah-brand-deep);
  color: var(--mah-on-brand);
}

/* The wordmark: "myagentic" in white, "hosts" in amber. */
.logo {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  font-family: var(--mah-font-brand);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.01em;
  text-decoration: none;
  line-height: 1;
}
.logo b { color: #fff; font-weight: 700; }
.logo span { color: var(--mah-accent); font-weight: 700; }

.topnav-links { display: flex; align-items: center; gap: var(--mah-1); }
.topnav-link {
  padding: 8px 14px;
  border-radius: var(--mah-r-md);
  font-size: var(--mah-fs-base);
  font-weight: 500;
  color: var(--mah-on-brand-2);
  text-decoration: none;
  transition: background var(--mah-dur-2) var(--mah-ease), color var(--mah-dur-2) var(--mah-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(--mah-r-md);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
}
.nav-toggle:hover { background: rgba(255, 255, 255, .16); }

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

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

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

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

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

/* Live ingestion widget in the sidebar's second group. */
.side-widget {
  padding: 10px 12px;
  border: 1px solid var(--mah-line);
  border-radius: var(--mah-r-lg);
  background: var(--mah-n50);
  font-size: var(--mah-fs-sm);
  color: var(--mah-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(--mah-font-brand); color: var(--mah-ink); }
.side-widget .swi.is-bad b { color: var(--mah-bad); }

.sidebar-scrim { display: none; }

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

.content {
  min-width: 0;
  padding: var(--mah-6) var(--mah-7) var(--mah-10);
}
.content-inner { max-width: var(--mah-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(--mah-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(--mah-5);
  margin-bottom: var(--mah-6);
  border-bottom: 1px solid var(--mah-line);
}
.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--mah-fs-sm);
  margin-bottom: 8px;
}
.crumbs a { color: var(--mah-ink-3); text-decoration: none; }
.crumbs a:hover { color: var(--mah-ink); text-decoration: underline; }
.crumb-sep { color: var(--mah-n400); }
.crumb-current { color: var(--mah-ink-2); font-weight: 500; }

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--mah-5);
  flex-wrap: wrap;
}
.page-header-main { min-width: 0; }
.page-title-row { display: flex; align-items: center; gap: var(--mah-3); flex-wrap: wrap; }
.page-title { font-size: var(--mah-fs-h1); }
.page-actions { display: flex; align-items: center; gap: var(--mah-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(--mah-topnav-h);
    bottom: 0;
    height: auto;
    width: 260px;
    z-index: var(--mah-z-drawer);
    transform: translateX(-100%);
    transition: transform var(--mah-dur-3) var(--mah-ease);
    box-shadow: var(--mah-sh-raised);
  }
  body.nav-open .sidebar { transform: none; }

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

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

@media (max-width: 767px) {
  .topnav { gap: var(--mah-2); padding: 0 var(--mah-3); height: 64px; }
  .topnav-links { display: none; }
  /* Log out collapses to its icon so the bar fits a 390px viewport. */
  #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(--mah-4) var(--mah-4) var(--mah-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(--mah-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; }
