.app {
  display: grid;
  grid-template-columns: 88px 1fr;
  grid-template-rows: 56px 1fr;
  /* Lock the app to viewport height so internal panes (chat rail,
     chat stream, drawers) own their own scrollbars instead of pushing
     the entire page into a body-level scroll. */
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* brandbar */
.brandbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  /* z-index 65 > drawer (60) — brandbar siedzi nad drawerem (jest też wizualnie
   * powyżej; drawer ma top: 56px). Bez tego brandbar tworzył własny stacking
   * context, więc dropdownik TK (z-index 70) był ograniczony do "5" globalnie
   * i drawer go zakrywał. */
  position: relative; z-index: 65;
}
.brand {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
  color: var(--ink);
  display: flex; align-items: center; gap: 8px;
  flex: none;
}
.brand-logo { height: 26px; width: auto; display: block; }
.brand-dot {
  width: 22px; height: 22px;
  background: var(--accent);
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08), 0 1px 0 rgba(0,0,0,.05);
}
[data-theme="dark"] .brand-dot { color: #14130F; }
.brand-grow { flex: 1; }
.brand-actions { display: flex; align-items: center; gap: 6px; }
.logout-form { margin: 0; }

/* Customization navbar slot — puzzle icon trigger po lewej, koło
   ProjectPill. Trigger korzysta z .iconbtn (whitelabel akcent gdy hover).
   Dropdown leci pod ikoną; content przychodzi z service_customization
   (lista <a>), więc minimalna stylizacja kontenera i delegacja stylu
   linków do designu hosta. */
.brand-navbar-slot { position: relative; display: inline-flex; }
.brand-navbar-slot-trigger { color: var(--ink-3); }
.brand-navbar-slot-trigger:hover,
.brand-navbar-slot-trigger:focus-visible { color: var(--ink); }
.brand-navbar-slot-menu {
  position: absolute;
  top: calc(100% + 6px); left: 0;
  min-width: 220px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
  padding: 6px;
  z-index: 70;
}
.brand-navbar-slot-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  transition: background-color .12s;
}
.brand-navbar-slot-menu a:hover { background: var(--bg-sunk); }

/* Project (workspace) switcher ---------------------------------- */
.project-pill-wrap { position: relative; margin-left: 6px; }
.project-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  max-width: 240px;
}
.project-pill:hover { border-color: var(--line-3); }
.pp-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--accent);
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700;
  font-family: var(--font-mono);
  flex: none;
}
.pp-name {
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 160px;
}
.pp-chev { color: var(--ink-4); display: inline-flex; }
[x-cloak] { display: none !important; }

.project-pop {
  position: absolute;
  top: calc(100% + 8px); left: 0;
  width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  box-shadow: var(--sh-3);
  padding: 8px;
  z-index: 70;
  display: flex; flex-direction: column;
  max-height: min(560px, calc(100vh - 80px));
  min-height: 0;
  overflow: hidden;
}
.project-pop-section + .project-pop-section {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 4px;
}
.project-pop-h {
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-4);
  padding: 8px 10px 4px;
}
.project-pop-search {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 6px 6px;
  padding: 0 10px;
  height: 32px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--bg);
}
.project-pop-search > svg { color: var(--ink-4); flex: none; }
.project-pop-search input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 13px; color: var(--ink);
}
.project-pop-search input::placeholder { color: var(--ink-4); }
.project-pop-list {
  display: flex; flex-direction: column;
  max-height: 240px; overflow-y: auto;
}
.project-pop-form { margin: 0; }
.project-pop-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
.project-pop-item:hover { background: var(--bg-sunk); }
.project-pop-item[data-active="true"] { background: var(--accent-wash); }
[data-theme="dark"] .project-pop-item[data-active="true"] { background: var(--bg-tinted-2); }
.project-pop-name {
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.project-pop-tick { color: var(--accent-deep); display: inline-flex; }
.project-pop-domain {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  margin-top: 1px;
}

/* User menu --------------------------------------------------- */
.user-menu { position: relative; }
.user-menu-trigger { padding: 0 2px !important; }
.user-avatar {
  border-radius: 8px;
  display: inline-grid; place-items: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .02em;
  flex: none;
}
.user-menu-pop {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  width: 260px;
  background: var(--bg-elev);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: var(--sh-3);
  padding: 8px;
  z-index: 70;
}
.user-menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.user-menu-meta { min-width: 0; flex: 1; }
.user-menu-name {
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  letter-spacing: -.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu-email {
  font-size: 11.5px; color: var(--ink-4);
  font-family: var(--font-mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu-sep { height: 1px; background: var(--line); margin: 4px 0; }
.user-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0; background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--ink-2);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.user-menu-item:hover { background: var(--bg-sunk); color: var(--ink); }
.user-menu-danger { color: var(--bad); }
.user-menu-form { margin: 0; }

/* Super-admin marker on the user avatar */
.user-avatar-wrap { position: relative; display: inline-flex; }
.user-super-dot {
  position: absolute;
  top: -2px; right: -2px;
  width: 9px; height: 9px;
  background: #e53935;
  border: 2px solid var(--bg-elev);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(229, 57, 53, .25);
}
.user-super-dot.lg {
  width: 11px; height: 11px;
  top: -3px; right: -3px;
}
.user-super-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  background: #e53935;
  border-radius: 4px;
  vertical-align: middle;
}

/* Onboarding row inside the user menu */
.user-menu-onb {
  display: block;
  padding: 8px 10px;
  margin: 4px 0;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  transition: background .12s, border-color .12s;
}
.user-menu-onb:hover { background: var(--accent-wash); border-color: var(--accent); }
.user-menu-onb-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.user-menu-onb-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3);
}
.user-menu-onb-pct {
  font-size: 13px; font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.user-menu-onb-bar {
  height: 5px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.user-menu-onb-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .25s ease;
}
.user-menu-onb-cta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--accent-deep);
}

