/*
 * App shell: top bar, sidebar, content, side panel slot, status bar (global activity).
 * The document scrolls (not an inner container), so anchors, find-in-page and full-page
 * screenshots behave naturally; chrome elements are sticky/fixed.
 */

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

.shell[data-sidebar="collapsed"] { --sb-w: var(--sidebar-w-collapsed); }

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

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding: 0 var(--space-4) 0 0;
  background: color-mix(in srgb, var(--bg-chrome) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  flex: 0 0 auto;
  width: var(--sb-w);
  height: 100%;
  padding: 0 var(--space-4);
  color: var(--text);
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  transition: width var(--dur) var(--ease-standard);
}

.topbar__brand:hover { text-decoration: none; }
.topbar__brand:focus-visible { outline-offset: -4px; }

.topbar__brand .logo { flex: 0 0 auto; width: 26px; height: 26px; }

.topbar__brand-name { display: flex; align-items: baseline; gap: var(--space-1-5); min-width: 0; }

.topbar__brand-tag {
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  color: var(--text-3);
  letter-spacing: 0;
}

.topbar .topbar__menu-btn { display: none; }

.topbar__search {
  position: relative;
  flex: 0 1 380px;
  min-width: 160px;
}

.topbar__search .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  translate: 0 -50%;
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}

.topbar__search-input {
  width: 100%;
  height: 32px;
  padding: 0 64px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: var(--text-sm);
  transition: background-color var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.topbar__search-input::placeholder { color: var(--text-3); }
.topbar__search-input:hover { border-color: var(--border-strong); }

.topbar__search-input:focus-visible {
  outline: none;
  background: var(--bg-surface);
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

.topbar__search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  translate: 0 -50%;
  display: flex;
  gap: 3px;
  pointer-events: none;
}

.topbar__search-input:focus-visible ~ .topbar__search-kbd { opacity: 0; }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.topbar__divider {
  width: 1px;
  height: 20px;
  margin: 0 var(--space-2);
  background: var(--border);
}

.topbar__indicator { position: relative; }

.topbar__indicator .count-badge {
  position: absolute;
  top: 2px;
  right: 1px;
}

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

.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--topbar-h);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  padding: var(--space-3) var(--space-2-5);
  background: var(--bg-chrome);
  border-right: 1px solid var(--border);
  overflow-x: hidden;
  overflow-y: auto;
}

.nav { display: flex; flex-direction: column; gap: var(--space-5); }

.nav__group { display: flex; flex-direction: column; gap: 1px; }

.nav__heading {
  height: 24px;
  padding: 0 var(--space-2-5);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  line-height: 24px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  height: 32px;
  padding: 0 var(--space-2-5);
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-weight: var(--weight-medium);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}

.nav__item .icon { flex: 0 0 auto; width: 16px; height: 16px; color: var(--text-3); transition: color var(--dur-fast); }

.nav__item:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav__item:hover .icon { color: var(--text-2); }

.nav__item[aria-current="page"] {
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--border);
}

.nav__item[aria-current="page"] .icon { color: var(--accent-text); }

.nav__item[aria-disabled="true"] {
  color: var(--text-disabled);
  cursor: default;
}

.nav__item[aria-disabled="true"]:hover { background: transparent; color: var(--text-disabled); }
.nav__item[aria-disabled="true"] .icon { color: var(--text-disabled); }

button.nav__item {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: var(--weight-medium);
  text-align: left;
  cursor: pointer;
}

.nav__item:focus-visible { outline-offset: -2px; }

.nav__label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }

