/* ── Application Layout: Shell, Sidebar, Topbar, Navigation & Viewports ── */

/* ── App Shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* Super Admin Tenant Workspaces Table Logo & Avatar (Option B) */
.tenant-table-logo,
.tenant-table-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  overflow: hidden;
}
.tenant-table-logo {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  padding: 0;
  overflow: hidden;
}

.tenant-table-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.tenant-table-avatar {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  letter-spacing: -0.02em;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.input-sm {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-sm:hover,
.input-sm:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(114, 37, 61, 0.15);
}

.input-sm option {
  background-color: var(--surface);
  color: var(--text);
  padding: 6px 8px;
}

.btn-delete {
  background: rgba(180, 72, 60, 0.1);
  color: var(--danger);
  border: 1px solid rgba(180, 72, 60, 0.25);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-delete:hover {
  background: var(--danger-fill);
  color: var(--tb-on-fill);
  border-color: var(--danger-fill);
}

@keyframes spin { 100% { transform: rotate(360deg); } }

.spacer { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: var(--r-full);
  font-size: 12px;
  background: var(--ok-bg);
  color: var(--ok-fg);
  font-family: var(--mono);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

.topbar-session-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}
.topbar-session-pill:hover {
  border-color: var(--brand-primary);
  color: var(--brand-text);
}
.topbar-session-pill .dot {
  background: var(--brand-primary);
  box-shadow: 0 0 6px var(--brand-primary);
  flex: none;
}
.topbar-session-pill.hidden {
  display: none !important;
}

.topbar-token-counters {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--text-2);
  user-select: none;
  transition: opacity 0.2s ease;
}
.topbar-token-counters.hidden {
  display: none !important;
}
.topbar-token-counters .token-metric {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.topbar-token-counters .token-lbl {
  color: var(--text-3);
  font-weight: 500;
  text-transform: lowercase;
}
.topbar-token-counters .token-val {
  color: var(--text);
  font-weight: 600;
}
.topbar-token-counters .token-metric.token-total .token-val {
  color: var(--brand-text);
}
@media (max-width: 900px) {
  .topbar-token-counters {
    display: none !important;
  }
}

.topbar-chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-chat-actions.hidden {
  display: none !important;
}
.topbar-history-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}
.topbar-history-btn:hover, .topbar-history-btn.active {
  border-color: var(--brand-primary);
  color: var(--brand-text);
}
.topbar-history-btn .badge {
  background: rgba(114, 37, 61, 0.15);
  color: var(--brand-text);
  font-weight: 600;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
}
.topbar-history-btn .badge:empty {
  display: none !important;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--surface);
}
.seg button {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
}
.seg button.on {
  background: var(--brand-primary);
  color: #fff;
  font-weight: 600;
}

.view {
  padding: 26px 32px;
  max-width: 1300px;
  width: 100%;
}

.grid { display: grid; gap: 16px; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media(max-width: 1000px) { .g3, .g2 { grid-template-columns: 1fr; } }

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tile h3 { margin: 0; font-size: 17px; font-weight: 600; }
.tile p { margin: 0; font-size: 14px; color: var(--text-2); }
.tile .metric { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.delta-up { color: var(--ok-fg); font-size: 13px; font-family: var(--mono); }
.delta-dn { color: var(--warn); font-size: 13px; font-family: var(--mono); }

.sectionhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 14px;
}
.sectionhead h3 { margin: 0; font-size: 16px; font-weight: 600; }

/* ── Collection views (Dashboards, Money Ball) ───────────────────────────────
   One slim navigation bar (folder crumb · linkable item tabs · tools) above a page that fills the rest of
   the viewport. Tabs are <a href="#<area>/<id>"> links; the active one carries an underline. */
.dash-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 16px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.dash-folder-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  padding-inline-end: 16px;
  border-inline-end: 1px solid var(--line);
  line-height: 18px;
}
[dir="rtl"] .dash-folder-label { letter-spacing: 0; text-transform: none; font-size: 12.5px; }
.dash-tablist {
  display: flex;
  align-self: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.dash-tablist::-webkit-scrollbar { display: none; }
.dash-tab-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s ease, background .15s ease;
}
.dash-tab-btn svg { opacity: .65; flex: none; }
.dash-tab-btn:hover { color: var(--text); background: var(--bg-hover); }
.dash-tab-btn.active { color: var(--brand-text); font-weight: 600; }
.dash-tab-btn.active svg { opacity: 1; }
.dash-tab-btn.active::after {
  content: "";
  position: absolute;
  inset-inline: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand-text);
}
.dash-tab-btn:focus-visible { outline: 2px solid var(--tb-spice); outline-offset: -2px; }
.dash-tools {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 6px;
}
.dash-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.dash-action-btn:hover { border-color: var(--line-active); color: var(--brand-text); background: var(--bg-hover); }
@media (max-width: 760px) {
  .dash-tool-label { display: none; }
  .dash-action-btn { padding: 7px; }
  .dash-folder-label { display: none; }
}
.dash-iframe-wrap {
  width: 100%;
  height: calc(100vh - 180px);
  min-height: 600px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
  position: relative;
}
.dash-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Full-width collection views: the page takes the whole main column and the rest of the viewport
   (top bar ~57px + view padding + navigation bar ~54px) */
