:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --border: #2f3b4f;
  --text: #e7ecf3;
  --muted: #9aa8bc;
  --accent: #3d8bfd;
  --accent-2: #2f6fed;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --danger: #f07178;
  --user: #1e3a5f;
  --assistant: #1b2838;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

/* UI font size (settings → cookie → html class). rem-based UI scales from html. */
html.font-size-sm { font-size: 87.5%; }  /* ~14px */
html.font-size-md { font-size: 100%; }   /* ~16px */
html.font-size-lg { font-size: 125%; }   /* ~20px */
html.font-size-xl { font-size: 156.25%; } /* ~25px — заметно крупнее обычного */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.45;
}

/* Chat page: lock viewport, scroll only inside chat pane */
body.page-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
body.page-chat .topbar,
body.page-chat .flash-wrap {
  flex-shrink: 0;
}
body.page-chat .flash-wrap {
  max-width: none;
  margin: 0;
  padding: 0.5rem 1.25rem 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.deploy-dirty-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  color: #fff;
  background: #c0152f;
  animation: deploy-dirty-blink 1.1s ease-in-out infinite;
}
.deploy-dirty-banner-files {
  font-weight: 400;
  opacity: 0.9;
}
@keyframes deploy-dirty-blink {
  0%, 100% { background: #c0152f; }
  50% { background: #7a0d1e; }
}
@media (prefers-reduced-motion: reduce) {
  .deploy-dirty-banner { animation: none; background: #c0152f; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  padding-top: max(0.65rem, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  /* Solid / high-opacity bg: backdrop-filter on this sticky bar creates a
     containing block that clips the Projects absolute submenu (same class of
     bug as the mobile nav drawer). Blur lives on a non-clipping ::before. */
  background: rgba(15, 20, 25, 0.94);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  position: sticky;
  top: 0;
  z-index: 100;
  overflow: visible;
}
.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: rgba(15, 20, 25, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex-shrink: 0;
}
/* Hamburger: only on narrow screens (see mobile block) */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(99, 179, 237, 0.08);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:hover {
  border-color: var(--accent);
  background: rgba(99, 179, 237, 0.14);
}
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 1.1rem;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after { top: 6px; }
body.nav-open .nav-toggle-bars {
  background: transparent;
}
body.nav-open .nav-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}
body.nav-open .nav-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}
.site-nav-drawer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
}
.nav-backdrop,
.sidebar-backdrop {
  display: none;
}
.brand {
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { color: var(--accent); text-decoration: none; }
.app-revision {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  user-select: all;
  flex-shrink: 0;
  opacity: 0.85;
}
.app-revision.is-behind {
  color: #ff4d4f;
  opacity: 1;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255, 77, 79, 0.85);
}
.topbar-nav {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
  overflow: visible;
}
.topbar-user {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
}
.topbar-link {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color 0.15s ease, background 0.15s ease;
}
.topbar-link:hover {
  color: var(--text);
  background: rgba(99, 179, 237, 0.1);
  text-decoration: none;
}
.topbar-link.active {
  color: var(--accent);
  background: rgba(99, 179, 237, 0.12);
}