.nav__meta {
  flex: 0 0 auto;
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  color: var(--text-disabled);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.sidebar__footer {
  margin-top: auto;
  padding-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar__collapse .icon { transition: rotate var(--dur) var(--ease-standard); }

/* Collapsed rail */
.shell[data-sidebar="collapsed"] .nav__label,
.shell[data-sidebar="collapsed"] .nav__meta,
.shell[data-sidebar="collapsed"] .topbar__brand-name {
  display: none;
}

.shell[data-sidebar="collapsed"] .nav__heading {
  height: 1px;
  margin: var(--space-1) var(--space-2-5);
  padding: 0;
  font-size: 0;
  background: var(--border);
}

.shell[data-sidebar="collapsed"] .nav__item { justify-content: center; padding: 0; }
.shell[data-sidebar="collapsed"] .topbar__brand { padding: 0; justify-content: center; }
.shell[data-sidebar="collapsed"] .sidebar__collapse .icon { rotate: 180deg; }

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

.main {
  grid-area: main;
  min-width: 0;
  padding-bottom: calc(var(--statusbar-h) + var(--space-8));
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-8) var(--space-6);
}

.page-wide { max-width: none; }
.page-narrow { max-width: 880px; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-header__text { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }

.page-header__eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-3);
}

.page-header__title { font-size: var(--text-2xl); }

.page-header__subtitle {
  max-width: 72ch;
  color: var(--text-2);
  font-size: var(--text-md);
}

.page-header__actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.page-header .breadcrumb { margin-bottom: var(--space-1); }

.section { display: flex; flex-direction: column; gap: var(--space-3); }

.section + .section { margin-top: var(--space-8); }

.section__header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }

.section__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.section__subtitle { color: var(--text-3); font-size: var(--text-sm); }

/* ---- Right side panel slot (missing info, AI assistant: later phases) -- */

.side-panel {
  grid-area: panel;
  position: sticky;
  top: var(--topbar-h);
  width: var(--side-panel-w);
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  height: calc(100dvh - var(--topbar-h) - var(--statusbar-h));
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

/* ---- Status bar (global activity bar slot) ---------------------------- */

.statusbar {
  position: fixed;
  left: var(--sb-w);
  right: 0;
  bottom: 0;
  z-index: var(--z-statusbar);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--statusbar-h);
  padding: 0 var(--space-3);
  background: color-mix(in srgb, var(--bg-chrome) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-3);
  transition: left var(--dur) var(--ease-standard);
}

.statusbar__right { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); }

.statusbar__hint { display: inline-flex; align-items: center; gap: var(--space-1-5); }

.activity-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 22px;
  padding: 0 var(--space-2-5) 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast), background-color var(--dur-fast);
}

.activity-pill:hover { border-color: var(--border-strong); background: var(--bg-hover); }

.activity-pill__dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--text-disabled);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-disabled) 22%, transparent);
}

.activity-pill[data-state="running"] .activity-pill__dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  animation: pulse-dot 1.6s var(--ease-in-out) infinite;
}

@keyframes pulse-dot {
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 6%, transparent); }
}

/* ---- Minimal layout (login, logged-out errors) ------------------------ */

.minimal {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

.minimal::before {
  /* soft ambient light */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(60rem 36rem at 15% -10%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 70%),
    radial-gradient(48rem 30rem at 100% 110%, color-mix(in srgb, var(--info) 9%, transparent), transparent 70%),
    var(--bg-app);
}

.minimal::after {
  /* fine grid, fading out from the centre */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 42%, #000 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 42%, #000 20%, transparent 75%);
}

.minimal__main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
}

.minimal__footer {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-3);
}

/* ---- Responsive ------------------------------------------------------- */

@media (max-width: 1280px) {
  .side-panel {
    position: fixed;
    right: 0;
    z-index: var(--z-drawer);
    box-shadow: var(--shadow-xl);
  }
}