.view.view-dashboards,
.view.view-moneyball {
  max-width: 100%;
  width: 100%;
  padding: 6px 18px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  box-sizing: border-box;
}
.view.view-dashboards .dash-iframe-wrap,
.view.view-moneyball .dash-iframe-wrap {
  flex: 1;
  height: calc(100vh - 134px);
  height: calc(100dvh - 134px);
  min-height: 560px;
  box-shadow: 0 1px 3px rgba(31, 20, 24, .06);
  background: var(--bg);
}
@media (max-width: 860px) {
  .view.view-dashboards,
  .view.view-moneyball { padding-inline: 10px; }
}

/* ── Responsive Window Interactivity ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .history-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .history-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-history-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    border-radius: 0;
    z-index: 1050;
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.35);
    transform: translateX(100%);
    display: flex !important;
  }

  [dir="rtl"] .chat-history-sidebar {
    right: auto;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.35);
  }

  .chat-history-sidebar.open {
    transform: translateX(0);
  }

  .chat-history-sidebar.collapsed {
    transform: translateX(100%);
    display: flex !important;
  }

  [dir="rtl"] .chat-history-sidebar.collapsed {
    transform: translateX(-100%);
  }
}

.chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 4px 6px 6px 4px;
  box-sizing: border-box;
  overflow: visible;
}

/* Dynamic 2x2 grid when history sidebar is open or viewport is constrained */
.chat-layout.history-open .chips {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 1200px) {
  .chips {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .chips,
  .chat-layout.history-open .chips {
    grid-template-columns: 1fr;
  }
}

.suggest {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: start;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggest:hover {
  border-color: var(--brand-primary);
  color: var(--brand-text);
  background: var(--tb-brand-wash);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(114, 37, 61, 0.12);
}
.suggest-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  width: 100%;
  text-align: inherit;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 22px;
  padding: 6px 8px 6px 16px;
  width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, border-radius 0.15s ease;
}
.composer:focus-within {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(114, 37, 61, 0.2);
}
.composer textarea,
.composer input {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  resize: none;
  max-height: 160px;
  min-height: 22px;
  overflow-y: auto;
}
.composer textarea::placeholder,
.composer input::placeholder {
  color: var(--text-3);
}
.iconbtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--brand-primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-bottom: 2px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.iconbtn:hover {
  transform: scale(1.05);
}
.empty { color: var(--text-3); text-align: center; padding: 40px 0; }

/* ══ The Brain rail (sidebar) ═══════════════════════════════════════════════ */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
#app.hidden { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-block: 18px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: 14px;
  background: linear-gradient(180deg, var(--tb-ink-2), var(--tb-ink) 60%);
  color: var(--tb-on-ink);
  --tb-f: "Segoe UI", "Segoe UI Variable", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  font-family: var(--tb-f);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .18) transparent;
}
[dir="rtl"] .sidebar {
  padding-right: max(14px, env(safe-area-inset-right, 0px));
  padding-left: 14px;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); border-radius: 4px; }
.sidebar :focus-visible { outline: 2px solid var(--tb-spice); outline-offset: 2px; }

