/* Salvo webapp template (MIG-121) — the shared app shell.

   One stylesheet for every Salvo web app: the React components in this folder
   and the framework-free renderers (vanilla.js) emit the same salvo-* classes,
   so the shell looks the same in REMI, Home, core, LiveClip, Ingest, ATEM
   Builder and the status page. No inline styles are needed, so it works
   under a CSP of style-src 'self'. Colours, type and spacing come from
   tokens.css; load that first (index.js imports both).

   Brand v2: square corners, hairline borders, nothing under 12px, no
   decorative caps microtype. */

/* ---------- Shell frame ---------- */

/* Mantine apps get border-box from Mantine; the vanilla build doesn't. */
[class^="salvo-"],
[class*=" salvo-"],
[class^="salvo-"] *,
[class*=" salvo-"] * {
  box-sizing: border-box;
}

.salvo-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

/* Full-bleed tool apps (REMI, ATEM Builder): exactly one viewport tall, the
   main area scrolls or fills on its own. */
.salvo-shell--bleed {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.salvo-shell__body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.salvo-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.salvo-shell--bleed .salvo-main { overflow: auto; }

/* Leave room for the fixed bottom nav on phones. */
.salvo-shell--bottomnav .salvo-main { padding-bottom: var(--lgl-bottom-nav-h); }

.salvo-skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 300;
  padding: 8px 12px;
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  font-size: 14px;
}
.salvo-skip:focus { left: 8px; }

/* ---------- Shared controls ---------- */

.salvo-shell :focus-visible,
.salvo-topbar :focus-visible,
.salvo-footer :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.salvo-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--lgl-duration-fast) var(--lgl-ease), color var(--lgl-duration-fast) var(--lgl-ease);
}
.salvo-iconbtn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* A text button in the bar (workspace switcher). */
.salvo-barbtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: 600 13px/1 var(--font-ui);
  cursor: pointer;
  text-decoration: none;
}
.salvo-barbtn:hover { background: var(--bg-hover); }
.salvo-barbtn[disabled], .salvo-barbtn--static { cursor: default; }
.salvo-barbtn--static:hover { background: transparent; }
.salvo-barbtn__icon { color: var(--text-muted); font-size: 12px; }
.salvo-barbtn__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(200px, 26vw);
}
.salvo-barbtn__caret { color: var(--text-muted); font-size: 12px; }

.salvo-sep {
  width: 1px;
  height: 20px;
  flex-shrink: 0;
  background: var(--border);
}

/* Square avatar: initials on the cobalt fill (white label). */
.salvo-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--accent-control);
  color: var(--accent-contrast);
  font: 600 13px/1 var(--font-ui);
}
.salvo-avatar img { width: 100%; height: 100%; object-fit: cover; }
.salvo-avatar--lg { width: 40px; height: 40px; font-size: 16px; }

/* Count / state badge on a nav item. */
.salvo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  white-space: nowrap;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font: 500 12px/1 var(--font-mono);
  font-feature-settings: var(--font-features-mono);
}
.salvo-badge--accent { background: var(--accent-control); color: var(--accent-contrast); }
.salvo-badge--live { background: var(--status-live); color: #fff; }
.salvo-badge--error { background: var(--status-error); color: #fff; }

/* ---------- Lockup ---------- */

.salvo-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  color: inherit;
  text-decoration: none;
}
.salvo-lockup-svg, .salvo-mark { display: block; flex-shrink: 0; }
.salvo-lockup__divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}
.salvo-lockup__product {
  font: 600 14px/1 var(--font-ui);
  color: var(--text-secondary);
  white-space: nowrap;
}

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

.salvo-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 52px;
  padding: 0 16px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.salvo-topbar__nav {
  display: flex;
  align-self: stretch;
  /* Reach over the bar's bottom border so the active underline replaces it
     (the nav scrolls, so the tabs can't overflow it themselves). */
  margin-bottom: -1px;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.salvo-topbar__nav::-webkit-scrollbar { display: none; }

.salvo-topbar__chips {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Chips keep their size; the nav (which scrolls) gives way first. */
  flex-shrink: 0;
}

.salvo-topbar__end {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-width: 0;
}

.salvo-topbar__burger { display: none; }

/* Nav tab: muted until active, a 2px accent underline on the bar's border. */
.salvo-navtab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font: 600 13px/1 var(--font-ui);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--lgl-duration-fast) var(--lgl-ease);
}
.salvo-navtab:hover { color: var(--text-primary); }
.salvo-navtab.is-active,
.salvo-navtab[aria-current="page"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}
.salvo-navtab__icon { font-size: 12px; opacity: 0.8; }

/* ---------- Sidebar (admin apps) ---------- */

