/* ============================================================================
   NexusCore Operations — Application Shell
   ----------------------------------------------------------------------------
   A fixed sidebar for navigation, a top bar for scope and identity.

   The important idea: PRODUCT IS A SCOPE, NOT A NAV ITEM. Navigation lists
   functions (Overview, Support, Customers, Products, Reports) and stays the
   same length forever; the product selector in the top bar narrows every
   surface at once. The previous build put "Managed Websites" — a product — in
   the nav as a peer of "Customers" — a dimension, which meant nav would grow
   by one entry for every product ever added.

   Depends on tokens.css and system.css.
   ========================================================================= */

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--shell-sidebar) minmax(0, 1fr);
  grid-template-rows: var(--shell-topbar) minmax(0, 1fr);
  grid-template-areas:
    "brand topbar"
    "nav   main";
}

.shell--plain {
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "brand topbar"
    "main  main";
}

/* ---------------------------------------------------------------------------
   Brand block — sits above the sidebar, aligned with the top bar
   ------------------------------------------------------------------------ */

.shell__brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--surface-sunken);
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.shell--plain .shell__brand {
  background: transparent;
  border-right: 0;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  min-width: 0;
}

.brand:hover { color: var(--text); text-decoration: none; }
.brand__mark { color: var(--accent); width: 28px; height: 28px; flex: none; }
.brand__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand__identity { display: grid; gap: 2px; }
.brand__caption { font-size: 10px; font-family: var(--font-mono); color: var(--text-tertiary); letter-spacing: 0.12em; text-transform: uppercase; }

/* ---------------------------------------------------------------------------
   Sidebar
   ------------------------------------------------------------------------ */

.shell__nav {
  grid-area: nav;
  background: var(--surface-sunken);
  border-right: 1px solid var(--border-strong);
  padding: var(--space-5) var(--space-3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.workspace-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 var(--space-1) var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: var(--text-meta);
  background: var(--surface);
}

.navgroup ul { display: grid; gap: var(--space-1); }

.navgroup__label {
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-tertiary);
}

.navlink {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--text-body);
  line-height: 1.3;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
  position: relative;
}

.navlink:hover {
  background: var(--surface-raised);
  color: var(--text);
  text-decoration: none;
}

.navlink[aria-current="page"] {
  background: var(--accent-quiet);
  color: var(--accent);
  font-weight: 500;
}

/* The active item carries the same 2px rail the status system uses, so the
   device reads consistently across navigation and data. */
.navlink[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 2px;
  background: var(--accent);
}

.navlink__icon { width: 1rem; text-align: center; flex: none; font-size: 0.85rem; }
.navlink__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* A live count sitting on a nav item — unassigned tickets, failing checks. */
.navlink__count {
  margin-left: auto;
  padding: 0 var(--space-2);
  min-width: 1.35rem;
  text-align: center;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  color: var(--text-secondary);
}

.navlink__count[data-status]:not([data-status="idle"]) {
  background: var(--status-quiet);
  border-color: color-mix(in srgb, var(--status) 35%, transparent);
  color: var(--status);
}

.navgroup--foot { margin-top: auto; padding-top: var(--space-5); border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------------------
   Top bar
   ------------------------------------------------------------------------ */

.shell__topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

/* --- Product scope ---------------------------------------------------------
   The control that makes this a multi-product console. Selecting a product
   narrows every surface; "All products" is the cross-product view. */

.scope {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.25rem var(--space-2) 0.25rem var(--space-3);
  min-height: 36px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-meta);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease);
}

.scope:hover { border-color: var(--text-tertiary); }
.scope__label { font-family: var(--font-mono); font-size: var(--text-label);
  text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-tertiary); }
.scope__value { font-weight: 500; white-space: nowrap; }
.scope__caret { color: var(--text-tertiary); font-size: 0.7rem; }

.scope-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 150;
  min-width: 15rem;
  padding: var(--space-1);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  display: none;
}

.scope-menu.is-open { display: block; }

.scope-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.scope-menu__item:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.scope-menu__item[aria-current="true"] { color: var(--accent); }
.scope-menu__key { margin-left: auto; }
.scope-menu__sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

.has-menu { position: relative; }

/* --- User menu ------------------------------------------------------------ */

.usermenu {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.25rem var(--space-2);
  min-height: 30px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--text-meta);
  cursor: pointer;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}

.usermenu:hover { background: var(--surface); color: var(--text); }
.usermenu__avatar {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  background: var(--accent-quiet);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: 600;
  text-transform: uppercase;
}

