/* SivarAppShell — the shared fleet top bar. Editorial-only, token-driven.
 * Ported from the merged mockup
 * sivar-architecture/design-explorations/sivar-app-shell.html, with all colors
 * expressed as rgb(var(--sivar-*)) so light/dark follow the §19 tokens. Shadows
 * are derived from --sivar-ink (tokens.css carries no shadow tokens).
 */

.sivar-appshell {
  /* Mobile safe area (CONVENTIONS §25). On a Capacitor edge-to-edge WebView the OS
     status bar (clock/wifi/battery) overlays the page, so the fleet bar must grow by
     the top inset to keep the wordmark + app-switcher clear of it. env() is ~52px on
     device and 0 on the web (inert in the browser). Requires viewport-fit=cover.
     The bar's paper background fills the inset strip → seamless status bar. */
  box-sizing: border-box;
  min-height: calc(56px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) 0
    max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  background: rgb(var(--sivar-paper));
  border-bottom: 1px solid rgb(var(--sivar-line));
  font-family: 'Inter', system-ui, sans-serif;
  color: rgb(var(--sivar-ink));
}

/* ── home wordmark ──────────────────────────────────────────── */
.sivar-appshell__home {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: rgb(var(--sivar-ink));
  font-family: var(--sivar-font-display, 'Fraunces', Georgia, serif);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.sivar-appshell__home-dot {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgb(var(--sivar-ink));
  color: rgb(var(--sivar-paper));
  display: grid;
  place-items: center;
  font-family: var(--sivar-font-display, 'Fraunces', Georgia, serif);
  font-weight: 900;
  font-size: 14px;
}

.sivar-appshell__center {
  flex: 1;
  display: flex;
  justify-content: center;
}

/* The cross-app search pill (desktop center). Reads as an input, acts as a
   button — the real input lives in the palette dialog. */
.sivar-appshell__search-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(420px, 100%);
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgb(var(--sivar-line));
  border-radius: 999px;
  background: rgb(var(--sivar-surface));
  color: rgb(var(--sivar-ink-soft));
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 150ms ease;
}

.sivar-appshell__search-pill:hover {
  border-color: rgb(var(--sivar-ink) / 0.4);
}

.sivar-appshell__search-pill-text {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sivar-appshell__search-pill kbd {
  border: 1px solid rgb(var(--sivar-line));
  border-radius: 6px;
  padding: 0 5px;
  font-size: 10px;
  font-family: inherit;
  color: rgb(var(--sivar-ink-soft));
}

.sivar-appshell__right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* App-owned controls (locale, theme, …) — left of the app-switcher. The host
   styles the controls themselves; the shell only lays them out in a row with a
   hairline divider before the switcher cluster. */
.sivar-appshell__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 6px;
  padding-right: 8px;
  border-right: 1px solid rgb(var(--sivar-line));
}

/* Same app-owned controls, but inside the mobile bottom-sheet (below the app
   grid) where there's room — keeps the phone bar uncluttered. */
.sivar-appshell__sheet-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgb(var(--sivar-line));
}

/* ── 9-dot apps button ──────────────────────────────────────── */
.sivar-appshell__icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: rgb(var(--sivar-ink));
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 150ms ease;
}
.sivar-appshell__icon-btn:hover,
.sivar-appshell__icon-btn[data-state='open'] {
  background: rgb(var(--sivar-surface));
}
.sivar-appshell__icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ── anonymous sign-in pill ─────────────────────────────────── */
.sivar-appshell__signin {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: rgb(var(--sivar-ink));
  color: rgb(var(--sivar-paper));
  border: none;
}

/* ── avatar ─────────────────────────────────────────────────── */
.sivar-appshell__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgb(var(--sivar-forest));
  color: rgb(255 255 255);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border: none;
}