.brandrow { display: flex; align-items: center; gap: 10px; padding: 2px 6px; min-width: 0; }
.brandrow .brand-mark { width: 36px; height: 36px; flex: none; color: var(--tb-on-ink); }
.brand-words { min-width: 0; }
.brand-words b { display: block; font-size: 19px; font-weight: 600; letter-spacing: -.01em; line-height: 1; }
.brand-words b span { font-weight: 300; }
.brand-words small { display: block; font-size: 11.5px; color: var(--tb-on-ink-dim); margin-top: 3px; overflow-wrap: anywhere; }

/* Workspace card (workspace users) / workspace switcher (super admin): tenant logo tile + name */
.ws {
  display: flex; align-items: center; gap: 11px;
  width: 100%; min-width: 0;
  padding: 9px 11px 9px 9px;
  border-radius: var(--tb-r-md);
  border: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(135deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .03));
  color: var(--tb-on-ink);
  text-align: start;
  font: inherit;
  transition: background .15s ease, border-color .15s ease;
}
[dir="rtl"] .ws { padding: 9px 9px 9px 11px; }
.ws.hidden { display: none !important; }
button.ws { cursor: pointer; }
button.ws:hover { background: rgba(255, 255, 255, .1); border-color: rgba(242, 179, 61, .45); }
.ws-logo {
  width: 40px; height: 40px; flex: none;
  border-radius: 10px;
  background: var(--tb-brand);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .16), 0 4px 12px rgba(0, 0, 0, .35);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
  overflow: hidden;
}
.ws-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ws-logo .ws-globe { width: 22px; height: 22px; fill: none; stroke: var(--tb-on-ink); stroke-width: 1.6; }
.ws-logo-sm { width: 26px; height: 26px; border-radius: 7px; font-size: 10px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .14); }
.ws-logo-sm .ws-globe { width: 16px; height: 16px; }
.ws-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.ws-text > span { font-size: 15px; font-weight: 600; letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-text small { color: var(--tb-on-ink-dim); font-size: 11.5px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sa-tenant-switcher { display: flex; flex-direction: column; }
.sa-tenant-switcher.hidden { display: none !important; }
.sa-select-wrap.custom-tenant-dropdown { position: relative; width: 100%; }
.sa-tenant-trigger { justify-content: space-between; }
.sa-tenant-trigger-left { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; overflow: hidden; }
.sa-tenant-trigger-arrow { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--tb-on-ink-dim); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
.custom-tenant-dropdown:has(.sa-tenant-menu:not(.hidden)) .sa-tenant-trigger-arrow { transform: rotate(180deg); }
.sa-tenant-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  inset-inline: 0;
  background: var(--tb-ink);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: var(--tb-r-md);
  padding: 5px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, .55);
  z-index: 1060;
  max-height: min(340px, 60vh);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
}
.sa-tenant-menu.hidden { display: none !important; }
.sa-tenant-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; border-radius: var(--tb-r-sm);
  cursor: pointer; font-size: 13px; color: var(--tb-on-ink);
}
.sa-tenant-item:hover { background: var(--tb-rail-hover); }
.sa-tenant-item.selected { background: var(--tb-rail-active); font-weight: 600; }
.sa-tenant-item-left { display: flex; align-items: center; gap: 9px; min-width: 0; overflow: hidden; }
.sa-tenant-item-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sa-tenant-item-check { color: var(--tb-spice); flex: none; }