/* Workspace + project tree dropdown ---------------------------- */

.ws-list {
  display: flex; flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}
.ws-list::-webkit-scrollbar { width: 8px; }
.ws-list::-webkit-scrollbar-track { background: transparent; }
.ws-list::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 4px;
}
.ws-list::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

.ws-item {
  display: flex; flex-direction: column;
  border-radius: 10px;
  transition: background .12s;
}
.ws-item:hover { background: var(--bg-sunk); }
.ws-item[data-active="true"] { background: var(--accent-wash); }
/* Whitelabel inline-style override forces --accent-wash to its light value
   in every theme, so the active highlight stayed cream-yellow in dark mode
   (light ink on light surface = unreadable). --bg-tinted-2 has a proper
   dark token and is NOT overridden by wl-vars. Same pattern as
   .wf-tmpl-cta in workflows.css. */
[data-theme="dark"] .ws-item[data-active="true"] { background: var(--bg-tinted-2); }

.ws-item-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
.ws-item[data-active="true"] .ws-item-row { font-weight: 600; }
.ws-item-row .pp-avatar { width: 22px; height: 22px; font-size: 10px; }
.ws-item-name {
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: -.005em;
}
.ws-item-active-pill {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--ink);
}
.ws-item-chev {
  color: var(--ink-4);
  display: inline-flex;
  transition: transform .15s;
  flex: none;
}
.ws-item-chev.is-open { transform: rotate(90deg); color: var(--ink); }

.ws-item-projects {
  display: flex; flex-direction: column;
  padding: 4px 6px 6px 36px;
  gap: 1px;
  position: relative;
}
.ws-item-projects::before {
  content: "";
  position: absolute;
  top: 0; bottom: 4px;
  left: 19px;
  width: 1px;
  background: var(--line);
}
.ws-item[data-active="true"] .ws-item-projects::before {
  background: var(--accent-deep);
  opacity: .35;
}

.ws-item-project-form { margin: 0; }
.ws-item-project {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  min-height: 28px;
  padding: 4px 8px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-2);
}
.ws-item-project:hover {
  background: var(--bg-elev);
  color: var(--ink);
}
.ws-item-project[data-active="true"] {
  color: var(--ink);
  font-weight: 600;
}
.ws-item-project-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink-5);
  flex: none;
  margin-left: 2px;
}
.ws-item-project:hover .ws-item-project-dot { background: var(--ink-3); }
.ws-item-project[data-active="true"] .ws-item-project-dot {
  background: var(--accent-deep);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.ws-item-project-meta {
  flex: 1;
  display: flex; align-items: baseline; gap: 8px;
  min-width: 0;
  line-height: 1.2;
}
.ws-item-project-title {
  font-size: 12.5px;
  color: inherit;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.ws-item-project-domain {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-4);
  white-space: nowrap;
  flex: none;
}
.ws-item-project .project-pop-tick {
  color: var(--accent-deep);
  display: inline-flex;
  flex: none;
}

.ws-item-lazy, .ws-item-empty {
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--ink-4);
  letter-spacing: -.003em;
}