.salvo-sidebar {
  width: 232px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  overflow-y: auto;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.salvo-sidebar__heading {
  padding: 16px 12px 6px;
  color: var(--text-muted);
  font: 600 12px/1.2 var(--font-ui);
}

.salvo-sidenav {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font: 500 14px/1.2 var(--font-ui);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.salvo-sidenav:hover { background: var(--bg-hover); color: var(--text-primary); }
.salvo-sidenav.is-active,
.salvo-sidenav[aria-current="page"] {
  background: var(--accent-dim);
  border-left-color: var(--accent);
  color: var(--text-primary);
  font-weight: 600;
}
.salvo-sidenav__icon { width: 16px; font-size: 13px; text-align: center; color: var(--text-muted); }
.salvo-sidenav.is-active .salvo-sidenav__icon { color: var(--accent-text); }
.salvo-sidenav .salvo-badge { margin-left: auto; }

/* ---------- Bottom nav (phones) ---------- */

.salvo-bottomnav { display: none; }

/* ---------- Drawer nav (burger, phones) ---------- */

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

/* ---------- Dropdown (vanilla build; React uses Mantine Menu) ---------- */

.salvo-dropdown { position: relative; min-width: 0; }
.salvo-dropdown > summary { max-width: 100%; }
.salvo-dropdown > summary { list-style: none; }
.salvo-dropdown > summary::-webkit-details-marker { display: none; }
.salvo-dropdown__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 200;
  min-width: 220px;
  padding: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: var(--overlay-shadow);
}
.salvo-dropdown__panel--start { left: 0; right: auto; }
.salvo-dropdown__panel--wide { min-width: 300px; }
.salvo-dropdown__label {
  padding: 8px 10px 4px;
  color: var(--text-muted);
  font: 500 12px/1.2 var(--font-ui);
}
.salvo-dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: 400 14px/1.2 var(--font-ui);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.salvo-dropdown__item:hover { background: var(--bg-hover); }
.salvo-dropdown__item.is-active::after {
  content: '';
  width: 6px;
  height: 6px;
  margin-left: auto;
  background: var(--accent);
}
.salvo-dropdown__item--danger { color: var(--status-error); }
.salvo-dropdown__divider { height: 1px; margin: 4px 0; background: var(--border); }

/* ---------- Menus (shared by React and vanilla) ---------- */

.salvo-menuhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  min-width: 0;
}
.salvo-menuhead__text { min-width: 0; }
.salvo-menuhead__name {
  color: var(--text-primary);
  font: 600 14px/1.3 var(--font-ui);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.salvo-menuhead__sub {
  color: var(--text-muted);
  font: 400 13px/1.3 var(--font-ui);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.salvo-menuicon { width: 14px; font-size: 12px; text-align: center; color: var(--text-muted); }
.salvo-menucheck { font-size: 12px; color: var(--accent-text); }

/* App switcher grid. */
.salvo-apps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
}
.salvo-apps__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 76px;
  padding: 10px 6px;
  border: 1px solid transparent;
  color: var(--text-primary);
  font: 500 13px/1.2 var(--font-ui);
  text-align: center;
  text-decoration: none;
}
.salvo-apps__item:hover { background: var(--bg-hover); }
.salvo-apps__item.is-active { border-color: var(--accent-edge); background: var(--accent-dim); }
.salvo-apps__icon { font-size: 18px; color: var(--accent-text); }

/* ---------- Inline alert ---------- */

/* Neutral panel, hairline border, 3px status rule; colour only on the rule
   and the icon. Text stays ink and muted. */
.salvo-alert {
  --salvo-alert-tone: var(--lgl-info);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--salvo-alert-tone);
  color: var(--text-primary);
  font: 400 14px/1.45 var(--font-ui);
}
.salvo-alert--success { --salvo-alert-tone: var(--status-live); }
.salvo-alert--warning { --salvo-alert-tone: var(--status-warning); }
.salvo-alert--error   { --salvo-alert-tone: var(--status-error); }
.salvo-alert--info    { --salvo-alert-tone: var(--lgl-info); }
.salvo-alert--neutral { --salvo-alert-tone: var(--text-muted); }

.salvo-alert__icon {
  display: inline-flex;
  align-items: center;
  height: 20px;
  flex-shrink: 0;
  color: var(--salvo-alert-tone);
  font-size: 14px;
}
.salvo-alert__body { flex: 1; min-width: 0; }
.salvo-alert__title { font-weight: 600; color: var(--text-primary); }
.salvo-alert__text { color: var(--text-secondary); overflow-wrap: anywhere; }
.salvo-alert__title + .salvo-alert__text { margin-top: 2px; }
.salvo-alert__action { flex-shrink: 0; align-self: center; }
.salvo-alert__close { width: 24px; height: 24px; margin: -2px -4px 0 0; color: var(--text-muted); }

/* ---------- Row ---------- */

/* Hairline between rows; the last row leaves the bottom edge to its container
   (a bordered Card would otherwise show a double line). */
.salvo-row { border-bottom: 1px solid var(--border); }
.salvo-row:last-child { border-bottom: 0; }

/* ---------- Status badge ---------- */

/* Hairline frame, ink label, colour only on a square indicator: a lit cell
   of the Salvo mark. The square sits with equal space above, below and to
   its left, so it never touches the frame. */
