/* ==========================================================================
   GHE OS - app shell: sidebar / topbar / content / right context panel
   ========================================================================== */

#app { height: 100%; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: 100%;
  height: 100%;
  transition: grid-template-columns var(--dur) var(--ease);
}
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  position: relative;
  z-index: var(--z-sticky);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s1);
  height: var(--topbar-h);
  padding: 0 var(--s2);
  flex: none;
  border-bottom: 1px solid var(--border-faint);
  overflow: hidden;
}
.sidebar__logo { width: 30px; height: 30px; flex: none; color: var(--primary); }
.sidebar__wordmark { min-width: 0; }
.sidebar__name {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: var(--track-tight);
  line-height: 1.1;
}
.sidebar__tag {
  font-size: var(--fs-2xs);
  color: var(--text-faint);
  letter-spacing: .02em;
  white-space: nowrap;
}

.sidebar__scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--s2) var(--s1) var(--s1); }

.sidebar__group + .sidebar__group { margin-top: var(--s2); }
.sidebar__grouplabel {
  padding: var(--s1) var(--s2) var(--s05);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

.navitem {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s1);
  width: 100%;
  padding: 9px var(--s1) 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.navitem__icon { width: 18px; height: 18px; flex: none; opacity: .85; }
.navitem__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.navitem__chev { width: 14px; height: 14px; flex: none; opacity: .5; transition: transform var(--dur) var(--ease); }
.navitem[aria-expanded="true"] .navitem__chev { transform: rotate(90deg); }

.navitem:hover { background: rgba(255,255,255,.045); color: var(--text); }
.navitem.is-active { background: var(--primary-soft); color: var(--primary); }
.navitem.is-active .navitem__icon { opacity: 1; }
.navitem.is-active::before {
  content: "";
  position: absolute;
  left: -8px; top: 50%;
  width: 3px; height: 18px;
  margin-top: -9px;
  border-radius: 0 var(--r-full) var(--r-full) 0;
  background: var(--primary);
}
.navitem.is-open { color: var(--text); }

/* the single reserved, non-navigable future slot */
.navitem.is-reserved { color: var(--text-faint); cursor: default; opacity: .55; }
.navitem.is-reserved:hover { background: none; color: var(--text-faint); }

.navsub { overflow: hidden; }
.navsub .navitem {
  padding-left: 38px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-normal);
  color: var(--text-muted);
}
.navsub .navitem:hover { color: var(--text-2); }
.navsub .navitem.is-active {
  background: transparent;
  color: var(--primary);
  font-weight: var(--fw-medium);
}
.navsub .navitem.is-active::before { left: 20px; height: 14px; margin-top: -7px; border-radius: var(--r-full); width: 2px; }

.sidebar__foot { flex: none; padding: var(--s1); border-top: 1px solid var(--border-faint); }

.workspacecard {
  display: flex;
  align-items: center;
  gap: var(--s1);
  width: 100%;
  padding: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  overflow: hidden;
}
.workspacecard:hover { border-color: var(--border-strong); background: var(--surface-3); }
.workspacecard__mark {
  width: 28px; height: 28px; flex: none;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
}
.workspacecard__body { min-width: 0; text-align: left; }

/* collapsed sidebar */
.shell.is-collapsed .sidebar__wordmark,
.shell.is-collapsed .sidebar__grouplabel,
.shell.is-collapsed .navitem__label,
.shell.is-collapsed .navitem__chev,
.shell.is-collapsed .navsub,
.shell.is-collapsed .workspacecard__body { display: none; }
.shell.is-collapsed .sidebar__brand { justify-content: center; padding: 0; }
.shell.is-collapsed .navitem { justify-content: center; padding-left: var(--s1); padding-right: var(--s1); }
.shell.is-collapsed .workspacecard { justify-content: center; }