/* Topbar dropdown (Projects submenu) — desktop: hover; mobile: .is-open */
.nav-dropdown {
  position: relative;
  display: inline-block;
  vertical-align: middle;
}
.nav-dropdown-trigger {
  /* button reset so it matches .topbar-link */
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  line-height: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.nav-dropdown-trigger::after {
  content: "▾";
  font-size: 0.7em;
  opacity: 0.75;
  transition: transform 0.15s ease;
}
.nav-dropdown:hover > .nav-dropdown-trigger,
.nav-dropdown:focus-within > .nav-dropdown-trigger,
.nav-dropdown.is-open > .nav-dropdown-trigger,
.nav-dropdown.active > .nav-dropdown-trigger {
  color: var(--accent);
  background: rgba(99, 179, 237, 0.12);
}
.nav-dropdown:hover > .nav-dropdown-trigger::after,
.nav-dropdown:focus-within > .nav-dropdown-trigger::after,
.nav-dropdown.is-open > .nav-dropdown-trigger::after {
  transform: rotate(180deg);
  opacity: 1;
}
.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 14rem;
  max-width: min(22rem, 92vw);
  max-height: min(70vh, 24rem);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.4rem;
  /* bridge gap so mouse can travel trigger → menu without close */
  margin-top: 0;
  border-radius: 12px;
  border: 1px solid rgba(99, 179, 237, 0.22);
  background: rgba(12, 18, 28, 0.98);
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.2),
    0 16px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(0, 0, 0, 0.25);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease,
    visibility 0.14s ease;
}
/* Invisible hit area above panel — keeps hover while crossing the gap */
.nav-dropdown-menu::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -0.55rem;
  height: 0.55rem;
}
.nav-dropdown:hover > .nav-dropdown-menu,
.nav-dropdown:focus-within > .nav-dropdown-menu,
.nav-dropdown.is-open > .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0.2rem);
}
.nav-dropdown-item {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-dropdown-item:hover,
.nav-dropdown-item:focus-visible {
  background: rgba(99, 179, 237, 0.14);
  color: var(--accent);
  text-decoration: none;
  outline: none;
}
.nav-dropdown-all {
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  margin-bottom: 0.2rem;
  padding-bottom: 0.55rem;
}
.nav-dropdown-empty {
  padding: 0.45rem 0.75rem;
  display: block;
}
html[dir="rtl"] .nav-dropdown-menu {
  left: auto;
  right: 0;
}

.topbar-user-name {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user-name:hover {
  color: var(--accent);
  text-decoration: none;
}
.topbar-logout {
  display: inline;
  margin: 0;
}

/* Language switcher */
.lang-switcher {
  display: inline-flex;
  align-items: center;
  margin: 0;
}
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(99, 179, 237, 0.1);
  border: 1px solid rgba(99, 179, 237, 0.3);
  color: var(--text);
  border-radius: 8px;
  padding: 0.3rem 1.6rem 0.3rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.lang-select:hover,
.lang-select:focus {
  border-color: var(--accent);
  outline: none;
}
.lang-select option {
  background: var(--panel);
  color: var(--text);
}

.env-switcher {
  display: inline-flex;
  align-items: center;
  margin: 0 0.8rem 0 0;
}
.env-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(99, 179, 237, 0.1);
  border: 1px solid rgba(99, 179, 237, 0.3);
  color: var(--text);
  border-radius: 8px;
  padding: 0.3rem 1.6rem 0.3rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.env-select:hover,
.env-select:focus {
  border-color: var(--accent);
  outline: none;
}
.env-select option {
  background: var(--panel);
  color: var(--text);
}

/* RTL (Hebrew) */
html[dir="rtl"] body {
  direction: rtl;
}
html[dir="rtl"] .topbar-left {
  flex-direction: row-reverse;
}
html[dir="rtl"] .site-nav-drawer {
  flex-direction: row-reverse;
}
html[dir="rtl"] .topbar-user {
  flex-direction: row-reverse;
}
html[dir="rtl"] .topbar-nav {
  flex-direction: row-reverse;
}
html[dir="rtl"] .lang-select {
  padding: 0.3rem 0.55rem 0.3rem 1.6rem;
  background-position: 12px 55%, 7px 55%;
}
html[dir="rtl"] .chat-layout {
  direction: rtl;
}
html[dir="rtl"] .sidebar {
  border-right: none;
  border-left: 1px solid var(--border);
}
html[dir="rtl"] .btn-text,
html[dir="rtl"] .home-content {
  text-align: right;
}
html[dir="rtl"] .info-row,
html[dir="rtl"] .settings-header {
  direction: rtl;
}
html[dir="rtl"] .prompt-bar {
  direction: rtl;
}
/* Statusbar controls stay LTR even in Hebrew UI (selects, buttons, order). */
html[dir="rtl"] .chat-statusbar {
  direction: ltr;
}
html[dir="rtl"] .msg .role {
  text-align: right;
}

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1, .card h1, .sidebar h2 { margin: 0 0 0.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
/* .btn { display: inline-flex } must not defeat the HTML hidden attribute */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.card.narrow, .login-card { max-width: 480px; margin: 2rem auto; }
.empty { text-align: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.project-card-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: flex-start; }
.project-card h2 { font-size: 1.15rem; }
.path {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
  margin: 0.4rem 0 0.8rem;
}

.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag {
  font-size: 0.72rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  color: var(--muted);
}

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.primary { background: var(--accent-2); border-color: transparent; }
.btn.danger {
  background: rgba(240, 113, 120, 0.18);
  border-color: rgba(240, 113, 120, 0.55);
  color: #ffb4b8;
}
.btn.danger:hover { background: rgba(240, 113, 120, 0.32); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.block { width: 100%; }
.btn.small { padding: 0.25rem 0.55rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.stack { display: flex; flex-direction: column; gap: 0.85rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.92rem; }
input[type=text], input[type=password], input[type=number], textarea, select {
  background: #0d1218;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}
textarea { resize: vertical; min-height: 2.5rem; }

.flash-wrap { max-width: 1100px; margin: 0.75rem auto 0; padding: 0 1.25rem; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.55rem 0.55rem 0.8rem;
  margin-bottom: 0.4rem;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.flash.is-dismissed {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}
.flash-text {
  flex: 1 1 auto;
  min-width: 0;
}
.flash-dismiss {
  flex: 0 0 auto;
  margin: -0.15rem -0.1rem -0.15rem 0;
  padding: 0.15rem 0.4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.2;
  cursor: pointer;
  border-radius: 6px;
}
.flash-dismiss:hover,
.flash-dismiss:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}
.flash.success { border-color: rgba(62,207,142,0.4); }
.flash.error { border-color: rgba(240,113,120,0.5); }

.section { margin-top: 2rem; }
.session-list { list-style: none; padding: 0; margin: 0; }

/* Tree-only projects above the chat list */
.sidebar-tree-projects {
  flex: 0 0 auto;
  margin: 0.35rem 0 0.55rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-tree-projects > h3 {
  margin: 0 0 0.35rem;
}
.tree-project-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.tree-project-item .tree-project-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  color: var(--text);
  border: 1px solid transparent;
  text-decoration: none;
}
.tree-project-item .tree-project-link:hover {
  background: var(--panel);
  border-color: var(--border);
}
.tree-project-item.active .tree-project-link {
  background: var(--panel);
  border-color: var(--accent, #5b8cff);
}
.tree-project-icon {
  flex: 0 0 auto;
  opacity: 0.9;
}
.tree-project-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}
.chat-tree-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.chat-tree-panel .project-tree-layout {
  flex: 1 1 auto;
  min-height: 12rem;
}

/* Session list grows and scrolls — no duplicate “selected chat” panel below */
.sidebar-chats {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.sidebar-chats > .sidebar-filter {
  flex: 0 0 auto;
}
.sidebar-chats .session-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.15rem;
  margin-right: -0.1rem;
}

/* Simple session links (dev page etc.) — not used for .session-item rows */
.session-list > li:not(.session-item) > a {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  color: var(--text);
  border: 1px solid transparent;
}
.session-list > li:not(.session-item) > a:hover {
  background: var(--panel);
  border-color: var(--border);
  text-decoration: none;
}
.session-list.compact > li:not(.session-item) > a {
  display: block;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-list > li:not(.session-item).active > a {
  background: var(--panel-2);
  border-color: var(--border);
}

/* Chat sidebar: one row per session — [dot] [title…] [⋮] */
.session-item {
  position: relative;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.2rem;
  width: 100%;
  min-width: 0;
  padding: 0 0.1rem;
  margin-bottom: 1px;
  border-radius: 8px;
  transition: background 0.15s ease;
  list-style: none;
  box-sizing: border-box;
}

.session-item:hover,
.session-item.menu-open {
  background: rgba(99, 179, 237, 0.1);
}

.session-item.active {
  background: var(--panel-2);
}

/* Sidebar header: “+ Новый чат” and the open-chat quota share one row */
.sidebar-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sidebar-top #new-chat-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  white-space: nowrap;
  overflow: hidden;
}
.chat-quota {
  flex: 0 0 auto;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chat-quota strong {
  color: var(--text);
}
.chat-quota-full {
  color: var(--warn);
  font-weight: 600;
}
.btn-disabled,
a.btn-disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: not-allowed;
}
/* Mute only the row chrome — never the whole item.
   Parent opacity would make the fixed ⋮ menu translucent and trap it
   in a stacking context so later session rows paint over the menu. */
.session-item.session-closed > .session-status-dot,
.session-item.session-closed > .session-link,
.session-item.session-closed > .session-card-actions,
.session-item.session-draft > .session-status-dot,
.session-item.session-draft > .session-link,
.session-item.session-draft > .session-card-actions {
  opacity: 0.72;
}
.session-item.session-closed:hover > .session-card-actions,
.session-item.session-closed.menu-open > .session-card-actions,
.session-item.session-draft:hover > .session-card-actions,
.session-item.session-draft.menu-open > .session-card-actions {
  opacity: 1;
}
.session-item.session-draft .session-link {
  cursor: default;
}
.draft-banner {
  border-color: rgba(99, 179, 237, 0.35);
}
.session-item.session-closed .session-title-text {
  font-style: italic;
}
.session-closed-badge {
  display: inline-block;
  flex: 0 0 auto;
  font-size: 0.7rem;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  text-transform: lowercase;
}
.closed-chat-banner {
  margin: 0 0 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(99, 179, 237, 0.08);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}
.task-done-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  border-color: rgba(72, 187, 120, 0.4);
  background: rgba(72, 187, 120, 0.1);
  color: var(--text);
}
.task-done-banner.hidden {
  display: none;
}
.task-done-banner.is-running {
  border-color: rgba(99, 179, 237, 0.45);
  background: rgba(99, 179, 237, 0.1);
}
.task-done-banner.is-fail {
  border-color: rgba(245, 101, 101, 0.45);
  background: rgba(245, 101, 101, 0.1);
}
.task-done-banner .task-done-banner-label {
  flex: 0 0 auto;
  font-weight: 650;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.session-status-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
  margin-left: 0.25rem;
  border: 1px solid transparent;
  box-sizing: border-box;
}

/* task_done PASS (✓) / finalize OK (✓✓) instead of the green ready dot */
.session-status-dot.session-status-checks {
  width: auto;
  min-width: 0.7rem;
  height: auto;
  border-radius: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  opacity: 1;
  color: var(--ok);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.08em;
  animation: none;
}

/* Open idle chats (any, not only selected) — ready/free */
.session-item.session-ready .session-status-dot {
  background: var(--ok);
  opacity: 1;
  box-shadow: 0 0 6px rgba(62, 207, 142, 0.4);
}

/* Selected row: stronger glow; color still comes from ready/running/closed */
.session-item.active.session-ready .session-status-dot {
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.55);
}

/* Any open chat with its own AI turn in flight */
.session-item.session-running .session-status-dot {
  background: var(--warn);
  opacity: 1;
  box-shadow: 0 0 6px rgba(237, 201, 72, 0.45);
  animation: pulse-dot 1.4s ease-in-out infinite;
}

/* Error / interrupted / stuck blocker — sticky red until a new turn */
.session-item.session-error .session-status-dot {
  background: var(--danger);
  opacity: 1;
  box-shadow: 0 0 6px rgba(240, 113, 120, 0.45);
  animation: none;
}

/* Closed chat: colorless hollow status (AI released) */
.session-item.session-closed .session-status-dot {
  background: transparent;
  opacity: 0.55;
  box-shadow: none;
  animation: none;
  border-color: var(--muted);
}

/* Draft: neutral until first prompt creates a real session */
.session-item.session-draft .session-status-dot {
  background: var(--muted);
  opacity: 0.55;
  box-shadow: none;
  animation: none;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.75; }
}

.session-menu a.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  text-decoration: none;
  color: inherit;
  box-sizing: border-box;
}

/* One line per chat: [title…] [project…] — the row title attribute has both in full */
.session-link {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.3rem;
  padding: 0.22rem 0.3rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.86rem;
  line-height: 1.3;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
}

.session-title-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-project-badge {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 45%;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.7;
}

/* Filtered to a single project — the per-row project name is redundant */
.session-list.single-project .session-project-badge {
  display: none;
}

.session-link:hover {
  background: rgba(99, 179, 237, 0.12);
  text-decoration: none;
}

.session-item.active .session-link {
  font-weight: 600;
}

.sidebar-filter {
  margin: 0;
}
.sidebar-filter select {
  width: 100%;
  margin: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border-radius: 6px;
  background: #0d1218;
  border: 1px solid var(--border);
  color: var(--text);
}
.sidebar-filter select:focus {
  outline: none;
  border-color: var(--accent, #63b3ed);
}

.project-fixed-name {
  display: inline-block;
  max-width: 12rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.82rem;
  border-radius: 6px;
  background: #0d1218;
  border: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.model-picker.project-locked {
  opacity: 0.95;
}

.session-card-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.1rem;
  margin-right: 0.15rem;
}

.session-action-btn,
.session-menu-btn {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}

.session-menu-btn {
  font-size: 1.05rem;
  opacity: 0.55;
}

.session-item:hover .session-action-btn,
.session-item:hover .session-menu-btn,
.session-item.menu-open .session-menu-btn,
.session-item.active .session-action-btn,
.session-action-btn:focus-visible,
.session-menu-btn:focus-visible {
  opacity: 1;
}

.session-action-btn:hover,
.session-action-btn:active,
.session-action-btn:focus-visible,
.session-menu-btn:hover,
.session-menu-btn:active,
.session-menu-btn:focus-visible,
.session-item.menu-open .session-menu-btn {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
  outline: none;
}

.session-action-btn.close-chat-btn:hover,
.session-action-btn.close-chat-btn:focus-visible {
  color: var(--warn, #edc948);
  border-color: rgba(237, 201, 72, 0.35);
}

.session-action-btn.reopen-chat-btn:hover,
.session-action-btn.reopen-chat-btn:focus-visible {
  color: var(--ok, #3ecf8e);
  border-color: rgba(62, 207, 142, 0.35);
}

/* Fixed positioning is applied in JS so the panel is not clipped by sidebar overflow.
   Solid opaque panel + high z-index so menu never blends with session rows beneath. */
.session-menu {
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--panel-2, #243044);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 160px;
  z-index: 10000;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  padding: 0.25rem 0;
  opacity: 1;
  isolation: isolate;
}

.session-menu.hidden {
  display: none !important;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.9rem;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  transition: background 0.1s ease, color 0.1s ease;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: rgba(99, 179, 237, 0.2);
  outline: none;
}

.menu-item.danger {
  color: #ffb4b8;
}

.menu-item.danger:hover,
.menu-item.danger:focus-visible {
  background: rgba(240, 113, 120, 0.2);
  color: var(--danger);
}

/* Chat layout — fills remaining viewport under topbar */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/*
 * Footer status bar (under prompt), always column top→bottom:
 *   TOP row  = Статус + таймер | Проект | Ветка | [Переписка]
 *   BOTTOM   = Модель | Агент | Разрешения | … (LTR left→right)
 */
.chat-statusbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.12rem;
  padding: 0.14rem 0.65rem 0.16rem;
  border-top: 1px solid var(--border);
  background: rgba(20, 28, 40, 0.96);
  font-size: 0.74rem;
  line-height: 1.2;
  direction: ltr;
}
.statusbar-row {
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
  min-height: 1.55rem;
}
/* TOP: status left, project/branch/thread clustered right */
.statusbar-row-top {
  direction: ltr;
  justify-content: space-between;
  gap: 0.35rem 0.6rem;
  flex-wrap: nowrap;
  order: 0;
}
/* BOTTOM: controls always LTR, start from the left */
.statusbar-row-bottom {
  direction: ltr;
  justify-content: flex-start;
  gap: 0.25rem 0.45rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  white-space: nowrap;
  order: 1;
}
.chat-statusbar .agent-status {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  flex-wrap: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border: none;
  background: transparent;
  min-height: 0;
  font-size: inherit;
}
.chat-statusbar .agent-status-dot {
  width: 0.45rem;
  height: 0.45rem;
}
.chat-statusbar .agent-status-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12rem;
}
.chat-statusbar .agent-status-timer {
  flex-shrink: 0;
}
/* Project + Branch + Переписка — same top-row group */
.statusbar-context {
  display: flex;
  align-items: center;
  gap: 0.3rem 0.45rem;
  flex-shrink: 0;
  flex-wrap: nowrap;
  direction: ltr;
  margin-inline-start: auto;
}
.statusbar-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem 0.45rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
  direction: ltr;
  justify-content: flex-start;
  min-width: 0;
  width: 100%;
}
/* Override global label { flex-direction: column } — keep pickers on one line */
.chat-statusbar .model-picker {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.22rem;
  margin: 0;
  font-size: inherit;
  line-height: 1.15;
  white-space: nowrap;
  flex-shrink: 0;
}
.chat-statusbar .model-picker > .muted {
  font-size: 0.68rem;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}
.model-picker {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.22rem;
  margin: 0;
}
.model-picker select {
  min-width: 5.2rem;
  max-width: 9rem;
  height: 1.45rem;
  padding: 0 0.28rem;
  font-size: 0.72rem;
  line-height: 1.2;
  border-radius: 5px;
  background: #0d1218;
}
.chat-statusbar .model-picker select {
  min-width: 5rem;
  max-width: 8.5rem;
  height: 1.4rem;
  padding: 0 0.22rem;
  font-size: 0.72rem;
}
/* Provider status chip next to model select (official status pages, not load %) */
.provider-health {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  margin: 0;
  padding: 0.05rem 0.32rem 0.05rem 0.22rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.65rem;
  line-height: 1.2;
  color: var(--muted);
  text-decoration: none;
  flex-shrink: 0;
  max-width: 7.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.provider-health:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--text);
}
.provider-health[hidden] {
  display: none !important;
}
.provider-health-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.provider-health.ok .provider-health-dot { background: var(--ok); }
.provider-health.degraded .provider-health-dot {
  background: var(--warn);
  box-shadow: 0 0 0 2px rgba(240, 180, 41, 0.25);
}
.provider-health.outage .provider-health-dot {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(240, 113, 120, 0.28);
}
.provider-health.unknown .provider-health-dot { background: var(--muted); }
.provider-health.degraded {
  color: #f5d78a;
  border-color: rgba(240, 180, 41, 0.45);
}
.provider-health.outage {
  color: #f5a8ad;
  border-color: rgba(240, 113, 120, 0.5);
}
.provider-health-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-picker.isolate-branch-toggle {
  cursor: pointer;
  user-select: none;
  gap: 0.2rem;
}
.model-picker.isolate-branch-toggle input[type="checkbox"] {
  margin: 0;
  width: 0.85rem;
  height: 0.85rem;
  accent-color: var(--accent, #3b82f6);
  cursor: pointer;
  flex-shrink: 0;
}
/* Compact quota/context chips: bar + short label only */
.usage-panel {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  color: var(--muted);
  max-width: 6.2rem;
  flex-shrink: 0;
}
.usage-bar-wrap {
  display: inline-block;
  width: 2.1rem;
  height: 0.28rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: hidden;
  vertical-align: middle;
  flex-shrink: 0;
}
.usage-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.25s ease, background 0.25s ease;
}
.usage-panel.warn .usage-bar { background: var(--warn); }
.usage-panel.danger .usage-bar { background: var(--danger); }
.usage-label, .cost-label {
  white-space: nowrap;
  font-size: 0.7rem;
  line-height: 1;
  min-width: 0;
}
.credits-panel {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  max-width: 5.5rem;
}
.credits-panel:hover .usage-label,
.credits-panel:hover .cost-label { color: var(--text); }
.credits-panel .credits-bar { background: #5b8def; }
.credits-panel.warn .credits-bar { background: var(--warn); }
.credits-panel.danger .credits-bar { background: var(--danger); }
.ws-chip {
  color: var(--muted);
  font-size: 0.7rem;
  flex-shrink: 0;
  white-space: nowrap;
}
.ws-chip #ws-status { font-weight: 600; }
.chat-statusbar .btn.small {
  padding: 0.1rem 0.35rem;
  font-size: 0.7rem;
  border-radius: 5px;
  min-height: 1.4rem;
  line-height: 1.1;
}
/* «Переписка» — only on TOP row, next to Branch; solid button on dark bar */
.statusbar-row-top .agent-thread-btn,
.statusbar-context .agent-thread-btn,
.statusbar-context button.agent-thread-btn.btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin: 0;
  margin-inline-start: 0.2rem;
  padding: 0.2rem 0.7rem;
  min-height: 1.55rem;
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  border-radius: 7px;
  border: 1px solid #1f5fd0;
  background: #2f6fed;
  color: #fff !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  text-decoration: none;
}
.statusbar-row-top .agent-thread-btn:hover,
.statusbar-context .agent-thread-btn:hover,
.statusbar-context button.agent-thread-btn.btn:hover {
  background: #4a8dff;
  border-color: #4a8dff;
  color: #fff !important;
  filter: none;
}
.statusbar-row-top .agent-thread-btn:focus-visible {
  outline: 2px solid rgba(99, 179, 237, 0.9);
  outline-offset: 1px;
}
.statusbar-row-top .agent-thread-btn[hidden],
.statusbar-context .agent-thread-btn[hidden] {
  display: none !important;
}
.statusbar-row-top .agent-thread-btn .agent-thread-badge {
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
}
/* Never show thread button in the bottom controls row */
.statusbar-row-bottom .agent-thread-btn {
  display: none !important;
}

/* Git branch chip (statusbar) + sidebar branch line */
.git-branch-chip .git-branch-name {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
.chat-statusbar .project-fixed-name {
  font-size: 0.74rem;
  white-space: nowrap;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.git-branch-chip.is-empty .git-branch-name { color: var(--muted); font-weight: 400; }
.meta .git-branch { margin-top: 0.25rem; }
.meta .git-branch code { color: var(--accent); }

/* Agent run state: working / done / stuck / waiting */
.agent-status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding: 0.45rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 28, 40, 0.92);
  font-size: 0.9rem;
  min-height: 2.4rem;
}
.agent-status-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
  box-shadow: 0 0 0 0 transparent;
}
.agent-status-label { font-weight: 650; letter-spacing: 0.01em; }
.agent-status-detail { flex: 1; min-width: 8rem; }
.agent-status-timer {
  font-family: var(--mono);
  font-size: 0.78rem;
  opacity: 0.85;
}
.agent-status.idle .agent-status-dot { background: var(--ok); }
.agent-status.idle .agent-status-label { color: var(--ok); }