.salvo-status {
  --salvo-status-tone: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 10px 0 7px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font: 500 13px/1 var(--font-ui);
  white-space: nowrap;
  vertical-align: middle;
}
.salvo-status--md { height: 32px; gap: 10px; padding: 0 12px 0 9px; font-size: 14px; }
.salvo-status__dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  background: var(--salvo-status-tone);
}
.salvo-status--md .salvo-status__dot { width: 12px; height: 12px; }
.salvo-status--success { --salvo-status-tone: var(--status-live); }
.salvo-status--warning { --salvo-status-tone: var(--status-warning); }
.salvo-status--error   { --salvo-status-tone: var(--status-error); }
.salvo-status--info    { --salvo-status-tone: var(--lgl-info); }
.salvo-status--accent  { --salvo-status-tone: var(--accent); }
.salvo-status--neutral { --salvo-status-tone: var(--text-muted); }
.salvo-status--neutral { color: var(--text-secondary); }
.salvo-status--pulse .salvo-status__dot { animation: lgl-pulse 1.6s var(--lgl-ease) infinite; }
@media (prefers-reduced-motion: reduce) {
  .salvo-status--pulse .salvo-status__dot { animation: none; }
}

/* ---------- Page layout ---------- */

.salvo-page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
  box-sizing: border-box;
}
.salvo-page--wide { max-width: 1440px; }
.salvo-page--bleed {
  max-width: none;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Footer ---------- */

.salvo-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--bg-deep);
}
.salvo-footer__inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
  box-sizing: border-box;
  color: var(--text-muted);
  font: 400 13px/1.4 var(--font-ui);
}
.salvo-footer__brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text-secondary); }
.salvo-footer__links { display: flex; flex-wrap: wrap; gap: 16px; margin-left: auto; }
.salvo-footer a { color: var(--text-secondary); text-decoration: none; }
.salvo-footer a:hover { color: var(--accent-text); text-decoration: underline; }
.salvo-footer__version { font-family: var(--font-mono); font-feature-settings: var(--font-features-mono); font-size: 12px; }

/* Compact: one 36px line, for full-bleed tool apps. */
.salvo-footer--compact .salvo-footer__inner {
  max-width: none;
  min-height: 36px;
  padding: 6px 16px;
  font-size: 12px;
}

/* ---------- States ---------- */

.salvo-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  padding: 48px 24px;
  text-align: center;
}
.salvo-state--page { min-height: 60vh; }
.salvo-state__icon { font-size: 24px; color: var(--text-muted); }
.salvo-state__icon--error { color: var(--status-error); }
.salvo-state__title { margin: 0; font: 600 18px/1.35 var(--font-display); color: var(--text-primary); }
.salvo-state__text { margin: 0; max-width: 460px; color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.salvo-state__detail {
  max-width: 560px;
  margin: 0;
  padding: 8px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: 400 12px/1.5 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left;
}
.salvo-state__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }

/* Plain buttons for the vanilla build and the states (React apps can pass
   Mantine buttons instead). */
.salvo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border-light);
  background: var(--bg-panel);
  color: var(--text-primary);
  font: 600 14px/1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
}
.salvo-btn:hover { background: var(--bg-hover); }
.salvo-btn--primary { background: var(--accent-control); border-color: var(--accent-control); color: var(--accent-contrast); }
.salvo-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

/* Boot splash: static markup in index.html, visible until the app mounts
   over it. Mark lit cells breathe; nothing moves with reduced motion. */
.salvo-boot {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-deep);
  color: var(--text-muted);
  font: 500 14px/1.4 var(--font-ui);
}
.salvo-boot .salvo-mark__lit { animation: lgl-pulse 1.6s var(--lgl-ease) infinite; }
@media (prefers-reduced-motion: reduce) {
  .salvo-boot .salvo-mark rect { animation: none !important; }
}

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .salvo-topbar { gap: 10px; padding: 0 12px; }
  .salvo-topbar__nav { display: none; }
  .salvo-topbar__burger { display: inline-flex; }
  .salvo-lockup { gap: 8px; }
  .salvo-topbar__end { gap: 2px; }
  .salvo-barbtn { padding: 0 4px; }
  .salvo-barbtn__label { max-width: 24vw; }
  .salvo-hide-mobile { display: none !important; }
  .salvo-sidebar { display: none; }
  .salvo-page { padding: 16px; }

  .salvo-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    height: var(--lgl-bottom-nav-h);
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
  }
  .salvo-bottomnav__item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-top: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font: 600 12px/1 var(--font-ui);
    text-decoration: none;
    cursor: pointer;
  }
  .salvo-bottomnav__item.is-active,
  .salvo-bottomnav__item[aria-current="page"] { color: var(--text-primary); border-top-color: var(--accent); }
  .salvo-bottomnav__icon { font-size: 18px; }
  .salvo-bottomnav__item > span:not(.salvo-badge) {
    max-width: 100%;
    padding: 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .salvo-bottomnav__item .salvo-badge { position: absolute; top: 6px; left: calc(50% + 6px); }
}

@media (min-width: 769px) {
  .salvo-hide-desktop { display: none !important; }
}
