/* Connect+ - app chrome: header, icon rail, dashboard toolbar, menus.
   The body is a grid (css/base.css): header across the top, rail on the left,
   toolbar + screen to the right. Heights/widths come from tokens.css. */

/* ---- Shared bits (the header that lived here is now the rail) ---- */
.topbar-spacer { flex: 1; min-width: 0; }

/* Live-connection pill. Hidden while connected (see topbar.setConnectionState);
   amber = reconnecting (data on screen is stale), red = backend alert. The
   persistent live/demo state is the separate #tb-source badge. */
.conn-pill {
  font: 600 var(--fs-xs) var(--font-body);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  min-width: 0;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conn-pill[hidden] { display: none; }
.conn-pill--down {
  color: var(--amb-ink);
  background: var(--warn-bg);
  border: 1px solid var(--warn-ln);
  animation: connpulse 1.8s ease-in-out infinite;
}
.conn-pill--alert {
  color: var(--red-ink);
  background: var(--bad-bg);
  border: 1px solid var(--bad-ln);
}
@keyframes connpulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .conn-pill--down { animation: none; } }

/* Tenant avatar + name */
.tenant-chip { display: flex; align-items: center; gap: var(--sp-2); position: relative; min-width: 0; }
.tenant-avatar {
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  background: var(--acT);
  color: var(--ac-ink);
  display: grid;
  place-items: center;
  font: 600 var(--fs-sm) var(--font-body);
  flex: none;
}
.tenant-name-btn {
  background: none;
  border: none;
  color: var(--tx);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 3px 6px;
  border-radius: var(--r-sm);
  font: 600 var(--fs-md) var(--font-body);
}
.tenant-name-btn > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22ch; }
.tenant-name-btn:hover:not(:disabled) { background: var(--sf2); }
/* Disabled = "this account cannot switch tenants", not "broken": it reads as
   plain text, with no chevron and no not-allowed cursor. */
.tenant-name-btn:disabled { opacity: 1; cursor: default; }
.tenant-name-btn:disabled svg { display: none; }

/* ---- Icon rail ---- */
.rail {
  grid-column: 1;
  grid-row: 1 / -1;
  position: relative;
  z-index: 90;
  background: var(--frame);
}
.rail-inner {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-2) 7px;
  background: var(--frame);
  border-radius: 0 var(--r-canvas) var(--r-canvas) 0;
  transition: width .15s var(--ease-expo);
}
/* Expands over the content on hover or keyboard focus - not on mouse-click
   focus, or a clicked item would pin the rail open. */
/* A rail menu (tenant, theme) holds the rail open so it stays attached. */
.rail:hover .rail-inner,
.rail.is-menu-open .rail-inner,
.rail:has(:focus-visible) .rail-inner {
  width: var(--rail-w-open);
  background: var(--sf);
  box-shadow: var(--shadow-pop);
}
.rail-group {
  height: 22px;
  margin-top: var(--sp-2);
  padding: 0 var(--sp-2);
  font: 600 var(--fs-2xs)/22px var(--font-body);
  color: var(--tx2);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
}
.rail-group:first-child { margin-top: 0; }
.rail:hover .rail-group,
.rail.is-menu-open .rail-group,
.rail:has(:focus-visible) .rail-group { opacity: 1; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 32px;
  padding: 0 7px;
  border: none;
  border-radius: var(--r-md);
  background: none;
  color: var(--tx2);
  font: 500 var(--fs-md) var(--font-body);
  white-space: nowrap;
  cursor: pointer;
}
.nav-btn[hidden] { display: none; }
.nav-btn svg { flex: none; }
.nav-btn { transition: background-color var(--t-out), color var(--t-out); }
.nav-btn:hover { color: var(--tx); background: var(--row-hover); transition-duration: 0s; }
.nav-btn[aria-current="page"] { color: var(--tx); background: var(--sf2); font-weight: 500; box-shadow: inset 2px 0 0 var(--indigo); }
.nav-label { opacity: 0; transition: opacity .1s; }
.rail:hover .nav-label,
.rail.is-menu-open .nav-label,
.rail:has(:focus-visible) .nav-label { opacity: 1; }