.agent-status.working .agent-status-dot {
  background: var(--accent);
  animation: agent-pulse 1.1s ease-in-out infinite;
}
.agent-status.working .agent-status-label { color: var(--accent); }
.agent-status.working {
  background: linear-gradient(90deg, rgba(61,139,253,0.12), rgba(20,28,40,0.92) 55%);
}
.chat-statusbar .agent-status.working,
.chat-statusbar .agent-status.waiting,
.chat-statusbar .agent-status.stuck,
.chat-statusbar .agent-status.done,
.chat-statusbar .agent-status.error,
.chat-statusbar .agent-status.idle {
  background: transparent;
  border: none;
}

.agent-status.waiting .agent-status-dot {
  background: var(--warn);
  animation: agent-pulse 1.4s ease-in-out infinite;
}
.agent-status.waiting .agent-status-label { color: var(--warn); }
.agent-status.waiting {
  background: linear-gradient(90deg, rgba(240,180,41,0.14), rgba(20,28,40,0.92) 55%);
}

.stuck-panel.stuck-long-process .stuck-badge {
  background: rgba(240, 180, 41, 0.2);
  color: var(--warn);
}
.stuck-panel.stuck-long-process {
  border-color: rgba(240, 180, 41, 0.45);
}
.agent-status.stuck .agent-status-dot {
  background: var(--danger);
  animation: agent-blink 0.9s step-end infinite;
}
.agent-status.stuck .agent-status-label { color: var(--danger); }
.agent-status.stuck {
  background: linear-gradient(90deg, rgba(240,113,120,0.16), rgba(20,28,40,0.92) 55%);
  border-bottom-color: rgba(240,113,120,0.35);
}

.agent-status.done .agent-status-dot { background: var(--ok); }
.agent-status.done .agent-status-label { color: var(--ok); }
.agent-status.done {
  background: linear-gradient(90deg, rgba(62,207,142,0.14), rgba(20,28,40,0.92) 55%);
}

.agent-status.error .agent-status-dot { background: var(--danger); }
.agent-status.error .agent-status-label { color: var(--danger); }

/* Soft tint on whole footer bar by phase */
.chat-statusbar:has(.agent-status.working) {
  background: linear-gradient(90deg, rgba(61,139,253,0.1), rgba(20,28,40,0.96) 50%);
}
.chat-statusbar:has(.agent-status.waiting) {
  background: linear-gradient(90deg, rgba(240,180,41,0.12), rgba(20,28,40,0.96) 50%);
}
.chat-statusbar:has(.agent-status.stuck),
.chat-statusbar:has(.agent-status.error) {
  background: linear-gradient(90deg, rgba(240,113,120,0.12), rgba(20,28,40,0.96) 50%);
}
.chat-statusbar:has(.agent-status.done) {
  background: linear-gradient(90deg, rgba(62,207,142,0.1), rgba(20,28,40,0.96) 50%);
}

@keyframes agent-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(61,139,253,0.55); }
  50% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(61,139,253,0); }
}
@keyframes agent-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(20, 28, 40, 0.95);
  padding: 0.55rem 0.6rem;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.sidebar .back { font-size: 0.9rem; }
.sidebar h3 { margin: 0.6rem 0 0.2rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.meta code { font-family: var(--mono); font-size: 0.72rem; }
.meta {
  flex: 0 0 auto;
  font-size: 0.75rem;
  line-height: 1.3;
}
.meta-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
}
.meta-row > #sidebar-project-name {
  flex: 0 1 auto;
  min-width: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta-row > .git-branch {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta .path {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-publish-url {
  margin: 0.15rem 0 0;
  min-width: 0;
}
.sidebar-publish-url-a {
  display: inline-block;
  max-width: 100%;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--accent, #7aa2f7);
  text-decoration: none;
}
.sidebar-publish-url-a:hover {
  text-decoration: underline;
}
.statusbar-site-link {
  flex: 0 0 auto;
  text-decoration: none;
}
.statusbar-site-link[hidden] {
  display: none !important;
}
.project-publish-url {
  color: var(--accent, #7aa2f7);
  text-decoration: none;
}
.project-publish-url:hover {
  text-decoration: underline;
}

.project-run-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
/* ▶ Запустить and the ⚙ setup toggle share one row — the command itself
   lives in the run button's tooltip instead of a separate hint line. */
.project-run-row {
  display: flex;
  align-items: stretch;
  gap: 0.3rem;
}
.project-run-row #project-run-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
  overflow: hidden;
}
.project-run-block .muted-link {
  flex: 0 0 auto;
  text-align: center;
  color: var(--muted);
  border-style: dashed;
  cursor: pointer;
  background: transparent;
  padding: 0.35rem 0.5rem;
  font: inherit;
}
.project-run-block .muted-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.agent-docs-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  max-height: 11rem;
  min-height: 0;
}
.agent-docs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}
.agent-docs-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.agent-docs-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 0;
}
.agent-docs-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  text-decoration: none;
  color: var(--text);
  font-size: 0.78rem;
  min-width: 0;
  cursor: pointer;
}
.agent-docs-item:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.agent-docs-item .msg-file-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-docs-empty {
  padding: 0.15rem 0.2rem;
}

/* Agent document preview — always centered in the viewport */
.agent-doc-modal-root {
  z-index: 12000;
  align-items: center !important;
  justify-content: center !important;
  padding: 1.25rem !important;
}
.agent-doc-modal {
  width: min(920px, 96vw) !important;
  max-height: min(90vh, 90dvh) !important;
  margin: 0 auto;
}
.agent-doc-modal-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.agent-doc-modal-body {
  flex: 1 1 auto;
  min-height: 12rem;
  max-height: calc(90vh - 4.5rem);
  overflow: auto;
  gap: 0.75rem;
}
.agent-doc-modal-body .md-body,
.agent-doc-modal-body .agent-doc-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cascadia Code", Consolas, ui-monospace, monospace;
  font-size: 0.86rem;
  line-height: 1.45;
}
.agent-doc-modal-body .md-body {
  font-family: inherit;
  white-space: normal;
}
.agent-doc-modal-body .agent-doc-frame,
.agent-doc-modal-body .agent-doc-img {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
}
.agent-doc-modal-body .agent-doc-frame {
  min-height: min(70vh, 36rem);
  height: min(70vh, 36rem);
}
.agent-doc-modal-body .agent-doc-img {
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  max-height: min(70vh, 36rem);
}

.project-run-edit {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem 0.5rem;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.project-run-edit[hidden] {
  display: none !important;
}
.project-run-edit label {
  margin: 0;
}
.project-run-edit .project-run-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(15, 20, 25, 0.85);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
}
.project-run-edit .project-run-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.2);
}
.project-run-edit-actions {
  display: flex;
  gap: 0.35rem;
}
.project-run-edit-actions .btn {
  flex: 1;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(15,20,25,0.2), transparent 120px);
}

/* Conversation (flex) + compact thought/work rail */
.chat-workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* First user prompt: compact bar pinned above the scrollable feed */
.first-prompt-pin {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.55rem 1.25rem 0;
  padding: 0.55rem 0.85rem;
  border: 1px solid rgba(61, 139, 253, 0.55);
  border-radius: 10px;
  background: linear-gradient(180deg, #243f66 0%, #1a2f4d 100%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 5;
  min-width: 0;
  max-width: calc(100% - 2.5rem);
}
.first-prompt-pin[hidden] {
  display: none !important;
}
.first-prompt-pin-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.first-prompt-pin-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8eb8f8;
  line-height: 1.2;
  font-weight: 650;
}
.first-prompt-pin-text {
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.first-prompt-pin:not(.is-expanded) .first-prompt-pin-text {
  cursor: pointer;
}
.first-prompt-pin.is-expanded .first-prompt-pin-text {
  white-space: pre-wrap;
  text-overflow: unset;
  max-height: min(40vh, 14rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  cursor: auto;
}
.first-prompt-pin-actions {
  flex: 0 0 auto;
  align-self: center;
}
.first-prompt-pin-toggle {
  flex: 0 0 auto;
  align-self: center;
  padding: 0.15rem 0.45rem !important;
  line-height: 1;
  color: var(--muted);
}
.first-prompt-pin.is-expanded .first-prompt-pin-toggle {
  transform: rotate(180deg);
}
/*
 * First-prompt text lives in the pin. Do not hide the whole source bubble:
 * images and other non-text details must stay visible under the pin.
 * Hide only the duplicated body; drop an empty text-only shell entirely.
 */
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt > .body,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt > .body {
  display: none;
}
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:not(:has(.msg-images)):not(:has(.msg-files)),
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:not(:has(.msg-images)):not(:has(.msg-files)) {
  display: none;
}
/* Compact image strip under the pin (no role chrome / data-window chrome). */
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images),
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images),
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files),
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) {
  align-self: flex-start;
  max-width: min(900px, 100%);
  padding: 0.45rem 0.55rem;
  background: transparent;
  border-style: dashed;
  border-color: rgba(61, 139, 253, 0.35);
}
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .role,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .role,
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .msg-head,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .msg-head,
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .data-window-actions,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-images) > .data-window-actions,
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .role,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .role,
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .msg-head,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .msg-head,
.first-prompt-pin:not([hidden]) ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .data-window-actions,
.first-prompt-pin.is-filled ~ .chat-scroll .msg.user.is-first-prompt:has(.msg-files) > .data-window-actions {
  display: none;
}