/* ==========================================================================
   Main column
   ========================================================================== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  height: var(--topbar-h);
  flex: none;
  padding: 0 var(--s3);
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg-2);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  position: relative;
  z-index: var(--z-topbar);
}

.topbar__left { display: flex; align-items: center; gap: var(--s1); flex: none; }
.topbar__right { display: flex; align-items: center; gap: var(--s05); flex: none; margin-left: auto; }

.iconbtn {
  position: relative;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.iconbtn:hover { background: rgba(255,255,255,.06); color: var(--text); }
.iconbtn.is-on { background: var(--primary-soft); color: var(--primary); }
.iconbtn__dot {
  position: absolute; top: 6px; right: 6px;
  min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: var(--r-full);
  background: var(--critical);
  color: #fff;
  font-size: 9px; font-weight: var(--fw-bold);
  display: grid; place-items: center;
  border: 2px solid var(--surface-2);
}

/* universal search in the topbar */
.searchbar {
  flex: 1 1 auto;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
}
.searchbar__input {
  width: 100%;
  height: 36px;
  padding: 0 var(--s6) 0 36px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.searchbar__input::placeholder { color: var(--text-faint); }
.searchbar__input:focus { border-color: var(--primary-ring); background: var(--surface-3); outline: none; }
.searchbar__icon { position: absolute; left: 11px; top: 9px; width: 17px; height: 17px; color: var(--text-faint); pointer-events: none; }
.searchbar__kbd { position: absolute; right: 8px; top: 8px; pointer-events: none; }

.breadcrumb { display: flex; align-items: center; gap: var(--s05); font-size: var(--fs-sm); color: var(--text-muted); }
.breadcrumb__sep { opacity: .4; }
.breadcrumb a:hover { color: var(--text-2); }
.breadcrumb__current { color: var(--text-2); font-weight: var(--fw-medium); }

/* ==========================================================================
   Content + right context panel
   ========================================================================== */
.body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  transition: grid-template-columns var(--dur) var(--ease);
}
.body.has-context { grid-template-columns: minmax(0, 1fr) var(--context-w); }

.content {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.content__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s3);
}
.content__inner--flush { max-width: none; padding: 0; height: 100%; }

/* page header block used by every module */
.pagehead {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  margin-bottom: var(--s3);
}
.pagehead__text { min-width: 0; flex: 1 1 auto; }
.pagehead__title { font-size: var(--fs-3xl); font-weight: var(--fw-bold); letter-spacing: var(--track-tight); line-height: 1.15; }
.pagehead__sub { margin-top: var(--s05); color: var(--text-muted); font-size: var(--fs-md); }
.pagehead__actions { display: flex; align-items: center; gap: var(--s1); flex: none; padding-top: var(--s05); }

/* horizontal module tabs */
.tabs {
  display: flex;
  align-items: center;
  gap: var(--s3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s3);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: 0 0 10px;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text-2); }
.tab.is-active { color: var(--primary); }
.tab.is-active::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; border-radius: var(--r-full);
  background: var(--primary);
}

/* right context panel */
.context {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  padding: var(--s2);
}
.context__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.context__section + .context__section { margin-top: var(--s3); }
.context__title {
  font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  letter-spacing: var(--track-wide); text-transform: uppercase;
  color: var(--text-faint); margin-bottom: var(--s1);
}

/* ==========================================================================
   Grid helpers - 8px rhythm
   ========================================================================== */
.grid { display: grid; gap: var(--s2); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid--6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid--wide { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.grid--main-side { grid-template-columns: minmax(0, 1fr) 340px; }
.grid--side-main { grid-template-columns: 300px minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-full { grid-column: 1 / -1; }

/* ==========================================================================
   Responsive desktop - the shell degrades, never scrolls the body sideways
   ========================================================================== */
@media (max-width: 1600px) {
  .grid--6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1440px) {
  .body.has-context { grid-template-columns: minmax(0, 1fr) 300px; }
  .grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1280px) {
  .shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
  .shell .sidebar__wordmark,
  .shell .sidebar__grouplabel,
  .shell .navitem__label,
  .shell .navitem__chev,
  .shell .navsub,
  .shell .workspacecard__body { display: none; }
  .shell .sidebar__brand { justify-content: center; padding: 0; }
  .shell .navitem { justify-content: center; }
  .shell .workspacecard { justify-content: center; }
  .body.has-context { grid-template-columns: minmax(0, 1fr); }
  .body.has-context .context { display: none; }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--main-side, .grid--side-main { grid-template-columns: minmax(0, 1fr); }
  .content__inner { padding: var(--s2); }
}
@media (max-width: 1024px) {
  .grid--3, .grid--5, .grid--6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .searchbar { max-width: none; }
}