/* ---- Rail: brand, tenant, status, theme, sign out ------------------------- */
.rail-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--sp-2); flex: none; }
.rail-brand { display: flex; align-items: center; gap: 12px; height: 36px; padding: 0 2px; }
.rail-brand svg { width: 24px; height: 24px; flex: none; }
.rail-brand .wordmark { font: 600 var(--fs-lg) var(--font-display); letter-spacing: -.01em; line-height: 1; color: var(--tx); }
.rail-brand .wordmark .plus { color: var(--ac-ink); }
.rail-head .tenant-chip { height: 36px; padding: 0 4px; gap: 12px; border-radius: var(--r-md); }
.rail-head .tenant-chip:hover { background: var(--row-hover); }
.rail-head .tenant-name-btn { flex: 1; min-width: 0; padding: 0 4px; justify-content: space-between; }
.rail-head .tenant-name-btn > span:first-child { max-width: none; }
.rail-head #tb-role { align-self: flex-start; margin: 2px 0 2px 38px; }
.rail-spacer { flex: 1; min-height: var(--sp-3); }
.rail-foot { display: flex; flex-direction: column; gap: 2px; flex: none; padding-top: var(--sp-2); }
.rail-status { display: flex; align-items: center; gap: 12px; height: 28px; padding: 0 7px; }
.rail-dot { width: 16px; flex: none; display: grid; place-items: center; }
.rail-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--tx2); }
.rail-status[data-tone="ok"] .rail-dot::before { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.rail-status[data-tone="warn"] .rail-dot::before { background: var(--amb); }
.rail-status[data-tone="bad"] .rail-dot::before { background: var(--red); }
.rail-status .badge { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rail-status .badge::before { display: none; } /* the dot beside it is the status */
/* The pill is the detail behind the dot: only legible once the rail is open. */
.rail .conn-pill { max-width: calc(100% - 8px); margin: 2px 4px; white-space: normal; opacity: 0; transition: opacity .1s; }
.rail:hover .conn-pill, .rail.is-menu-open .conn-pill, .rail:has(:focus-visible) .conn-pill { opacity: 1; }
.rail .menu-anchor:not(.tenant-chip) { display: block; }
.rail #tb-more { display: none; }
.rail-sheet { display: none; }

/* ---- Dashboard toolbar ---- */
.subbar {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 6px var(--sp-4) 6px 0;
  background: var(--frame);
}
.subbar[hidden] { display: none; }
.subbar-dash { display: flex; align-items: center; gap: var(--sp-2); }
.subbar-dash[hidden] { display: none; }

/* Dropdown menu (theme picker etc.) */
.menu-anchor { position: relative; }
.menu-backdrop { position: fixed; inset: 0; z-index: 110; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 120;
  min-width: 220px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  background: var(--sf);
  border: 1px solid var(--ln);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.subbar-dash .menu { right: auto; left: 0; }
.menu-label {
  font: 600 var(--fs-2xs) var(--font-body);
  color: var(--tx2);
  padding: 6px 10px 4px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  border-radius: var(--r-md);
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--tx);
  font: 600 var(--fs-md) var(--font-body);
}
.menu-item:hover { background: var(--sf2); }

/* Accent-palette section of the theme menu (20 swatches, so a grid rather
   than a list - a 20-row menu would not fit the viewport). */
.menu-sep {
  margin: 8px 4px 4px;
  padding-top: 8px;
  border-top: 1px solid var(--ln);
  font: 600 var(--fs-2xs) var(--font-body);
  color: var(--tx2);
}
.palette-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  padding: 4px;
}
.palette-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--ln);
  padding: 0;
  cursor: pointer;
  outline-offset: 2px;
}
.palette-dot:hover { transform: scale(1.18); }
.palette-dot:focus-visible { outline: 2px solid var(--tx); }
.menu-item[aria-selected="true"] { background: var(--acT); color: var(--ac-ink); }
.menu-item .swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--ln);
  flex: none;
}
.menu-item .sub { font: 500 var(--fs-xs) var(--font-body); color: var(--tx2); }

/* ---- Screen area ---- */
#screen-root {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-5) var(--sp-6);
}
#screen-root:focus { outline: none; }