/* Only this region grows/scrolls; activity rail + prompt stay pinned */
.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 0 0 auto;
  padding: 1.25rem 1.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.msg {
  max-width: 900px;
  border-radius: 12px;
  padding: 0.75rem 0.95rem;
  border: 1px solid var(--border);
}
.msg.user { background: var(--user); align-self: flex-end; }
.msg.assistant, .msg.system, .msg.tool { background: var(--assistant); align-self: flex-start; }
.msg.system.turn-timing-msg {
  border-color: rgba(240, 180, 41, 0.45);
  background: rgba(240, 180, 41, 0.08);
  padding: 0.45rem 0.75rem;
}
.msg.system.turn-timing-msg .body a {
  margin-left: 0.35rem;
}
.msg.system.turn-tokens-msg {
  border-color: rgba(96, 165, 250, 0.45);
  background: rgba(96, 165, 250, 0.08);
  padding: 0.45rem 0.75rem;
}
.turn-log-detail {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font-size: 0.82rem;
}
.msg.system.host-tests-msg {
  border-color: rgba(72, 187, 120, 0.45);
  background: rgba(72, 187, 120, 0.08);
}
.msg.system.host-tests-msg .body {
  white-space: pre-wrap;
}
.msg.system.host-tests-msg.is-running {
  border-color: rgba(99, 179, 237, 0.45);
  background: rgba(99, 179, 237, 0.1);
}
.msg.system.host-tests-msg.is-fail {
  border-color: rgba(245, 101, 101, 0.45);
  background: rgba(245, 101, 101, 0.1);
}
.msg.system .git-auth-form {
  margin-top: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(245, 166, 35, 0.45);
  border-radius: 8px;
  background: rgba(245, 166, 35, 0.08);
  display: grid;
  gap: 0.45rem;
}
.msg.system .git-auth-form .git-auth-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
}
.msg.system .git-auth-form .git-auth-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.msg.system .git-auth-form label {
  display: grid;
  gap: 0.2rem;
  font-size: 0.78rem;
}
.msg.system .git-auth-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg, #12151c);
  color: inherit;
}
.msg.system .git-auth-form .git-auth-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}
.msg.system .git-auth-form .git-auth-status {
  margin: 0;
  font-size: 0.78rem;
}
.msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  min-height: 1.35rem;
}
.msg .role,
.msg-head .role {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0;
  min-width: 0;
}
.msg > .role {
  margin-bottom: 0.3rem;
}
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg .body.md-body {
  white-space: normal;
  line-height: 1.5;
}
.msg .body.md-body > :first-child { margin-top: 0; }
.msg .body.md-body > :last-child { margin-bottom: 0; }
.msg .body.md-body h1,
.msg .body.md-body h2,
.msg .body.md-body h3,
.msg .body.md-body h4,
.msg .body.md-body h5,
.msg .body.md-body h6 {
  margin: 0.85em 0 0.35em;
  line-height: 1.25;
  font-weight: 650;
  color: var(--text, #e7ecf3);
}
.msg .body.md-body h1 { font-size: 1.25rem; }
.msg .body.md-body h2 { font-size: 1.12rem; }
.msg .body.md-body h3 { font-size: 1.02rem; }
.msg .body.md-body p,
.msg .body.md-body ul,
.msg .body.md-body ol,
.msg .body.md-body blockquote,
.msg .body.md-body pre,
.msg .body.md-body .table-wrap {
  margin: 0.45em 0;
}
.msg .body.md-body ul,
.msg .body.md-body ol {
  padding-left: 1.35em;
}
.msg .body.md-body li { margin: 0.15em 0; }
.msg .body.md-body li > p { margin: 0.2em 0; }
.msg .body.md-body a {
  color: var(--accent, #3d8bfd);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg .body.md-body a:hover { filter: brightness(1.12); }
.msg .body.md-body strong { font-weight: 700; }
.msg .body.md-body em { font-style: italic; }
.msg .body.md-body code {
  font-family: "Cascadia Code", Consolas, ui-monospace, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border, #2f3b4f);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  word-break: break-word;
}
.msg .body.md-body pre {
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border, #2f3b4f);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  white-space: pre;
}
.msg .body.md-body pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.86rem;
  white-space: inherit;
}
.msg .body.md-body blockquote {
  margin-left: 0;
  padding: 0.1rem 0.75rem;
  border-left: 3px solid var(--accent, #3d8bfd);
  color: var(--muted, #9aa8bc);
}
.msg .body.md-body hr {
  border: 0;
  border-top: 1px solid var(--border, #2f3b4f);
  margin: 0.85rem 0;
}
.msg .body.md-body .table-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border, #2f3b4f);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.msg .body.md-body table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0;
  white-space: normal;
}
.msg .body.md-body th,
.msg .body.md-body td {
  border: 1px solid var(--border, #2f3b4f);
  padding: 0.4rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.msg .body.md-body th {
  background: rgba(61, 139, 253, 0.12);
  font-weight: 650;
  color: var(--text, #e7ecf3);
}
.msg .body.md-body tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}
.msg .body.md-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.msg.is-collapsed .body {
  max-height: calc(1.4em * 5);
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(to bottom, #000 55%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent 100%);
  cursor: pointer;
}
/* Expanded long message: scroll inside the bubble instead of growing the feed */
.msg.is-long:not(.is-collapsed) .body {
  max-height: min(50vh, 22rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  cursor: auto;
}
.msg.streaming { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(61,139,253,0.2); }

/* Shared chrome: collapse + open-in-tab on any data window */
.data-window-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
  margin-left: auto;
}
.data-window-actions .btn.ghost {
  line-height: 1;
}
.data-collapse-btn {
  min-width: 1.5rem;
  padding-left: 0.25rem !important;
  padding-right: 0.25rem !important;
}
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.15rem 0 0.45rem;
}
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.15rem 0 0.45rem;
}
.msg-file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
}
.msg-file-link:hover {
  border-color: var(--accent, #7aa2f7);
}
.md-body a.msg-agent-download {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  text-decoration: none;
  color: inherit;
}
.md-body a.msg-agent-download:hover {
  border-color: var(--accent, #7aa2f7);
}
.msg-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 16rem;
}
.msg-file-size {
  flex-shrink: 0;
}
.msg-image-link {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 220px;
  background: rgba(0, 0, 0, 0.25);
}
.msg-image {
  display: block;
  max-width: 220px;
  max-height: 180px;
  width: auto;
  height: auto;
  object-fit: contain;
  vertical-align: middle;
}
.empty-chat { padding: 2rem; text-align: center; }

.live-panel {
  flex: 0 0 auto;
  padding: 0 1.5rem 1rem;
}

/* Thought + work + terminal: fixed small previews under chat */
.activity-rail {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.55rem;
  padding: 0.45rem 1.25rem 0.55rem;
  border-top: 1px solid var(--border);
  background: rgba(12, 16, 22, 0.92);
  min-height: 0;
}
.activity-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(26, 35, 50, 0.72);
  padding: 0.35rem 0.5rem 0.4rem;
}
.activity-pane.active {
  border-color: rgba(61, 139, 253, 0.4);
}
.activity-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-height: 1.4rem;
}
.activity-pane.is-collapsed .activity-pane-preview {
  display: none;
}
.activity-pane.is-collapsed {
  padding-bottom: 0.3rem;
}
.activity-pane-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.activity-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.activity-dot.thought { background: #9b7bff; }
.activity-dot.work { background: var(--warn); }
.activity-dot.terminal { background: #3d8bfd; }
.activity-pane.active .activity-dot.thought {
  box-shadow: 0 0 0 3px rgba(155, 123, 255, 0.25);
}
.activity-pane.active .activity-dot.work {
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.25);
}
.activity-pane.active .activity-dot.terminal {
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.28);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
}
.btn.ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
}
.btn.ghost:disabled {
  opacity: 0.35;
}
/* Live terminal tab button pulse while shell is running */
.btn.ghost.terminal-open-btn.is-live,
#terminal-open-btn.is-live {
  color: #8ec8ff;
  border-color: rgba(61, 139, 253, 0.45);
  background: rgba(61, 139, 253, 0.12);
  box-shadow: 0 0 0 1px rgba(61, 139, 253, 0.15);
}
.btn.ghost.terminal-open-btn.is-live:hover:not(:disabled),
#terminal-open-btn.is-live:hover:not(:disabled) {
  color: #c5e0ff;
  background: rgba(61, 139, 253, 0.2);
}
.activity-pane-preview {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  /* ~3 lines */
  max-height: calc(1.35em * 3);
  overflow: hidden;
  min-height: calc(1.35em * 2);
}
#thought-preview {
  font-style: italic;
  color: #c4b5fd;
}
#work-preview {
  color: #f0c96a;
  font-style: normal;
}
#terminal-preview {
  color: #8ec8ff;
  font-style: normal;
  font-family: var(--mono);
}
.activity-pane-preview.is-empty {
  color: var(--muted) !important;
  font-style: normal !important;
  opacity: 0.7;
}

@media (max-width: 980px) {
  .activity-rail {
    grid-template-columns: 1fr 1fr;
  }
  #terminal-pane {
    grid-column: 1 / -1;
  }
}
@media (max-width: 700px) {
  .activity-rail {
    grid-template-columns: 1fr;
  }
  #terminal-pane {
    grid-column: auto;
  }
}

/* Interactive tool permission (ACP session/request_permission) */
/* flex-shrink:0 — иначе chat-workspace/activity-rail съедают панель, и
   body (детали / вопросы) схлопывается до 0 при min-height:0. */
.permission-panel {
  flex: 0 0 auto;
  min-height: auto;
  margin: 0 1.25rem 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(240, 180, 41, 0.55);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(240, 180, 41, 0.12), rgba(26, 35, 50, 0.95));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: 900px;
  max-height: min(40vh, 22rem);
  overflow: auto;
  overscroll-behavior: contain;
}
.permission-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.permission-head-actions {
  margin-left: auto;
}
.permission-panel.is-data-collapsed #permission-data-body,
.permission-panel.is-data-collapsed .permission-detail,
.permission-panel.is-data-collapsed .permission-raw {
  display: none;
}
.question-panel.is-data-collapsed #question-body {
  display: none;
}
.plan-panel.is-data-collapsed #plan-content,
.plan-panel.is-data-collapsed #plan-empty,
.plan-panel.is-data-collapsed .plan-feedback-label,
.plan-panel.is-data-collapsed .plan-feedback {
  display: none;
}
.permission-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(240, 180, 41, 0.25);
  color: var(--warn);
  border: 1px solid rgba(240, 180, 41, 0.4);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
}
.permission-detail {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
  word-break: break-word;
  margin-bottom: 0.5rem;
  white-space: pre-wrap;
}
.permission-raw {
  margin: 0 0 0.65rem;
  padding: 0.55rem 0.7rem;
  background: #0d1218;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  max-height: 10rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.permission-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.perm-btn.allow,
.perm-btn.allow_once {
  background: rgba(62, 207, 142, 0.18);
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--ok);
}
.perm-btn.allow-always,
.perm-btn.allow_always {
  background: rgba(62, 207, 142, 0.32);
  border-color: rgba(62, 207, 142, 0.6);
  color: #7dffb5;
  font-weight: 600;
}
.perm-btn.deny,
.perm-btn.reject,
.perm-btn.reject_once,
.perm-btn.reject_always {
  background: rgba(240, 113, 120, 0.15);
  border-color: rgba(240, 113, 120, 0.45);
  color: var(--danger);
}