.usermenu__name { white-space: nowrap; }

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 150;
  min-width: 14rem;
  padding: var(--space-1);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  display: none;
}

/* `.show` is the convention the ticket detail script already uses; accept both
   rather than rewriting working JS. */
.menu.is-open,
.menu.show { display: block; }

.menu__head {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
}

.menu__head strong { display: block; font-size: var(--text-body); }
.menu__head span { font-size: var(--text-label); font-family: var(--font-mono); color: var(--text-tertiary); }

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.menu__item:hover { background: var(--surface); color: var(--text); text-decoration: none; }

/* Menu items are sometimes <button> (an action) rather than <a> (a destination). */
button.menu__item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: var(--text-body);
}
.menu__item i { width: 1rem; text-align: center; font-size: 0.8rem; flex: none; }
.menu__sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* --- Mobile nav toggle ---------------------------------------------------- */

.shell__navtoggle { display: none; }

/* ---------------------------------------------------------------------------
   Main region
   ------------------------------------------------------------------------ */

.shell__main {
  grid-area: main;
  min-width: 0;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-6) var(--page-gutter) var(--space-7);
}

@media (min-width: 1001px) {
  .shell__brand, .shell__topbar { position: sticky; top: 0; z-index: 150; }
  .shell__nav { position: sticky; top: var(--shell-topbar); height: calc(100dvh - var(--shell-topbar)); }
}

/* Forms and single-record reading get a narrower measure. These are the only
   two widths in the product. */
.page--narrow { max-width: var(--page-max-narrow); }

/* ---------------------------------------------------------------------------
   Footers

   An authenticated operations console does not need a marketing footer with a
   "Request Proposal" call to action; on mobile that footer was roughly a third
   of the page. Signed-in pages get a single meta line instead.
   ------------------------------------------------------------------------ */

.ops-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--page-gutter);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  color: var(--text-tertiary);
}

.ops-foot a { color: var(--text-tertiary); }
.ops-foot a:hover { color: var(--accent); }
.ops-foot__sep { color: var(--border-strong); }

.site-foot {
  border-top: 1px solid var(--border);
  padding: var(--space-6) var(--page-gutter);
}

.site-foot__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}

.site-foot h2 {
  font-family: var(--font-mono);
  font-size: var(--text-label);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

.site-foot li { margin-bottom: var(--space-2); }
.site-foot a { color: var(--text-secondary); font-size: var(--text-meta); }
.site-foot a:hover { color: var(--accent); }

.site-foot__meta {
  max-width: var(--page-max);
  margin: var(--space-5) auto 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  justify-content: space-between;
  font-size: var(--text-label);
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

.site-foot__meta .row { gap: var(--space-4); }

/* ---------------------------------------------------------------------------
   Responsive: sidebar becomes an off-canvas drawer
   ------------------------------------------------------------------------ */

@media (max-width: 1000px) {
  /* Brand and top bar share the first row rather than being assigned the same
     grid area, which stacked them and made the nav toggle unreachable. */
  .shell {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: var(--shell-topbar) minmax(0, 1fr);
    grid-template-areas:
      "brand topbar"
      "main  main";
  }

  .shell__brand {
    background: transparent;
    border-right: 0;
    padding-right: 0;
    gap: var(--space-2);
  }

  .shell__topbar { gap: var(--space-2); padding: 0 var(--space-4); }

  .shell__navtoggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 30px;
    flex: none;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
  }

  .shell__nav {
    position: fixed;
    inset: var(--shell-topbar) auto 0 0;
    z-index: 160;
    width: min(var(--shell-sidebar), 82vw);
    transform: translateX(-101%);
    transition: transform var(--duration) var(--ease);
    box-shadow: var(--shadow-panel);
  }

  .shell.nav-open .shell__nav { transform: none; }

  .shell.nav-open .shell__scrim {
    position: fixed;
    inset: var(--shell-topbar) 0 0 0;
    z-index: 155;
    background: rgba(4, 7, 9, 0.6);
  }

  .page { padding: var(--space-4) var(--space-4) var(--space-6); }
  .scope__label { display: none; }
}

@media (max-width: 620px) {
  .usermenu__name { display: none; }
  .brand__name { font-size: var(--text-meta); }
}

@media (max-width: 380px) {
  .brand__caption { display: none; }
  .brand__mark { width: 20px; height: 20px; }
  .shell__topbar { gap: var(--space-1); padding-inline: var(--space-2); }
  .shell--plain .shell__brand { padding-left: var(--space-2); }
  .scope { padding-inline: var(--space-2); }
}