/* ── switcher: shared heading + grid + tiles ────────────────── */
.sivar-appshell__switcher-heading {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgb(var(--sivar-ink-soft));
  font-weight: 700;
  margin: 2px 4px 12px;
}
.sivar-appshell__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.sivar-appshell__tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px 6px 10px;
  border-radius: var(--r-btn);
  text-decoration: none;
  color: rgb(var(--sivar-ink));
  position: relative;
  transition: background 150ms ease;
}
.sivar-appshell__tile:hover {
  background: rgb(var(--sivar-surface));
}
.sivar-appshell__tile.is-current {
  background: rgb(var(--sivar-surface));
  box-shadow: inset 0 0 0 1.5px var(--sivar-appshell-accent, rgb(var(--sivar-ink)));
}
.sivar-appshell__tile.is-soon {
  opacity: 0.72;
  cursor: default;
}
.sivar-appshell__tile-glyph {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--sivar-appshell-accent) 14%, transparent);
  color: var(--sivar-appshell-accent);
}
.sivar-appshell__tile-glyph svg {
  width: 22px;
  height: 22px;
}
.sivar-appshell__tile-name {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}
.sivar-appshell__tile-soon {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--sivar-mustard));
  background: color-mix(in srgb, rgb(var(--sivar-mustard)) 16%, transparent);
  padding: 1px 5px;
  border-radius: var(--r-pill);
}

/* ── desktop popover ────────────────────────────────────────── */
.sivar-appshell__popover {
  width: 312px;
  background: rgb(var(--sivar-paper));
  border: 1px solid rgb(var(--sivar-line));
  border-radius: var(--r-card);
  box-shadow: 0 4px 12px rgb(var(--sivar-ink) / 0.08),
    0 16px 48px rgb(var(--sivar-ink) / 0.12);
  padding: 14px;
  z-index: 50;
}
.sivar-appshell__popover-foot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgb(var(--sivar-line));
  text-align: center;
}
.sivar-appshell__popover-foot a {
  color: rgb(var(--sivar-ink-soft));
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

/* ── mobile bottom-sheet ────────────────────────────────────── */
.sivar-appshell__scrim {
  position: fixed;
  inset: 0;
  background: rgb(var(--sivar-ink) / 0.32);
  z-index: 50;
}
.sivar-appshell__sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  background: rgb(var(--sivar-paper));
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: 0 -12px 40px rgb(var(--sivar-ink) / 0.18);
  padding: 14px 14px 22px;
}
.sivar-appshell__grab {
  width: 38px;
  height: 4px;
  border-radius: 4px;
  background: rgb(var(--sivar-line));
  margin: 2px auto 14px;
}

/* ── user menu ──────────────────────────────────────────────── */
.sivar-appshell__menu {
  width: 240px;
  background: rgb(var(--sivar-paper));
  border: 1px solid rgb(var(--sivar-line));
  border-radius: var(--r-card);
  box-shadow: 0 4px 12px rgb(var(--sivar-ink) / 0.08),
    0 16px 48px rgb(var(--sivar-ink) / 0.12);
  padding: 8px;
  z-index: 50;
}
.sivar-appshell__who {
  padding: 10px 12px 12px;
  border-bottom: 1px solid rgb(var(--sivar-line));
  margin-bottom: 6px;
}
.sivar-appshell__who-name {
  font-weight: 700;
  font-size: 14px;
}
.sivar-appshell__who-email {
  color: rgb(var(--sivar-ink-soft));
  font-size: 12px;
}
.sivar-appshell__menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-btn);
  text-decoration: none;
  color: rgb(var(--sivar-ink));
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  user-select: none;
}
.sivar-appshell__menu-item[data-highlighted],
.sivar-appshell__menu-item:hover {
  background: rgb(var(--sivar-surface));
}
.sivar-appshell__menu-item.is-danger {
  color: rgb(var(--sivar-red));
}
.sivar-appshell__menu-item svg {
  opacity: 0.8;
}
.sivar-appshell__menu-sep {
  height: 1px;
  background: rgb(var(--sivar-line));
  margin: 6px 4px;
}