/* AskUserQuestion — same interactive style as TUI choice prompts */
.question-panel {
  flex: 0 0 auto;
  min-height: auto;
  margin: 0 1.25rem 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(61, 139, 253, 0.55);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(61, 139, 253, 0.12), rgba(26, 35, 50, 0.95));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: 900px;
  max-height: min(50vh, 28rem);
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.question-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(61, 139, 253, 0.25);
  color: var(--accent);
  border: 1px solid rgba(61, 139, 253, 0.4);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
}
.question-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin: 0.55rem 0 0.75rem;
  flex: 1 1 auto;
  /* Keep at least one question block visible — never collapse to 0 */
  min-height: 5.5rem;
  overflow: auto;
  color: var(--text);
}
.question-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: rgba(13, 18, 24, 0.55);
}
.question-block .q-text {
  font-weight: 600;
  margin-bottom: 0.45rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.question-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.question-option {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.question-option:hover {
  background: rgba(61, 139, 253, 0.08);
  border-color: var(--border);
}
.question-option.selected {
  background: rgba(61, 139, 253, 0.16);
  border-color: rgba(61, 139, 253, 0.45);
}
.question-option input { margin-top: 0.2rem; flex-shrink: 0; }
.question-option .opt-label { font-weight: 500; }
.question-option .opt-desc {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.1rem;
}
.question-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.question-footer #question-cancel {
  margin-right: auto;
}
.question-other-text {
  display: block;
}

/* Plan approval (exit_plan_mode) — like TUI a / s / q */
.plan-panel {
  flex: 0 0 auto;
  min-height: auto;
  margin: 0 1.25rem 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(167, 139, 250, 0.55);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(167, 139, 250, 0.12), rgba(26, 35, 50, 0.95));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: 900px;
  max-height: min(55vh, 32rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.plan-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(167, 139, 250, 0.25);
  color: #c4b5fd;
  border: 1px solid rgba(167, 139, 250, 0.45);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
}
.plan-empty {
  margin: 0.2rem 0 0;
}
.plan-content {
  flex: 1 1 auto;
  min-height: 6rem;
  max-height: min(38vh, 22rem);
  overflow: auto;
  margin: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(13, 18, 24, 0.7);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.plan-feedback-label {
  margin-top: 0.15rem;
}
.plan-feedback {
  width: 100%;
  resize: vertical;
  min-height: 2.4rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(13, 18, 24, 0.65);
  color: var(--text);
  font: inherit;
}
.plan-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.prompt-queue {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 12rem;
  overflow: auto;
  margin: 0.35rem 1rem 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.72);
}
.prompt-queue[hidden] {
  display: none !important;
}
.prompt-queue-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #8aa);
}
.prompt-queue-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.prompt-queue-text {
  flex: 1 1 12rem;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 3.4rem;
  overflow: hidden;
  line-height: 1.35;
}
.prompt-queue-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
  margin-left: auto;
}
.prompt-bar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.55rem 1rem 0.4rem;
  border-top: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.92);
}
.prompt-bar.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(61, 139, 253, 0.08);
}
.prompt-compose {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.prompt-bar textarea {
  min-height: 2.6rem;
  max-height: 10rem;
  resize: vertical;
  width: 100%;
}
.prompt-compose-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.voice-btn.is-listening {
  color: #fff;
  background: rgba(220, 70, 70, 0.85);
  border-color: rgba(255, 120, 120, 0.55);
  animation: voice-pulse 1.2s ease-in-out infinite;
}
.voice-btn:disabled,
.tts-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.tts-btn.is-enabled {
  color: #e8f4ff;
  background: rgba(70, 130, 220, 0.35);
  border-color: rgba(110, 182, 255, 0.55);
}
.tts-btn.is-speaking {
  color: #fff;
  background: rgba(60, 140, 90, 0.85);
  border-color: rgba(100, 200, 140, 0.55);
  animation: tts-pulse 1.2s ease-in-out infinite;
}
.msg-speak-btn {
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.75rem;
  line-height: 1.2;
  vertical-align: middle;
  opacity: 0.7;
}
.msg-speak-btn:hover,
.msg-speak-btn:focus-visible {
  opacity: 1;
}
.msg-speak-btn.is-speaking {
  opacity: 1;
  color: #9fd4a3;
}
.voice-status {
  color: var(--accent, #6eb6ff);
}
.voice-status.is-error {
  color: #f0a0a0;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 70, 70, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(220, 70, 70, 0); }
}
@keyframes tts-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(60, 140, 90, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(60, 140, 90, 0); }
}
.prompt-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-self: stretch;
}
.prompt-actions .btn {
  min-width: 7.2rem;
  flex: 1;
}

/* Pending image chips before send */
.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.image-previews.hidden { display: none; }
.image-chip {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}
.image-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.image-chip-remove:hover {
  background: rgba(240, 113, 120, 0.95);
}
.image-chip-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.1rem 0.2rem;
  font-size: 0.58rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pending file chips before send */
.file-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.file-previews.hidden { display: none; }
.file-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 14rem;
  padding: 0.28rem 1.6rem 0.28rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28);
  font-size: 0.78rem;
}
.file-chip-icon { flex-shrink: 0; }
.file-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip-remove {
  position: absolute;
  top: 50%;
  right: 0.2rem;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.file-chip-remove:hover {
  background: rgba(240, 113, 120, 0.95);
}

/* Stuck / hang: compact strip — must not bury chat + activity rail */
.stuck-panel {
  flex-shrink: 0;
  margin: 0 1.25rem 0.4rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid rgba(240, 113, 120, 0.45);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(240, 113, 120, 0.12), rgba(20, 28, 40, 0.95));
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: min(28vh, 12rem);
  overflow: hidden;
}
.stuck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.stuck-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  min-width: 0;
}
.stuck-head strong {
  font-size: 0.88rem;
}
.stuck-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #ffb4b8;
  background: rgba(240, 113, 120, 0.2);
  border: 1px solid rgba(240, 113, 120, 0.4);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
}
.stuck-details {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.2rem;
  border-top: 1px solid rgba(240, 113, 120, 0.25);
}
.stuck-details.hidden {
  display: none;
}
.stuck-diag {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.4;
}
.stuck-diag li { margin: 0.1rem 0; }
.stuck-explain {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  line-height: 1.35;
  font-size: 0.82rem;
}
.stuck-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Session list: status badges for closed/running/waiting chats */
.session-list > li:not(.session-item).closed > a {
  opacity: 0.7;
  font-style: italic;
  color: var(--muted);
}
.session-list > li:not(.session-item).running > a {
  color: var(--warn);
  font-weight: 600;
}
.session-list > li:not(.session-item).waiting > a {
  color: #ff6b9d;
  font-weight: 600;
  animation: pulse-waiting 1.5s ease-in-out infinite;
}
@keyframes pulse-waiting {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

@media (max-width: 700px) {
  .statusbar-row-top {
    flex-wrap: wrap;
    gap: 0.15rem 0.4rem;
  }
  .statusbar-row-bottom,
  .statusbar-controls {
    justify-content: flex-start;
  }
  /* Keep bottom controls on one scrollable row even on narrow screens */
  .statusbar-row-bottom {
    flex-wrap: nowrap;
  }
  .chat-statusbar .model-picker select {
    max-width: 7.5rem;
  }
}

#ws-status.ok { color: var(--ok); }
#ws-status.bad { color: var(--danger); }
#ws-status.busy { color: var(--warn); }

/* Chat mobile chrome (hidden on desktop; shown in mobile block) */
.chat-mobile-bar,
.sidebar-mobile-head {
  display: none;
}

/* Pre-JS mobile list home (set on <html> from chat.html inline script) */
@media (max-width: 900px) {
  html.mobile-list-pending body.page-chat .chat-main {
    display: none !important;
  }
  html.mobile-list-pending body.page-chat .chat-layout > .sidebar {
    position: relative;
    transform: none !important;
    width: 100%;
    max-width: none;
    flex: 1 1 auto;
    height: auto;
    box-shadow: none;
    border-right: none;
  }
}

/* ── Planned Tasks ─────────────────────────────────────────── */

.card.plan-form-card {
  width: 100%;
  max-width: none;
  margin: 0;
}
.plan-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem 1rem;
  align-items: start;
}
.plan-form-row > label {
  min-width: 0;
}
.plan-form-row > label.plan-form-checkbox {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 1.55rem;
  font-weight: 500;
}
.plan-form-row > label.plan-form-checkbox input {
  width: auto;
  margin: 0;
}
.plan-form-orchestration {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.plan-form-voice-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

/* Project hub + workspace */
.project-workspace-head {
  align-items: flex-start;
}
.project-workspace-title {
  min-width: 0;
  flex: 1 1 16rem;
}
.project-workspace-crumb {
  margin: 0 0 0.2rem;
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.project-workspace-path,
.projects-hub-path {
  margin: 0.25rem 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.project-workspace-section-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

/* Project workspace: segmented tab control */
.project-workspace-tabs {
  display: inline-flex;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.28rem;
  margin: 0 0 1.35rem;
  max-width: 100%;
  flex-wrap: wrap;
  border-radius: 14px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(36, 48, 68, 0.55), rgba(26, 35, 50, 0.92));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.18);
}
.project-workspace-tabs .ws-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.55rem 1.05rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition:
    color 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.12s ease;
}
.project-workspace-tabs .ws-tab:hover {
  color: var(--text);
  background: rgba(99, 179, 237, 0.08);
  border-color: rgba(99, 179, 237, 0.12);
}
.project-workspace-tabs .ws-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.45);
}
.project-workspace-tabs .ws-tab.active {
  color: #e8f2ff;
  background:
    linear-gradient(180deg, rgba(61, 139, 253, 0.34), rgba(47, 111, 237, 0.18));
  border-color: rgba(61, 139, 253, 0.42);
  box-shadow:
    0 0 0 1px rgba(61, 139, 253, 0.12),
    0 6px 16px rgba(15, 40, 80, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.project-workspace-tabs .ws-tab.active:hover {
  color: #fff;
  background:
    linear-gradient(180deg, rgba(61, 139, 253, 0.4), rgba(47, 111, 237, 0.22));
}
.project-workspace-tabs .ws-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 7px;
  color: inherit;
  opacity: 0.85;
  background: rgba(255, 255, 255, 0.04);
}
.project-workspace-tabs .ws-tab.active .ws-tab-icon {
  opacity: 1;
  color: #9ec9ff;
  background: rgba(61, 139, 253, 0.18);
}
.project-workspace-tabs .ws-tab-icon svg {
  display: block;
}
.project-workspace-tabs .ws-tab-text {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}
.project-workspace-tabs .ws-tab-label {
  min-width: 0;
}
.project-workspace-tabs .ws-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.2rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.project-workspace-tabs .ws-tab.active .ws-tab-count {
  color: #d7ebff;
  background: rgba(61, 139, 253, 0.22);
  border-color: rgba(61, 139, 253, 0.28);
}
@media (max-width: 560px) {
  .project-workspace-tabs {
    display: flex;
    width: 100%;
  }
  .project-workspace-tabs .ws-tab {
    flex: 1 1 auto;
    justify-content: center;
    padding: 0.6rem 0.7rem;
  }
  .project-workspace-tabs .ws-tab-label {
    font-size: 0.86rem;
  }
}

.project-workspace-section.tab-content {
  display: none;
}
.project-workspace-section.tab-content.active {
  display: block;
  animation: wsTabFade 0.18s ease;
}
@keyframes wsTabFade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}
.project-tree-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.project-tree-toolbar-main {
  min-width: 0;
  flex: 1 1 16rem;
}
.project-tree-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}
.project-tree-refresh-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}
.project-tree-model-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 10rem;
}
.project-tree-model-select {
  min-width: 12rem;
}
.project-tree-status {
  margin: 0 0 0.5rem;
  min-height: 1.2em;
}
.project-tree-status-error {
  color: var(--danger, #f87171);
}
/* Project tree: classic explorer-style tree view + detail pane */
.project-tree-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 1.35fr) minmax(14rem, 1fr);
  gap: 0.75rem;
  align-items: start;
}
@media (max-width: 900px) {
  .project-tree-layout {
    grid-template-columns: 1fr;
  }
}
.project-tree-root {
  padding: 0.5rem 0.35rem 0.65rem;
  overflow: auto;
  max-height: min(70vh, 42rem);
  min-height: 12rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}
