/* ---------------------------------------------------------------------------
   Application shell: title bar, navigation rail, session strip, page header,
   content region, and the auth screen. Screens themselves live in screens.css.
   --------------------------------------------------------------------------- */

/* ---- Title bar ---------------------------------------------------------
   Frameless window chrome. The drag region is explicit and every interactive
   control opts back out, otherwise buttons swallow clicks into a window drag. */

.titlebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--title-h);
  z-index: var(--z-titlebar);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-left: var(--space-3);
  background: var(--bg-void);
  border-bottom: 1px solid var(--line-soft);
  -webkit-app-region: drag;
}

.titlebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.titlebar__logo {
  width: 16px;
  height: 16px;
  flex: none;
}

.titlebar__title {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  color: var(--text-2);
  white-space: nowrap;
}

.titlebar__status {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-left: var(--space-5);
  min-width: 0;
  overflow: hidden;
}

.titlebar__meta {
  font-size: var(--text-2xs);
  color: var(--text-3);
  white-space: nowrap;
}

.titlebar__spacer {
  flex: 1;
  min-width: var(--space-4);
}

.titlebar__controls {
  display: flex;
  align-self: stretch;
  -webkit-app-region: no-drag;
}

.titlebar__btn {
  width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.titlebar__btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.titlebar__btn--close:hover {
  background: #d9364b;
  color: #ffffff;
}

.titlebar__btn svg {
  width: 11px;
  height: 11px;
}

/* Maximize and restore share one button; only one glyph shows at a time. */
.titlebar__btn .icon-restore,
.titlebar.is-maximized .titlebar__btn .icon-maximize {
  display: none;
}

.titlebar.is-maximized .titlebar__btn .icon-restore {
  display: block;
}

/* Anything interactive that sits inside the drag region. */
.titlebar__notify {
  -webkit-app-region: no-drag;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-h-sm);
  height: var(--control-h-sm);
  border-radius: var(--radius-sm);
  color: var(--text-2);
}

.titlebar__notify:hover {
  background: var(--surface-2);
  color: var(--text);
}

.titlebar__notify svg {
  width: 14px;
  height: 14px;
}

.titlebar__notify-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bad);
  border: 1px solid var(--bg-void);
}

/* ---- App frame --------------------------------------------------------- */

.app {
  position: fixed;
  inset: var(--title-h) 0 0 0;
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  background: var(--bg-base);
}

/* ---- Navigation rail --------------------------------------------------- */

.nav {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  background: var(--bg-void);
  border-right: 1px solid var(--line-soft);
}

.nav__scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.nav__section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__section-label {
  padding: 0 var(--space-3) var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-3);
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: left;
  transition: background-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.nav__item:hover:not(.is-active) {
  background: var(--surface-2);
  color: var(--text);
}

.nav__item.is-active {
  background: var(--primary-wash);
  border-color: var(--primary-wash-strong);
  color: var(--text);
}

/* The illuminated edge that marks the current view. */
.nav__item.is-active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 7px;
  bottom: 7px;
  width: 2px;
  border-radius: var(--radius-pill);
  background: var(--primary);
}

.nav__icon {
  width: 16px;
  height: 16px;
  flex: none;
  color: currentColor;
}

.nav__item.is-active .nav__icon {
  color: var(--primary-hi);
}

.nav__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Unread / attention marker. Paired with an aria-label so it is not a
   colour-only signal. */
.nav__flag {
  flex: none;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--bad);
  color: #ffffff;
  font-size: 9px;
  font-weight: var(--weight-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.nav__flag--muted {
  background: var(--surface-3);
  color: var(--text-2);
}

.nav__flag.is-empty {
  display: none;
}

.nav__foot {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--line-soft);
}

.nav__user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.nav__avatar {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--primary-wash-strong);
  color: var(--primary-hi);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}

.nav__user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.nav__user-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav__user-role {
  font-size: var(--text-2xs);
  color: var(--text-3);
}

.nav__version {
  font-size: var(--text-2xs);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ---- Workspace --------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  padding: var(--space-5) var(--page-pad) var(--space-4);
  min-width: 0;
}

.page-head__text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.page-head__desc {
  font-size: var(--text-sm);
  color: var(--text-3);
  max-width: 92ch;
}

.page-head__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---- Session strip -----------------------------------------------------
   Horizontal, scrollable, capped at four sessions plus the add card. */

.session-strip {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  padding: 0 var(--page-pad) var(--space-4);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  min-width: 0;
}

.session-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: var(--space-3);
  row-gap: var(--space-2);
  align-items: center;
  flex: 0 0 244px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease),
              background-color var(--duration-fast) var(--ease);
}

.session-card:hover {
  border-color: var(--line-loud);
}

.session-card.is-focused {
  border-color: var(--primary);
  background: var(--primary-wash);
}

/* Focused marker that does not rely on the border colour alone. */
.session-card.is-focused::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: -1px;
  height: 2px;
  border-radius: var(--radius-pill);
  background: var(--primary);
}

/* Explicit placement: auto-placement puts the row-spanning close button in the
   flexible middle column and pushes the account name into the auto one. */
.session-card__ordinal {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.session-card.is-focused .session-card__ordinal {
  background: var(--primary);
  color: #ffffff;
}

.session-card__main {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.session-card__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-2xs);
  color: var(--text-3);
  min-width: 0;
}

.session-card__meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-card__close {
  grid-column: 3;
  grid-row: 1;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  color: var(--text-3);
}

.session-card__close:hover {
  background: var(--bad-wash);
  color: var(--bad);
}

.session-card__close svg {
  width: 11px;
  height: 11px;
}

.session-card__vitals {
  grid-column: 2 / 4;
  grid-row: 2;
  display: flex;
  gap: var(--space-2);
}

.session-card__vitals .meter {
  flex: 1;
  gap: 0;
}

.session-card__scope {
  font-size: 9px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-3);
}

.session-add {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  background: transparent;
  border: 1px dashed var(--line-loud);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: background-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.session-add:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--primary);
}

.session-add svg {
  width: 14px;
  height: 14px;
}

.session-strip__empty {
  display: flex;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--text-3);
  padding: 0 var(--space-2);
}

/* ---- Content region ---------------------------------------------------- */

.content {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Every screen fills the content box and scrolls internally, so the document
   itself never scrolls and the map can measure a stable container. */
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 0 var(--page-pad) var(--page-pad);
}

/* Screens that own their full height (the map) must not scroll. */
.screen--fixed {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- Auth -------------------------------------------------------------- */

.auth {
  position: fixed;
  inset: var(--title-h) 0 0 0;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--bg-base);
  overflow-y: auto;
}

.auth__card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.auth__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.auth__logo {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  letter-spacing: var(--tracking-wide);
  color: var(--text);
}

.auth__logo-accent {
  color: var(--primary);
}

.auth__tagline {
  font-size: var(--text-xs);
  color: var(--text-3);
}

.auth__tabs {
  display: flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.auth__tab {
  flex: 1;
  height: 28px;
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: background-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.auth__tab:hover:not(.is-active) {
  color: var(--text);
}

.auth__tab.is-active {
  background: var(--primary);
  color: #ffffff;
}

.auth__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.auth__message {
  font-size: var(--text-xs);
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
  min-height: 17px;
}

.auth__message[data-tone="error"] { color: var(--bad); }
.auth__message[data-tone="success"] { color: var(--ok); }