.placeholder-card {
  max-width: 520px;
  margin: 12vh auto 0;
  background: var(--sf);
  border: 1px solid var(--ln);
  border-radius: var(--r-lg);
  padding: 28px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.placeholder-card h1 { margin: 0; font: 600 var(--fs-2xl) var(--font-display); font-variant-numeric: tabular-nums; }
.placeholder-card p { margin: 0; font: 500 var(--fs-md) var(--font-body); color: var(--tx2); line-height: 1.6; }
.placeholder-card .pill {
  font: 600 var(--fs-2xs) var(--font-body);
  color: var(--ac-ink);
  background: var(--acT);
  padding: 3px 8px;
  border-radius: var(--r-sm);
}

/* ---- Phones: the rail becomes a bottom tab bar; brand, tenant, status, theme and
   sign out move into a sheet behind "More" (js/ui/topbar.js layoutRail) ---- */
@media (max-width: 719px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: 56px;
  }
  #impersonation-banner, .subbar, #screen-root { grid-column: 1; }
  body:not(:has(#topbar-root[hidden])) #screen-root { margin: var(--canvas-gap); }
  body:has(.subbar:not([hidden])) #screen-root { margin-top: 0; }
  .rail {
    position: fixed;
    inset: auto 0 0 0;
    height: 56px;
    z-index: 95;
    border-right: none;
    border-top: 1px solid var(--ln);
    background: var(--bg);
  }
  .rail-inner {
    position: static;
    width: 100%;
    height: 100%;
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch;
    gap: 0;
    padding: 4px var(--sp-2);
    border: none;
    box-shadow: none !important;
    border-radius: 0;
    transition: none;
  }
  .rail-group { display: none; }
  /* The desktop rail grows on hover; on a phone a tap leaves a sticky :hover. */
  .rail:hover .rail-inner,
  .rail.is-menu-open .rail-inner,
  .rail:has(:focus-visible) .rail-inner { width: 100%; box-shadow: none; }
  .rail-spacer { display: none; }
  .nav-btn {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    height: auto;
    padding: 0;
    font-size: var(--fs-2xs);
  }
  /* Eight destinations in 390px: full labels collide, so the bar shows a short
     one (data-short) under the icon. */
  .nav-label { display: none; }
  .nav-btn { min-width: 0; }
  .nav-btn::after {
    content: attr(data-short);
    font: 500 var(--fs-2xs) / 1 var(--font-body);
    white-space: nowrap;
  }
  .rail #tb-more { display: flex; }
  .rail-sheet {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 64px;
    z-index: 96;
    padding: var(--sp-2);
    background: var(--sf);
    border: 1px solid var(--ln);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
  }
  .rail-sheet[hidden] { display: none; }
  .rail-sheet .nav-label { display: inline; opacity: 1; }
  .rail-sheet .nav-btn { flex: none; flex-direction: row; justify-content: flex-start; height: 36px; gap: 12px; padding: 0 7px; font-size: var(--fs-md); }
  .rail-sheet .nav-btn::after { content: none; }
  .rail-sheet .rail-head { margin-bottom: var(--sp-1); }
  .rail-sheet .rail-foot { padding-top: var(--sp-1); border-top: 1px solid var(--ln); }
  .rail-sheet .conn-pill { opacity: 1; }
  #screen-root { padding: var(--sp-4) var(--sp-3); }
  .subbar { padding: 6px var(--sp-3); }
}

/* Responsive label swaps per prototype */
.om-full { display: inline; }
.om-short { display: none; }
@media (max-width: 1199px) { .om-full { display: none; } .om-short { display: inline; } }
@media (max-width: 719px) { .om-short { display: none; } }
.om-hide-sm { display: inline; }
@media (max-width: 719px) { .om-hide-sm { display: none; } }

/* ── Read-only impersonation banner ──────────────────────────────────────── */
/* Deliberately high-contrast and full-width: while it is showing, everything
   below it is another tenant's data, and mistaking that for your own is the
   failure mode this strip exists to prevent. */
.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #1b1300;
  background: linear-gradient(90deg, #ffc046, #ffb01f);
  border-bottom: 1px solid rgba(0, 0, 0, 0.28);
}
.impersonation-banner[hidden] { display: none; }
.impersonation-exit {
  padding: 3px 12px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.32);
  border-radius: 6px;
}
.impersonation-exit:hover { background: rgba(0, 0, 0, 0.2); }

/* ── Tenant branding (settings card + top-bar mark) ──────────────────────── */
.sa-logo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.sa-logo-actions {
  display: flex;
  gap: 8px;
}
.sa-logo-preview {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg2);
  border: 1px solid var(--bd);
}
.sa-logo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  font: 600 10px var(--font-body);
  color: var(--tx2);
  text-align: center;
  border: 1px dashed var(--bd);
  border-radius: 8px;
}
/* Fills the existing 24px avatar square rather than resizing the chip, so a
   tall or wide logo can't shift the whole top bar's layout. */
.tenant-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: inherit;
}