.project-tree-detail {
  padding: 0.85rem 1rem;
  min-height: 12rem;
  max-height: min(70vh, 42rem);
  overflow: auto;
}
.project-tree-detail[hidden] {
  display: none !important;
}
.project-tree-detail-empty {
  padding: 1rem 0.25rem;
}
.project-tree-detail-head {
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.project-tree-detail-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}
.pt-tree {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: max-content;
  width: 100%;
}
.pt-row {
  display: block;
  outline: none;
}
.pt-row-main {
  display: flex;
  align-items: stretch;
  min-height: 1.85rem;
  cursor: pointer;
  border-radius: 4px;
  padding-right: 0.4rem;
  user-select: none;
}
.pt-row-main:hover {
  background: var(--panel-2, rgba(255, 255, 255, 0.05));
}
.pt-row.is-selected > .pt-row-main {
  background: rgba(99, 179, 237, 0.14);
  box-shadow: inset 0 0 0 1px rgba(99, 179, 237, 0.35);
}
.pt-row:focus-visible > .pt-row-main {
  box-shadow: inset 0 0 0 1px var(--accent, #63b3ed);
}
.pt-guides {
  display: flex;
  flex: 0 0 auto;
  align-items: stretch;
}
.pt-guide {
  position: relative;
  width: 1.1rem;
  flex: 0 0 1.1rem;
}
.pt-guide::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--muted, #9aa8bc);
  opacity: 0.55;
  transform: translateX(-50%);
}
.pt-guide-empty::before {
  display: none;
}
.pt-elbow {
  position: relative;
  width: 1.1rem;
  flex: 0 0 1.1rem;
}
.pt-elbow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 50%;
  width: 1.5px;
  background: var(--muted, #9aa8bc);
  opacity: 0.55;
  transform: translateX(-50%);
}
.pt-elbow::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  right: 0.15rem;
  height: 1.5px;
  background: var(--muted, #9aa8bc);
  opacity: 0.55;
  transform: translateY(-50%);
}
.pt-elbow:not(.pt-elbow-last)::before {
  bottom: 0;
}
/* Placeholder child when only root exists — shows the tree shape */
.pt-row.is-placeholder {
  pointer-events: none;
  opacity: 0.72;
}
.pt-row.is-placeholder .pt-row-main {
  cursor: default;
}
.pt-row.is-placeholder .pt-name {
  font-weight: 400;
  font-style: italic;
  color: var(--muted, #9aa8bc);
}
.pt-twisty {
  flex: 0 0 1.25rem;
  width: 1.25rem;
  height: 1.85rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted, #94a3b8);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.85rem;
  text-align: center;
  cursor: pointer;
  border-radius: 3px;
}
.pt-twisty:hover {
  color: var(--text, #e2e8f0);
  background: rgba(255, 255, 255, 0.06);
}
.pt-twisty-leaf {
  cursor: default;
  visibility: hidden;
}
.pt-icon {
  flex: 0 0 1.1rem;
  width: 1.1rem;
  line-height: 1.85rem;
  text-align: center;
  opacity: 0.9;
}
.pt-row.kind-project .pt-icon { color: var(--accent, #63b3ed); }
.pt-row.kind-program .pt-icon { color: #a78bfa; }
.pt-row.kind-subprogram .pt-icon { color: #34d399; }
.pt-row.kind-feature .pt-icon { color: #fbbf24; }
.pt-kind {
  flex: 0 0 auto;
  align-self: center;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  padding: 0.05rem 0.3rem;
  border-radius: 999px;
  margin-right: 0.35rem;
  color: var(--muted, #94a3b8);
  background: rgba(148, 163, 184, 0.12);
  font-family: system-ui, -apple-system, sans-serif;
}
.pt-row.kind-project .pt-kind {
  color: var(--accent, #63b3ed);
  background: rgba(99, 179, 237, 0.12);
}
.pt-row.kind-program .pt-kind {
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.12);
}
.pt-row.kind-subprogram .pt-kind {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
}
.pt-row.kind-feature .pt-kind {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
}
.kind-label-project { color: var(--accent, #63b3ed); }
.kind-label-program { color: #a78bfa; }
.kind-label-subprogram { color: #34d399; }
.kind-label-feature { color: #fbbf24; }
.pt-name {
  align-self: center;
  font-weight: 600;
  color: var(--text, #e2e8f0);
  white-space: nowrap;
}
.pt-meta {
  align-self: center;
  margin-left: 0.45rem;
  font-size: 0.75rem;
  font-family: system-ui, -apple-system, sans-serif;
}
.pt-path {
  align-self: center;
  margin-left: 0.55rem;
  font-size: 0.75rem;
  opacity: 0.85;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-tree-desc {
  margin: 0.2rem 0 0.35rem;
}
.pt-feature-desc {
  margin: 0 0 0.4rem;
  padding: 0.05rem 0.4rem 0.25rem;
  /* guides (depth+1) + twisty + icon + kind ≈ align under name */
  padding-inline-start: calc(
    (var(--pt-depth, 0) + 1) * 1.1rem + 1.35rem + 1.1rem + 4.2rem
  );
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 48rem;
  cursor: pointer;
  opacity: 0.9;
}
/* RTL: project tree explorer (Hebrew) */
html[dir="rtl"] .project-tree-toolbar-actions {
  justify-content: flex-start;
}
html[dir="rtl"] .pt-row-main {
  padding-right: 0;
  padding-left: 0.4rem;
}
html[dir="rtl"] .pt-elbow::after {
  left: 0.15rem;
  right: 50%;
  width: auto;
}
html[dir="rtl"] .pt-kind {
  margin-right: 0;
  margin-left: 0.35rem;
}
html[dir="rtl"] .pt-meta,
html[dir="rtl"] .pt-path {
  margin-left: 0;
  margin-right: 0.45rem;
}
html[dir="rtl"] .project-tree-detail-head,
html[dir="rtl"] .project-tree-desc-block,
html[dir="rtl"] .project-tree-rules-block,
html[dir="rtl"] .project-tree-add-child {
  text-align: right;
}
html[dir="rtl"] .project-tree-desc-actions,
html[dir="rtl"] .project-tree-rule-actions,
html[dir="rtl"] .project-tree-add-child-row {
  flex-direction: row-reverse;
}

.pt-row.is-selected > .pt-feature-desc {
  color: var(--text, #e2e8f0);
  opacity: 1;
}
.project-tree-desc-block {
  margin: 0.25rem 0 0.55rem;
  padding: 0.45rem 0.6rem 0.55rem;
  border-radius: var(--radius);
  background: var(--panel-2, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border, rgba(148, 163, 184, 0.2));
}
.project-tree-desc-block h4 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 650;
}
.project-tree-desc-input {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text, #e2e8f0);
  background: var(--panel, #0f172a);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
  box-sizing: border-box;
}
.project-tree-name-input {
  width: 100%;
  margin: 0.35rem 0 0.2rem;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--text, #e2e8f0);
  background: var(--panel, #0f172a);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
  box-sizing: border-box;
}
.project-tree-add-child {
  margin: 0.35rem 0 0.55rem;
  padding: 0.45rem 0.6rem 0.55rem;
  border-radius: var(--radius);
  background: var(--panel-2, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border, rgba(148, 163, 184, 0.2));
}
.project-tree-add-child h4 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 650;
}
.project-tree-add-child-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.project-tree-child-name {
  flex: 1 1 8rem;
  min-width: 6rem;
  font: inherit;
  color: var(--text, #e2e8f0);
  background: var(--panel, #0f172a);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
}
.project-tree-desc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.4rem;
}
.project-tree-rules-block {
  margin: 0.25rem 0 0.45rem;
  padding: 0.45rem 0.6rem 0.55rem;
  border-radius: var(--radius);
  background: var(--panel-2, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border, rgba(148, 163, 184, 0.2));
}
.project-tree-rules-block h4 {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  font-weight: 650;
}
.project-tree-rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.project-tree-rule {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel, #0f172a);
}
.project-tree-rule.status-proposed {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.06);
}
.project-tree-rule-badge {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--muted, #94a3b8);
  margin-bottom: 0.2rem;
}
.project-tree-rule-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}
.project-tree-rule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.project-tree-add-rule {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: flex-start;
  margin-top: 0.5rem;
}
.project-tree-rule-input {
  flex: 1 1 14rem;
  min-height: 2.4rem;
  resize: vertical;
}
.projects-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.projects-hub-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.projects-hub-card:hover {
  border-color: rgba(99, 179, 237, 0.45);
  background: rgba(99, 179, 237, 0.06);
  text-decoration: none;
  color: inherit;
  transform: translateY(-1px);
}
.projects-hub-name {
  margin: 0;
  font-size: 1.1rem;
}
.projects-hub-open {
  margin-top: auto;
  color: var(--accent);
  font-weight: 600;
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1rem;
}
.plan-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.plan-card.plan-inactive {
  opacity: 0.6;
}
.plan-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.plan-card-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.plan-title {
  font-size: 1.05rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plan-badges {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.plan-trigger-badge,
.plan-status-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  border: 1px solid;
  white-space: nowrap;
}
.plan-trigger-badge {
  background: rgba(61, 139, 253, 0.15);
  border-color: rgba(61, 139, 253, 0.35);
  color: var(--accent);
}
.trigger-scheduled {
  background: rgba(167, 139, 250, 0.15);
  border-color: rgba(167, 139, 250, 0.35);
  color: #c4b5fd;
}
.trigger-recurring {
  background: rgba(240, 180, 41, 0.15);
  border-color: rgba(240, 180, 41, 0.35);
  color: var(--warn);
}
.trigger-webhook {
  background: rgba(62, 207, 142, 0.15);
  border-color: rgba(62, 207, 142, 0.35);
  color: var(--ok);
}
.status-draft {
  background: rgba(154, 168, 188, 0.12);
  border-color: rgba(154, 168, 188, 0.3);
  color: var(--muted);
}
.status-ready {
  background: rgba(62, 207, 142, 0.12);
  border-color: rgba(62, 207, 142, 0.3);
  color: var(--ok);
}
.status-running {
  background: rgba(240, 180, 41, 0.15);
  border-color: rgba(240, 180, 41, 0.35);
  color: var(--warn);
}
.status-completed {
  background: rgba(62, 207, 142, 0.18);
  border-color: rgba(62, 207, 142, 0.4);
  color: var(--ok);
}
.status-failed {
  background: rgba(240, 113, 120, 0.15);
  border-color: rgba(240, 113, 120, 0.4);
  color: var(--danger);
}
.status-paused {
  background: rgba(154, 168, 188, 0.15);
  border-color: rgba(154, 168, 188, 0.35);
  color: var(--muted);
}
.error-kind {
  background: rgba(240, 113, 120, 0.12);
  border-color: rgba(240, 113, 120, 0.35);
  color: var(--danger);
}
.error-kind-server {
  background: rgba(240, 113, 120, 0.18);
  border-color: rgba(240, 113, 120, 0.45);
}
.error-kind-terminal {
  background: rgba(240, 180, 41, 0.15);
  border-color: rgba(240, 180, 41, 0.4);
  color: var(--warn);
}
.error-kind-ai {
  background: rgba(167, 139, 250, 0.15);
  border-color: rgba(167, 139, 250, 0.4);
  color: #c4b5fd;
}
.plan-card-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.plan-description {
  margin: 0;
  line-height: 1.35;
}
.plan-details {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.plan-detail-row {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}
.plan-detail-row code {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-all;
}
.plan-webhook-url {
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
}
.plan-prompt-preview {
  background: rgba(13, 18, 24, 0.55);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}
.plan-prompt-text {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 4.8em;
  overflow: hidden;
  color: var(--muted);
}
.plan-run-info {
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.plan-result-details {
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
}
.plan-result-details summary {
  cursor: pointer;
  user-select: none;
}
.plan-result-text {
  margin: 0.35rem 0 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 8em;
  overflow: auto;
  background: rgba(13, 18, 24, 0.4);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
}
.plan-trigger-fields {
  margin-top: 0.25rem;
}
.plan-trigger-fields[hidden] {
  display: none;
}
.plan-webhook-info {
  padding: 0.5rem 0.65rem;
  background: rgba(13, 18, 24, 0.55);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.plan-webhook-info code {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-all;
  display: block;
  margin-top: 0.25rem;
}

@media (max-width: 500px) {
  .plans-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Agent profiles / chains / bus ──────────────────────────────── */

.page-head-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.agent-section h2 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}
.chain-steps-preview {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.chain-steps-preview li {
  line-height: 1.35;
}
.chain-step-card {
  margin-bottom: 0.75rem;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.chain-step-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.bus-layout {
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1fr;
  gap: 1rem;
  align-items: start;
}
.bus-channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.bus-channel-list a {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  border: 1px solid transparent;
}
.bus-channel-list li.active a,
.bus-channel-list a:hover {
  background: rgba(61, 139, 253, 0.1);
  border-color: rgba(61, 139, 253, 0.25);
  text-decoration: none;
}
.bus-msg-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: calc(100vh - 220px);
  overflow: auto;
}
.bus-msg {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  background: rgba(13, 18, 24, 0.4);
}
.bus-msg-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.35rem;
}
.bus-msg-body {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16em;
  overflow: auto;
}
.bus-messages-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.bus-view-toggle {
  display: inline-flex;
  gap: 0.35rem;
}
.bus-thread-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(100vh - 220px);
  overflow: auto;
}
.bus-thread {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  background: rgba(13, 18, 24, 0.35);
}
.bus-thread-head {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.bus-thread-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.bus-run-id {
  font-size: 0.78rem;
}
.bus-thread-speakers {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
}
.bus-speaker-chip {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(61, 139, 253, 0.12);
  border: 1px solid rgba(61, 139, 253, 0.25);
  color: var(--accent);
  font-size: 0.75rem;
}
.bus-run-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.bus-stat-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.28);
  color: var(--muted, #94a3b8);
  white-space: nowrap;
}
.bus-stat-chip.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.bus-stat-chip.danger {
  background: rgba(240, 113, 120, 0.15);
  border-color: rgba(240, 113, 120, 0.4);
  color: var(--danger);
}
.bus-bubble.protocol-fail,
.agent-thread-bubble.protocol-fail {
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.12);
}
.bus-thread-msgs {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.bus-bubble {
  max-width: min(92%, 42rem);
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  background: rgba(20, 28, 36, 0.75);
}
.bus-bubble.from-user {
  align-self: flex-end;
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.28);
}
.bus-bubble.from-agent {
  align-self: flex-start;
}
.bus-bubble-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.25rem;
}
.bus-bubble-who {
  color: var(--text);
}
.bus-bubble-body {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 18em;
  overflow: auto;
  line-height: 1.4;
}
.status-result {
  background: rgba(62, 207, 142, 0.12);
  border-color: rgba(62, 207, 142, 0.3);
  color: var(--ok);
}
.status-handoff {
  background: rgba(61, 139, 253, 0.12);
  border-color: rgba(61, 139, 253, 0.3);
  color: var(--accent);
}
.status-user {
  background: rgba(167, 139, 250, 0.12);
  border-color: rgba(167, 139, 250, 0.3);
  color: #c4b5fd;
}
.status-error {
  background: rgba(240, 113, 120, 0.15);
  border-color: rgba(240, 113, 120, 0.4);
  color: var(--danger);
}
@media (max-width: 720px) {
  .bus-layout {
    grid-template-columns: 1fr;
  }
}

/* ── Agent thread panel (chat) ──────────────────────────────────── */
.agent-thread-btn {
  position: relative;
  white-space: nowrap;
}
.agent-thread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  margin-left: 0.25rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--accent);
  color: #0b1220;
  line-height: 1;
}
.agent-thread-badge.hidden {
  display: none;
}
.agent-thread-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}
.agent-thread-panel.hidden {
  display: none;
}
.agent-thread-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.agent-thread-shell {
  position: relative;
  z-index: 1;
  width: min(28rem, 100vw);
  max-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel, #121820);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
}
.agent-thread-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.agent-thread-title {
  margin: 0;
  font-size: 1.05rem;
}
.agent-thread-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.agent-thread-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.85rem 1rem 1.25rem;
}
.agent-thread-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.agent-thread-run {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.55rem 0.65rem 0.7rem;
  background: rgba(13, 18, 24, 0.45);
}
.agent-thread-run-head {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.55rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.agent-thread-run-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.agent-thread-msgs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.agent-thread-bubble {
  max-width: 95%;
  border-radius: 12px;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  background: rgba(20, 28, 36, 0.8);
}
.agent-thread-bubble.from-user {
  align-self: flex-end;
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.28);
}
.agent-thread-bubble.from-agent {
  align-self: flex-start;
}
.agent-thread-bubble-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.2rem;
  font-size: 0.75rem;
}
.agent-thread-bubble-body {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 14em;
  overflow: auto;
  line-height: 1.4;
}
.agent-thread-bubble.role-error {
  border-color: rgba(240, 113, 120, 0.4);
}
.agent-thread-bubble.role-handoff {
  border-color: rgba(61, 139, 253, 0.35);
}

/* ── Silent mode desk ───────────────────────────────────────────── */
.silent-hidden[hidden] {
  display: none !important;
}
.silent-desk {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
  gap: 0.75rem;
  transition: box-shadow 0.2s ease, background 0.2s ease;
}
.silent-desk.needs-you {
  background: radial-gradient(
    600px 280px at 50% 40%,
    rgba(61, 139, 253, 0.12),
    transparent 70%
  );
}
.silent-desk-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}
.silent-desk-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  max-width: 28rem;
}
.silent-desk-lead {
  margin: 0;
  max-width: 32rem;
  line-height: 1.5;
}
.silent-desk-state {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.85);
  font-weight: 600;
}
.silent-desk-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}
.silent-desk-dot[data-phase="working"],
.silent-desk-dot[data-phase="stuck"] {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.25);
  animation: silent-pulse 1.4s ease-in-out infinite;
}
.silent-desk-dot[data-phase="waiting"] {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.35);
  animation: silent-pulse 1.1s ease-in-out infinite;
}
.silent-desk-dot[data-phase="error"] {
  background: var(--danger);
}
.silent-desk-dot[data-phase="done"] {
  background: var(--ok);
}
.silent-desk-hint {
  margin: 0.35rem 0 0;
  max-width: 28rem;
}
@keyframes silent-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* Sidebar: waiting for user */
.session-item.session-waiting .session-status-dot {
  background: var(--accent) !important;
}

/* Sidebar: error / blocker wins over waiting/running CSS */
.session-item.session-error .session-status-dot {
  background: var(--danger) !important;
}

/* Attention modal root — normal chat: transparent layout wrapper */
body:not(.page-silent) .attention-modal-root,
body:not(.page-silent) .attention-modal-root.hidden {
  display: contents !important;
}
body:not(.page-silent) .attention-modal-backdrop {
  display: none !important;
}
body:not(.page-silent) .attention-modal-shell {
  display: contents;
}
body:not(.page-silent) .attention-modal-queue {
  display: none !important;
}

/* Silent mode: true centered modal, one at a time */
body.page-silent .attention-modal-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  pointer-events: none;
}
body.page-silent .attention-modal-root.hidden {
  display: none;
}
body.page-silent .attention-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}
body.page-silent .attention-modal-shell {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(88vh, 40rem);
  overflow: auto;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
body.page-silent .attention-modal-shell .permission-panel,
body.page-silent .attention-modal-shell .question-panel,
body.page-silent .attention-modal-shell .plan-panel {
  margin: 0;
  max-width: none;
  max-height: none;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}
body.page-silent .attention-modal-queue {
  text-align: center;
  padding: 0.25rem 0.5rem;
}
body.page-silent .chat-main {
  position: relative;
}
body.page-silent .prompt-bar {
  /* Keep composer available to launch/continue work */
  z-index: 5;
}

/* ── Лимиты моделей: global button + modal ─────────────────────────── */
.topbar-link-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  line-height: inherit;
}

.limits-modal-root {
  position: fixed;
  inset: 0;
  z-index: 11000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.limits-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 18, 0.62);
  backdrop-filter: blur(2px);
}
.limits-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.limits-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.limits-modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.limits-modal-head-actions {
  display: flex;
  gap: 0.4rem;
}
.limits-modal-body {
  padding: 1rem 1.1rem 1.2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.limits-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 0.95rem;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.limits-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.limits-card-name {
  font-weight: 600;
  font-size: 0.98rem;
}
.limits-card-note {
  margin: 0;
}
.limits-api-status {
  margin: 0;
  font-size: 0.92rem;
}
.limits-api-status.ok {
  color: var(--ok, #3ecf8e);
}
.limits-api-status.bad {
  color: var(--danger);
}
.limits-api-link {
  color: var(--accent);
  text-decoration: none;
}
.limits-api-link:hover {
  text-decoration: underline;
}

.limits-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.limits-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.limits-row-pct {
  color: var(--muted);
}
.limits-bar-track {
  height: 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.limits-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.limits-bar-fill.warn { background: var(--warn); }
.limits-bar-fill.danger { background: var(--danger); }
.limits-row-reset {
  margin: 0;
}

/* ── Agents help modal ───────────────────────────────────────────── */
.help-modal-root {
  position: fixed;
  inset: 0;
  z-index: 11000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.help-modal-root.hidden {
  display: none;
}
.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 18, 0.62);
  backdrop-filter: blur(2px);
}
.help-modal {
  position: relative;
  width: min(640px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.help-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.help-modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.help-modal-body {
  padding: 1rem 1.15rem 1.35rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  line-height: 1.5;
  font-size: 0.95rem;
}
.help-intro {
  margin: 0;
  color: var(--muted);
}
.help-section {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.help-section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.help-section p {
  margin: 0;
}
.help-bullets {
  margin: 0.15rem 0 0;
  padding-inline-start: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.help-code {
  margin: 0.25rem 0 0;
  padding: 0.65rem 0.8rem;
  background: var(--panel-2, rgba(0, 0, 0, 0.25));
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ===================================================================
   Mobile / tablet shell (phones & tablets ? 900px)
   Desktop layout unchanged above this breakpoint.
   =================================================================== */

@media (max-width: 900px) {
  /* -- Topbar: hamburger + slide-in drawer ----------------------- */
  .nav-toggle {
    display: inline-flex;
  }
  .topbar {
    padding: 0.5rem 0.75rem;
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    gap: 0.5rem;
    z-index: 40;
    /* backdrop-filter creates a containing block for position:fixed
       descendants and clips the nav drawer to the topbar strip. */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(15, 20, 25, 0.98);
    overflow: visible;
  }
  .site-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(20rem, 88vw);
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 1rem;
    padding: 4.25rem 1rem 1.25rem;
    padding-top: max(4.25rem, calc(env(safe-area-inset-top, 0px) + 3.5rem));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    background: rgba(15, 22, 34, 0.98);
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
    transform: translateX(110%);
    transition: transform 0.22s ease, visibility 0.22s ease;
    z-index: 60;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: none;
    min-width: 0;
    visibility: hidden;
    pointer-events: none;
  }
  body.nav-open .site-nav-drawer {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }
  html[dir="rtl"] .site-nav-drawer {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid var(--border);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.45);
    transform: translateX(-110%);
    padding-right: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
  }
  html[dir="rtl"] body.nav-open .site-nav-drawer {
    transform: translateX(0);
  }
  .topbar-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    width: 100%;
  }
  .topbar-nav .topbar-link {
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
    border-radius: 10px;
    min-height: 2.75rem;
  }
  .nav-dropdown {
    width: 100%;
    display: block;
  }
  .nav-dropdown-trigger {
    display: flex;
    width: 100%;
    text-align: start;
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
    border-radius: 10px;
    min-height: 2.75rem;
    justify-content: space-between;
  }
  /* Touch: no hover — only .is-open (JS toggle on trigger click) */
  .nav-dropdown:hover > .nav-dropdown-menu,
  .nav-dropdown:focus-within > .nav-dropdown-menu {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: none;
  }
  .nav-dropdown.is-open > .nav-dropdown-menu {
    position: static;
    max-width: none;
    max-height: none;
    box-shadow: none;
    border: 1px solid var(--border);
    margin: 0.15rem 0 0.35rem;
    background: rgba(99, 179, 237, 0.06);
    z-index: auto;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }
  .nav-dropdown-menu::before {
    display: none;
  }
  .nav-dropdown-item {
    white-space: normal;
    padding: 0.6rem 0.85rem;
  }
  .topbar-user {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    width: 100%;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
  }
  .topbar-user .topbar-link,
  .topbar-user-name {
    padding: 0.55rem 0.85rem;
    max-width: none;
  }
  .topbar-logout {
    display: block;
    width: 100%;
  }
  .topbar-logout .btn {
    width: 100%;
    min-height: 2.75rem;
  }
  .lang-switcher {
    width: 100%;
  }
  .lang-select {
    width: 100%;
    min-height: 2.5rem;
    font-size: 0.95rem;
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    border: none;
    padding: 0;
    cursor: pointer;
  }
  .nav-backdrop[hidden] {
    display: none !important;
  }
  /* Keep hamburger above the open drawer so it can close the menu */
  body.nav-open .nav-toggle {
    position: relative;
    z-index: 65;
  }

  /* -- Generic pages --------------------------------------------- */
  .container {
    padding: 1rem 0.85rem 2rem;
    padding-left: max(0.85rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.85rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
  }
  .page-head {
    gap: 0.65rem;
  }
  .page-head h1 {
    font-size: 1.35rem;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 0.9rem 0.95rem;
  }
  .flash-wrap {
    padding: 0 0.85rem;
  }
  .login-card {
    margin: 1.25rem auto;
  }

  /* -- Chat: list is home; chat is a detail screen ---------------- */
  /* Flex so fixed sidebar/backdrop do not create extra grid tracks. */
  .chat-layout {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  .chat-layout > .sidebar,
  .chat-layout > .sidebar-backdrop {
    flex: none;
  }
  .chat-main {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    /* % height fights flex shrink and can collapse the message pane */
    height: auto;
    overflow: hidden;
  }
  .chat-workspace {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  /* Keep the answer feed visible even when chrome is tall */
  .chat-scroll {
    flex: 1 1 auto;
    min-height: 10rem;
  }

  /* List home: sidebar fills the screen (primary mobile surface) */
  body.page-chat.mobile-list-home .chat-layout > .sidebar {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none !important;
    width: 100%;
    max-width: none;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    z-index: auto;
    box-shadow: none;
    border-right: none;
    border-left: none;
    padding: 0.65rem 0.7rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.7rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.7rem, env(safe-area-inset-right, 0px));
    background: transparent;
    overflow: auto;
    overscroll-behavior: contain;
  }
  body.page-chat.mobile-list-home .chat-main {
    display: none !important;
  }
  body.page-chat.mobile-list-home .sidebar-backdrop {
    display: none !important;
  }
  body.page-chat.mobile-list-home .sidebar-close-btn {
    display: none !important;
  }
  body.page-chat.mobile-list-home .sidebar-mobile-head {
    display: flex;
    border-bottom: none;
    padding-bottom: 0.15rem;
  }

  /* Chat detail: sidebar off-canvas (optional quick switch via CSS class) */
  body.page-chat:not(.mobile-list-home) .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(20rem, 90vw);
    max-width: 100%;
    z-index: 50;
    transform: translateX(-110%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--border);
    border-bottom: none;
    max-height: none;
    height: 100%;
    height: 100dvh;
    padding: 0.65rem 0.7rem;
    padding-top: max(0.65rem, env(safe-area-inset-top, 0px));
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.7rem, env(safe-area-inset-left, 0px));
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.45);
    background: rgba(16, 24, 36, 0.98);
    overflow: auto;
    overscroll-behavior: contain;
  }
  body.page-chat:not(.mobile-list-home).sidebar-open .sidebar {
    transform: translateX(0);
  }
  html[dir="rtl"] body.page-chat:not(.mobile-list-home) .sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border);
    transform: translateX(110%);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
    padding-left: 0.7rem;
    padding-right: max(0.7rem, env(safe-area-inset-right, 0px));
  }
  html[dir="rtl"] body.page-chat:not(.mobile-list-home).sidebar-open .sidebar {
    transform: translateX(0);
  }
  body.page-chat:not(.mobile-list-home) .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 48;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    border: none;
    padding: 0;
    cursor: pointer;
  }
  body.page-chat:not(.mobile-list-home) .sidebar-backdrop[hidden] {
    display: none !important;
  }
  body.sidebar-open,
  body.nav-open {
    overflow: hidden;
  }

  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.15rem;
  }
  .sidebar-mobile-title {
    font-size: 1.05rem;
    font-weight: 600;
  }
  .sidebar-close-btn {
    min-width: 2.4rem;
    min-height: 2.4rem;
  }

  /* Back-to-list bar (only on chat detail) */
  body.page-chat:not(.mobile-list-home) .chat-mobile-bar {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-shrink: 0;
    padding: 0.4rem 0.65rem;
    border-bottom: 1px solid var(--border);
    background: rgba(20, 28, 40, 0.96);
    min-height: 2.75rem;
  }
  body.page-chat.mobile-list-home .chat-mobile-bar {
    display: none !important;
  }
  .sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 2.35rem;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  /* Prefer a clear "back" affordance over the hamburger bars */
  .sidebar-toggle-icon {
    display: none;
  }
  .sidebar-toggle-btn::before {
    content: "←";
    font-size: 1.05rem;
    line-height: 1;
    opacity: 0.9;
  }
  html[dir="rtl"] .sidebar-toggle-btn::before {
    content: "→";
  }
  .chat-mobile-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
  }
  .chat-mobile-project {
    opacity: 0.85;
  }

  /* Touch-friendlier session rows */
  .session-item {
    min-height: 2.85rem;
  }
  .session-action-btn,
  .session-menu-btn {
    min-width: 2.25rem;
    min-height: 2.25rem;
  }

  /* Prompt + statusbar (safe-area only on last chrome strip) */
  .prompt-bar {
    grid-template-columns: 1fr auto;
    gap: 0.4rem;
    padding: 0.45rem 0.65rem 0.35rem;
    flex-shrink: 0;
  }
  .prompt-actions {
    flex-direction: column;
    align-self: stretch;
  }
  .prompt-actions .btn {
    flex: 1 1 auto;
    min-width: 5.5rem;
    min-height: 2.5rem;
  }
  .prompt-bar textarea {
    min-height: 2.6rem;
    max-height: 6rem;
    /* ≥16px — no iOS zoom; rem — respect settings font size */
    font-size: max(1rem, 16px);
  }
  .prompt-compose-tools {
    gap: 0.35rem;
  }
  .prompt-compose-tools .btn {
    min-height: 2.25rem;
  }
  #image-hint {
    display: none;
  }
  .chat-statusbar {
    padding: 0.15rem 0.55rem;
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom, 0px));
    font-size: 0.72rem;
    flex-shrink: 0;
  }
  .statusbar-context {
    max-width: 55%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .statusbar-context::-webkit-scrollbar {
    display: none;
  }
  .chat-statusbar .model-picker select {
    max-width: 7rem;
    font-size: max(1rem, 16px); /* ≥16px — no iOS zoom; rem — settings */
    height: 1.7rem;
  }
  .chat-statusbar .agent-status-detail {
    max-width: 7rem;
  }

  /* Messages / activity — NEVER stack the 3 panes (≤700px rule did that
     and zeroed out the answer feed on phones). Keep one compact row. */
  .first-prompt-pin {
    margin: 0.35rem 0.65rem 0;
    max-width: calc(100% - 1.3rem);
    padding: 0.4rem 0.6rem;
    flex-shrink: 0;
  }
  .messages {
    padding: 0.55rem 0.65rem 0.5rem;
  }
  .msg {
    max-width: 100%;
  }
  .live-panel {
    padding: 0 0.65rem 0.5rem;
  }
  .activity-rail {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.3rem;
    margin: 0;
    padding: 0.3rem 0.5rem 0.35rem;
    flex: 0 0 auto;
    max-height: 5.5rem;
    overflow: hidden;
  }
  .activity-rail #terminal-pane {
    grid-column: auto;
  }
  .activity-pane {
    padding: 0.25rem 0.35rem;
    min-height: 0;
  }
  .activity-pane-preview {
    max-height: calc(1.3em * 2);
    min-height: 0;
    font-size: 0.68rem;
  }
  .activity-pane-title {
    font-size: 0.62rem;
  }
  .activity-pane-head .btn.ghost {
    padding: 0.1rem 0.3rem;
    font-size: 0.65rem;
  }
  .permission-panel,
  .question-panel,
  .plan-panel {
    margin: 0 0.5rem 0.5rem;
    max-width: none;
    max-height: min(50vh, 22rem);
    padding: 0.75rem 0.75rem;
  }
  .permission-actions {
    gap: 0.4rem;
  }
  .permission-actions .btn,
  .question-footer .btn,
  .plan-footer .btn {
    min-height: 2.5rem;
  }
  .stuck-panel {
    margin: 0 0.5rem 0.4rem;
  }
  .agent-thread-shell {
    width: 100vw;
    max-width: 100%;
  }
  .limits-modal-root,
  .help-modal-root {
    padding: 0.5rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    align-items: flex-end;
  }
  /* Keep document preview centered even on narrow screens */
  .agent-doc-modal-root {
    align-items: center !important;
    justify-content: center !important;
    padding: 0.75rem !important;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px)) !important;
  }
  .limits-modal,
  .help-modal {
    width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 14px 14px 10px 10px;
  }
  .agent-doc-modal {
    width: min(96vw, 100%) !important;
    max-height: min(92dvh, 92vh) !important;
  }

  /* Plans / agents / bus */
  .plans-grid {
    grid-template-columns: 1fr;
  }
  .bus-layout {
    grid-template-columns: 1fr;
  }
  .bus-thread-list {
    max-height: none;
  }

  /* Prevent body scroll under open drawers on chat */
  body.page-chat.nav-open,
  body.page-chat.sidebar-open {
    overflow: hidden;
  }
}