.ws-more {
  margin: 8px 6px 2px;
  padding: 9px;
  background: transparent;
  border: 1px dashed var(--line-2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink-3);
  cursor: pointer;
  text-align: center;
  transition: background .12s, color .12s, border-color .12s, border-style .12s;
}
.ws-more:hover {
  color: var(--ink);
  background: var(--bg-sunk);
  border-style: solid;
  border-color: var(--line-3);
}

/* sidebar */
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg);
  padding: 12px 6px;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 0; overflow-y: auto;
}
.sidebar-prefs {
  /* Push to the very bottom of the column + stay subtle. The visible
     part is just the cog icon — no border, no background until hover.
     Per-user nav-visibility tweaks live behind this button so they
     don't compete with the primary nav items for attention. */
  margin-top: auto;
  width: 28px; height: 28px;
  align-self: center;
  display: grid; place-items: center;
  background: transparent; border: 0;
  color: var(--ink-5);
  opacity: .55;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity .15s, color .15s, background .15s;
}
.sidebar-prefs:hover { opacity: 1; color: var(--ink-2); background: var(--bg-sunk); }

/* Sidebar customization modal */
.sidebar-prefs-list { list-style: none; margin: 12px 0 0; padding: 0; }
.sidebar-prefs-li {
  display: flex; align-items: stretch;
  border-radius: 8px;
}
.sidebar-prefs-li:hover { background: var(--bg-sunk); }
.sidebar-prefs-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; flex: 0 0 26px;
  color: var(--ink-5);
  cursor: grab;
  opacity: .55; transition: opacity .12s, color .12s;
}
.sidebar-prefs-li:hover .sidebar-prefs-handle { opacity: 1; color: var(--ink-3); }
.sidebar-prefs-handle:active { cursor: grabbing; }
.sidebar-prefs-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  flex: 1; min-width: 0;
  cursor: pointer;
}
.sidebar-prefs-row input { margin: 0; }
.sidebar-prefs-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; color: var(--ink-3);
}
.sidebar-prefs-label { font-size: 13.5px; color: var(--ink); }
.nav-item {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-3);
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.15;
  transition: background .12s, color .12s, border-color .12s;
}
.nav-item-host { position: relative; }
.nav-badge-slot {
  position: absolute;
  top: 6px; right: 14px;
  pointer-events: none;
  line-height: 0;
}
.nav-badge-slot .nav-unread-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.nav-item .ni-i {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--ink-3);
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg-sunk); color: var(--ink); }
.nav-item:hover .ni-i { color: var(--ink); }
.nav-item[data-active="true"] {
  background: var(--bg-sunk);
  color: var(--ink);
  font-weight: 600;
}
.nav-item[data-active="true"] .ni-i {
  background: var(--accent);
  color: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.07);
}

/* view */
.view {
  min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  /* Chained from .app's overflow:hidden — each view governs its own
     scroll surface (the chat-rail-list, the chat-scroll stream, a
     task list, etc.). overflow:hidden here clips anything that
     misbehaves so the page-level scroll never re-appears. */
  overflow: hidden;
}
.view-header {
  padding: 22px var(--pad-x) 16px;
  display: flex; align-items: center; gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.view-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.015em;
}

/* responsive: collapse sidebar to bottom-nav below md */
@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr 64px;
  }
  .sidebar {
    order: 3;
    flex-direction: row;
    justify-content: space-around;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 6px;
    overflow-x: auto;
  }
  .nav-item { flex: 1; }

  /* brandbar — trim non-essential chrome so the bar fits in 390px.
     Onboarding pill is the worst offender (170px) — hide it; the
     same status is reachable from the onboarding page. ⌘K becomes
     icon-only (no kbd label) since the shortcut doesn't apply on
     mobile anyway. */
  .brandbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .brandbar .onb-chip { display: none; }
  .brandbar .cmdk-btn .kbd,
  .brandbar .cmdk-btn .cmdk-label,
  .brandbar .iconbtn .kbd { display: none; }
  .brandbar .iconbtn { padding-left: 8px; padding-right: 8px; }
}