@media (max-width: 1100px) {
  .shell,
  .shell[data-sidebar="collapsed"] { --sb-w: var(--sidebar-w-collapsed); }

  .shell .nav__label,
  .shell .nav__meta,
  .shell .topbar__brand-name { display: none; }

  .shell .nav__heading {
    height: 1px;
    margin: var(--space-1) var(--space-2-5);
    padding: 0;
    font-size: 0;
    background: var(--border);
  }

  .shell .nav__item { justify-content: center; padding: 0; }
  .shell .topbar__brand { padding: 0; justify-content: center; }
  .sidebar__collapse { display: none; }

  .page { padding: var(--space-6) var(--space-6) var(--space-6); }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "main"; }

  .topbar { padding-left: var(--space-2); }
  .topbar .topbar__menu-btn { display: inline-flex; }
  .topbar__brand { width: auto; padding: 0; }
  .topbar__search { display: none; }
  .topbar__user-name { display: none; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    width: var(--sidebar-w);
    translate: -100% 0;
    box-shadow: var(--shadow-xl);
    transition: translate var(--dur-slow) var(--ease-out);
  }

  .shell[data-sidebar-open="true"] .sidebar { translate: 0 0; }

  .shell[data-sidebar-open="true"] .nav__label,
  .shell[data-sidebar-open="true"] .nav__meta { display: initial; }

  .shell[data-sidebar-open="true"] .nav__item { justify-content: flex-start; padding: 0 var(--space-2-5); }

  .statusbar { left: 0; }

  .page { padding: var(--space-5) var(--space-4); }
}

/* ---- Activity bar (expanded states, lib/activity.js) ------------------- */

.activity-pill { max-width: min(560px, 60vw); }
.activity-pill__text { max-width: 260px; }
.activity-pill__bar { display: inline-flex; width: 72px; }
.activity-pill__bar[hidden] { display: none; }
.activity-pill__meta { color: var(--text-3); font-weight: var(--weight-regular); white-space: nowrap; }
.activity-pill__meta:empty { display: none; }
.activity-pill__chevron { color: var(--text-3); transition: rotate var(--dur) var(--ease-standard); }
.activity-pill[aria-expanded="true"] .activity-pill__chevron { rotate: 180deg; }
.activity-pill[data-state="running"] { border-color: var(--accent-border); }
.activity-pill[data-state="attention"] .activity-pill__dot { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 25%, transparent); }
.activity-pill[data-state="failed"] .activity-pill__dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent); }

.activity-panel {
  position: fixed;
  left: calc(var(--sb-w) + var(--space-3));
  bottom: calc(var(--statusbar-h) + var(--space-2));
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  width: min(460px, calc(100vw - var(--sb-w) - 24px));
  max-height: min(60vh, 520px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-xl);
  color: var(--text);
  font-size: var(--text-sm);
  animation: menu-in var(--dur) var(--ease-out);
  transform-origin: bottom left;
}

.activity-panel[hidden] { display: none; }

.activity-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.activity-panel__title { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.activity-panel__title .count-badge { box-shadow: none; }
.activity-panel__list { flex: 1 1 auto; overflow-y: auto; padding: var(--space-1) var(--space-1) var(--space-2); }
.activity-panel__label { padding: var(--space-2) var(--space-3) var(--space-1); font-size: var(--text-2xs); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--text-3); }
.activity-panel__empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-1-5); padding: var(--space-6) var(--space-4); text-align: center; font-size: var(--text-xs); color: var(--text-3); }
.activity-panel__empty .icon { width: 20px; height: 20px; color: var(--text-disabled); }
.activity-panel__empty strong { color: var(--text); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.activity-panel__empty[hidden] { display: none; }
.activity-panel__footer { display: flex; justify-content: flex-start; padding: var(--space-1-5) var(--space-2); border-top: 1px solid var(--border-subtle); background: var(--bg-surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

[data-notify-toggle][aria-disabled="true"] { color: var(--text-3); cursor: default; }
[data-notify-toggle][data-state="granted"] .icon { color: var(--success-text); }

.nav__count {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  line-height: 18px;
  text-align: center;
}

.nav__count[data-count="0"] { display: none; }
.shell[data-sidebar="collapsed"] .nav__count { position: absolute; top: 3px; right: 6px; min-width: 14px; height: 14px; line-height: 14px; padding: 0 3px; font-size: 9px; }

[data-jobs-indicator].is-busy { color: var(--accent-text); }

@media (max-width: 1100px) {
  .shell .nav__count { position: absolute; top: 3px; right: 6px; min-width: 14px; height: 14px; line-height: 14px; padding: 0 3px; font-size: 9px; }
  .activity-pill__text { max-width: 160px; }
}

@media (max-width: 760px) {
  .activity-panel { left: var(--space-2); width: calc(100vw - 16px); }
  .activity-pill__bar { display: none; }
}