/* ── Process monitor ─────────────────────────────────────────── */
.mon-resources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.mon-res-card {
  padding: 0.9rem 1rem;
}
.mon-res-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}
.mon-res-value {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 0.45rem;
}
.mon-res-value.mono { font-family: var(--mono); font-size: 1.1rem; }
.mon-res-detail {
  margin-top: 0.35rem;
  word-break: break-all;
}
.mon-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}
.mon-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.35s ease, background 0.2s ease;
}
.mon-bar-fill.warn { background: var(--warn); }
.mon-bar-fill.danger { background: var(--danger); }
.mon-auto {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  user-select: none;
  cursor: pointer;
}
.mon-table-card { padding: 0; overflow: hidden; }
.mon-table-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem 0.55rem;
  border-bottom: 1px solid var(--border);
}
.mon-table-title {
  margin: 0;
  font-size: 1.05rem;
}
.mon-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.mon-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.mon-table th,
.mon-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.mon-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
}
.mon-table tbody tr:hover td {
  background: rgba(61, 139, 253, 0.06);
}
.mon-table .mono { font-family: var(--mono); }
.mon-cmd {
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.mon-kind {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.mon-kind-acp { color: #7ec8ff; border-color: rgba(126, 200, 255, 0.35); }
.mon-kind-terminal { color: #b8e986; border-color: rgba(184, 233, 134, 0.35); }
.mon-kind-grok-headless,
.mon-kind-claude-headless,
.mon-kind-api-headless { color: #f0b429; border-color: rgba(240, 180, 41, 0.35); }
.mon-kind-preview { color: #c79bff; border-color: rgba(199, 155, 255, 0.35); }
.mon-kind-turn { color: #3ecf8e; border-color: rgba(62, 207, 142, 0.35); }
.mon-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  vertical-align: middle;
}
.mon-badge-run {
  background: rgba(62, 207, 142, 0.18);
  color: var(--ok);
  border: 1px solid rgba(62, 207, 142, 0.35);
}
.mon-table .empty-row { text-align: center; padding: 1.5rem; }
.danger-text { color: var(--danger); }

@media (max-width: 720px) {
  .mon-resources {
    grid-template-columns: 1fr 1fr;
  }
  .mon-cmd { max-width: 12rem; }
}
@media (max-width: 520px) {
  .mon-resources {
    grid-template-columns: 1fr;
  }
}

/* Phone refinements */
@media (max-width: 520px) {
  .brand {
    font-size: 0.95rem;
  }
  .topbar-user-name {
    font-size: 0.88rem;
  }
  .chat-mobile-bar {
    padding: 0.35rem 0.5rem;
  }
  .prompt-compose-tools .btn.small {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }
  .statusbar-row-top {
    flex-wrap: wrap;
  }
  .statusbar-context {
    max-width: 100%;
    margin-inline-start: 0;
    width: 100%;
  }
  .chat-statusbar .agent-status {
    width: 100%;
  }
  .msg .body {
    font-size: 0.95rem;
  }
  .silent-desk {
    padding: 1rem 0.85rem;
  }
  .silent-desk-title {
    font-size: 1.15rem;
  }
}

/* Prefer reduced motion */
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .site-nav-drawer,
  .sidebar {
    transition: none;
  }
}

/* Local connector lamp (futures/35) */
.device-lamp { display: inline-block; width: .6em; height: .6em; border-radius: 50%; background: #6b7280; vertical-align: middle; }
.device-lamp[data-state="on"] { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
