/* Relay app shell — one left sidebar shared by every page. */

/* Cross-document view transitions: the pages are separate .html files, so a
   nav click normally tears the sidebar down and rebuilds it. Naming it lets
   the browser carry the SAME element across the navigation instead — the
   sidebar visually never moves. Progressive enhancement: browsers without
   support just navigate normally (the sessionStorage cache in shell.js still
   removes the flash there). */
@view-transition { navigation: auto; }

.sidebar { view-transition-name: relay-sidebar; }

/* Only cross-fade the main content; the sidebar is held still by its name. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 90ms;
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}

body {
  display: flex;
  min-height: 100vh;
  margin: 0;
}

/* --- scrollbars ---------------------------------------------------------
   Default chrome scrollbars are light-grey slabs that break the dark theme.
   Firefox gets the standard properties; WebKit/Blink the pseudo-elements. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-corner { background: transparent; }

/* --- sidebar ----------------------------------------------------------- */
.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.side-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.side-brand a {
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; font-weight: 800; letter-spacing: -.02em;
  color: var(--text); text-decoration: none;
}
.side-brand a:hover { color: var(--accent); }
.side-brand small {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .1em;
  color: var(--text-faint);
  margin-top: 5px;
}

.side-group { padding: 12px 10px; }
.side-group + .side-group { border-top: 1px solid var(--border-soft); }
.side-label {
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-faint);
  padding: 0 8px 7px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px; font-weight: 500;
  border: none; background: none; width: 100%;
  font-family: var(--font-sans); cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2);
  color: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-item .ico { width: 17px; text-align: center; flex-shrink: 0; }
.nav-item .lbl {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* same rule as the cards: truncate the version, never the app name */
.nav-item .ver {
  flex: 0 1 auto; min-width: 0; max-width: 42%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: 9px; color: var(--text-faint);
}
.nav-item .count {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  background: var(--accent); color: #1a1200;
  border-radius: 9px; padding: 0 6px; min-width: 17px; text-align: center;
}

/* The app list is the ONLY part allowed to shrink, and it must scroll when it
   does. Without overflow-y it just spills out of its box and draws on top of
   the group below — which is what happens on a short window (e.g. 1100x560:
   the box gets 119px while the content needs 399px). */
.side-apps {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
/* everything else keeps its natural height rather than being squeezed */
.side-brand,
.side-group:not(.side-apps),
.side-foot { flex-shrink: 0; }

/* footer: status + who you are */
.side-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}
.side-status {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
  margin-bottom: 10px;
}
.side-status .pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 7px var(--ok);
}
.side-status.down .pulse { background: var(--danger); box-shadow: 0 0 7px var(--danger); }
.side-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.side-user .who { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* --- main --------------------------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page-head {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 26px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: rgba(10, 10, 10, .88);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.page-head h1 {
  margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em;
}
.page-head .sub { color: var(--text-faint); font-size: 12px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; }
.page-body { padding: 24px 26px; flex: 1; }

/* --- icons --------------------------------------------------------------
   One stroke family everywhere; sized by context, coloured by currentColor. */
.icn {
  width: 16px; height: 16px;
  flex-shrink: 0;
  vertical-align: -0.15em;
}
.brand-mark { width: 18px; height: 18px; color: var(--accent); }
.nav-item .ico {
  width: 17px; height: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
/* an app's uploaded icon, or its legacy emoji placeholder */
.app-img {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}
.nav-item .ico .app-img { width: 17px; height: 17px; }
.app-placeholder { opacity: .45; }
.card .icon .icn { width: 19px; height: 19px; }
.head-icon .icn { width: 19px; height: 19px; }

/* --- hover tooltip (shared) --------------------------------------------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s, transform .12s;
  z-index: 50;
  box-shadow: var(--shadow);
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- narrow screens: sidebar collapses to a compact top strip ------------
   Two rows only: [brand … status/user] then [nav + horizontally scrolling
   apps]. Without the nowrap the 10-app list wraps and eats half the screen. */
@media (max-width: 860px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; overflow: visible;
    border-right: none; border-bottom: 1px solid var(--border);
    flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 8px 12px; gap: 8px;
  }
  .side-brand { border: none; padding: 0; }
  .side-brand small { display: none; }
  .side-label { display: none; }
  .side-group {
    padding: 0; border: none !important;
    display: flex; gap: 4px; flex-wrap: nowrap;
  }
  .nav-item { width: auto; padding: 6px 10px; flex-shrink: 0; }
  .nav-item .lbl { max-width: 12ch; }

  /* Inviting people and minting API keys are desk jobs — don't spend a
     phone's vertical budget on them. Reachable on a wider screen. */
  #sb-invite, #sb-addapp, #sb-key { display: none; }
  .side-group:has(#sb-invite) { display: none; }

  /* apps: single scrollable row on its own line */
  .side-apps {
    order: 10; flex: 1 0 100%;
    min-width: 0; overflow-x: auto; overflow-y: hidden;
    padding-bottom: 2px;
  }
  .side-apps #side-app-list { display: flex; gap: 4px; flex-wrap: nowrap; }
  .side-apps .nav-item .ver { display: none; }

  .side-foot {
    margin: 0 0 0 auto; border: none; padding: 0;
    display: flex; gap: 12px; align-items: center;
  }
  .side-status { margin: 0; }
  .side-status #status-text { display: none; }   /* keep just the dot */
  .page-head { padding: 14px 16px; }
  .page-body { padding: 16px; }
}