/* Navigation: uppercase section labels, plain items, filled active item */
.navgroup { display: flex; flex-direction: column; gap: 14px; }
.navsection { display: flex; flex-direction: column; gap: 4px; }
#navAdminGroup { gap: 4px; }
.navgroup-items { display: flex; flex-direction: column; gap: 2px; }
.navlabel {
  margin: 0 10px 2px;
  font-size: 11px; font-weight: 600; line-height: 1.4;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--tb-on-ink-dim); opacity: .85;
}
[dir="rtl"] .navlabel { letter-spacing: 0; font-size: 12px; }
.navitem {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-width: 0;
  padding: 9px 12px;
  border: 0; border-radius: var(--tb-r-sm);
  background: none; color: var(--tb-on-ink);
  cursor: pointer; text-align: start;
  font-family: inherit; font-size: 14.5px; font-weight: 400;
  transition: background .15s ease;
}
.navitem .nav-ico {
  width: 19px; height: 19px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: .92;
}
.navitem .nav-text { min-width: 0; overflow-wrap: anywhere; }
.navitem:hover { background: rgba(255, 255, 255, .06); }
.navitem.active { background: #7A2442; box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset; color: #fff; font-weight: 600; }
.navitem.active .nav-ico { opacity: 1; }
.navitem.active:hover { background: #84294A; }

.nav-expand-chevron {
  margin-inline-start: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: none;
  border-radius: var(--tb-r-sm);
  opacity: .55;
  transition: transform .25s cubic-bezier(.4, 0, .2, 1), opacity .2s ease, background .15s ease;
}
.navitem:hover .nav-expand-chevron { opacity: .85; }
.nav-expand-chevron:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.nav-expand-chevron.expanded { transform: rotate(90deg); opacity: 1; }
[dir="rtl"] .nav-expand-chevron { transform: rotate(180deg); }
[dir="rtl"] .nav-expand-chevron.expanded { transform: rotate(90deg); }

/* Sub-items (Ask The Brain: + New question / History; Dashboards list) */
.nav-subgroup {
  display: flex; flex-direction: column; gap: 1px;
  margin-inline-start: 22px;
  padding-inline-start: 10px;
  border-inline-start: 1px solid rgba(255, 255, 255, .14);
  max-height: 0; opacity: 0; overflow: hidden; pointer-events: none;
  transition: max-height .25s cubic-bezier(.4, 0, .2, 1), opacity .2s ease, margin .2s ease;
}
.nav-subgroup.expanded { max-height: 1600px; opacity: 1; overflow: visible; margin-block: 2px 4px; pointer-events: auto; }
.navitem.nav-subitem { font-size: 13.5px; padding: 7px 10px; gap: 8px; color: var(--tb-on-ink-dim); font-weight: 400; }
.navitem.nav-subitem span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navitem.nav-subitem:hover { color: var(--tb-on-ink); background: var(--tb-rail-hover); }
.navitem.nav-subitem svg { flex: none; opacity: .75; }
.navitem.nav-subitem.active,
.navitem.nav-subitem.active:hover { background: rgba(255, 255, 255, .09); color: #fff; font-weight: 600; box-shadow: none; }

/* Ask The Brain: recent chats (last 10) */
.nav-recent { display: flex; flex-direction: column; gap: 1px; }
.nav-recent:empty { display: none; }
.nav-recent-label { margin: 8px 10px 3px; font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--tb-on-ink-dim); opacity: .7; }
[dir="rtl"] .nav-recent-label { letter-spacing: 0; font-size: 11.5px; }
.navitem.nav-recent-item { font-size: 13px; padding: 6px 10px; }
.nav-recent-pin { width: 12px; height: 12px; flex: none; fill: none; stroke: var(--tb-spice); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Dashboards sub-menu: collapsible folders */
.nav-folder-btn { font-weight: 400; color: var(--tb-on-ink-dim); }
.nav-folder-btn .nav-folder-chev { opacity: .7; transition: transform .15s ease; }
.nav-folder.open > .nav-folder-btn .nav-folder-chev { transform: rotate(90deg); }
[dir="rtl"] .nav-folder-btn .nav-folder-chev { transform: scaleX(-1); }
[dir="rtl"] .nav-folder.open > .nav-folder-btn .nav-folder-chev { transform: rotate(90deg); }
.nav-folder-count { margin-inline-start: auto; font-size: 11px; line-height: 1; padding: 2px 6px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: var(--tb-on-ink-dim); }
.nav-folder-items { display: none; flex-direction: column; gap: 1px; margin-inline-start: 13px; padding-inline-start: 8px; border-inline-start: 1px solid rgba(255, 255, 255, .1); }
.nav-folder.open > .nav-folder-items { display: flex; }
.nav-folder-empty { display: block; padding: 4px 8px; font-size: 12px; color: var(--tb-on-ink-dim); opacity: .7; font-style: italic; }

/* Footer: one panel — workspace (card / switcher) on top, signed-in user + sign-out below.
   Sticky so it stays reachable when the nav is long. */
.sidefoot {
  position: sticky; bottom: 0; z-index: 3;
  margin: auto -14px -18px; padding: 10px 14px 18px;
  background: var(--tb-ink);
  box-shadow: 0 -14px 18px -10px var(--tb-ink);
}
.sf-panel {
  display: flex; flex-direction: column;
  border-radius: var(--tb-r-md);
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(255, 255, 255, .045);
}
.sidefoot .ws {
  border: 0; background: none;
  border-radius: calc(var(--tb-r-md) - 1px) calc(var(--tb-r-md) - 1px) 0 0;
  padding: 10px;
}
.sidefoot button.ws:hover, .sidefoot .custom-tenant-dropdown:has(.sa-tenant-menu:not(.hidden)) button.ws { background: rgba(255, 255, 255, .07); }
.sidefoot .ws-logo { width: 42px; height: 42px; border-radius: 11px; }
.sf-user {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
}
.sf-panel > :not(.hidden) ~ .sf-user { border-top: 1px solid rgba(255, 255, 255, .08); }
.sf-avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--tb-spice); color: var(--tb-ink);
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.sf-who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.sf-who b { font-size: 13px; font-weight: 600; color: var(--tb-on-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-who small { font-size: 11.5px; color: var(--tb-on-ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-signout {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, .14); border-radius: var(--tb-r-sm);
  background: none; color: var(--tb-on-ink-dim);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.sf-signout svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .sf-signout svg { transform: scaleX(-1); }
.sf-signout:hover { background: rgba(179, 38, 30, .22); border-color: rgba(255, 140, 130, .45); color: #FFD9D5; }

/* ══ Main column + top bar ══════════════════════════════════════════════════ */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-block: 12px;
  padding-left: 28px;
  padding-right: max(28px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--tb-bg) 86%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--tb-line);
  color: var(--tb-fg);
  font-family: var(--tb-f);
}
[dir="rtl"] .topbar { padding-right: 28px; padding-left: max(28px, env(safe-area-inset-left, 0px)); }
.topbar :focus-visible { outline: 2px solid var(--tb-spice); outline-offset: 2px; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; min-width: 0; overflow-wrap: anywhere; }
.tb-menu {
  display: none;
  border: 1px solid var(--tb-line);
  background: var(--tb-surface);
  color: var(--tb-fg);
  border-radius: var(--tb-r-sm);
  padding: 6px 10px;
  cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500;
}
.tb-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; padding: 3px 10px; border-radius: 999px;
  white-space: nowrap;
}
.tb-status i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: tbBlink 2s ease-in-out infinite; }
.tb-status-live { color: var(--tb-good); background: var(--tb-good-soft); }
.tb-status-delayed { color: var(--tb-warn); background: var(--tb-warn-soft); }
.tb-status-unknown { color: var(--tb-muted); background: var(--tb-sunk); }
@keyframes tbBlink { 50% { opacity: .35; } }
.tb-fresh { font-size: 12.5px; color: var(--tb-muted); min-width: 0; overflow-wrap: anywhere; }
.topbar .seg { border-color: var(--tb-line); background: var(--tb-surface); border-radius: 999px; padding: 2px; }
.topbar .seg button { border-radius: 999px; padding: 4px 12px; color: var(--tb-muted); font-weight: 500; font-family: inherit; }
.topbar .seg button.on { background: var(--tb-brand); color: #fff; }
.topbar .seg button:not(.on):hover { color: var(--tb-fg); }

/* Appearance switch (System / Light / Dark, js/theme.js): icon-only, quieter "on" state than the language switch */
.seg-theme button { display: grid; place-items: center; }
.topbar .seg-theme button { padding: 4px 9px; }
.topbar .seg-theme button.on { background: var(--tb-bar-soft); color: var(--tb-brand-text); }
.seg-theme svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.topbar-session-pill:focus-visible { outline: 2px solid var(--tb-spice); }

.rail-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 19; }

/* Mobile: the rail becomes an off-canvas drawer (RTL-aware) */
@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 290px);
    height: 100%;
    transform: translateX(-102%);
    transition: transform .2s ease, visibility .2s;
    padding-top: calc(18px + env(safe-area-inset-top, 0px));
    visibility: hidden;
  }
  [dir="rtl"] .sidebar { inset: 0 0 0 auto; transform: translateX(102%); }
  .sidebar.open { transform: none; visibility: visible; }
  .tb-menu { display: inline-block; }
  .topbar,
  [dir="rtl"] .topbar {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .tb-fresh { display: none; }
  .view,
  [dir="rtl"] .view { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}
@media (max-width: 620px) {
  .topbar { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .tb-status i { animation: none; }
  .sidebar { transition: none; }
}
