:root {
  --bg: #171717;
  --sidebar: #141414;
  --list: #1b1b1b;
  --detail: #202020;
  --surface: #262626;
  --surface-hover: #2d2d2d;
  --surface-active: #333333;
  --text: #ececec;
  --text-soft: #c8c8c8;
  --muted: #9b9b9b;
  --subtle: #747474;
  --border: #343434;
  --border-strong: #454545;
  --green: #70d28a;
  --green-soft: rgba(112, 210, 138, 0.13);
  --yellow: #e8bd68;
  --yellow-soft: rgba(232, 189, 104, 0.13);
  --red: #f08086;
  --red-soft: rgba(240, 128, 134, 0.13);
  --blue: #86aaf6;
  --blue-soft: rgba(134, 170, 246, 0.13);
  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-width: 256px;
  --list-width: 390px;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: #575757 transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 99px; background: #575757; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #707070; background-clip: padding-box; }
html { min-width: 320px; min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100dvh; color: var(--text); background: var(--bg); line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button { color: inherit; touch-action: manipulation; }
button, [role="button"], summary { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
svg { width: 20px; height: 20px; flex: 0 0 auto; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }
p { margin: 0; }
[hidden] { display: none !important; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.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;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  transform: translateY(-160%);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #111;
  background: var(--text);
}
.skip-link:focus { transform: translateY(0); }

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  transition: color 160ms ease, background 160ms ease;
}
.icon-button:hover, .icon-button:active { color: var(--text); background: var(--surface-hover); }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface);
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px; }
.brand-mark.small svg { width: 20px; height: 20px; }

/* Login */
.login-shell {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.045), transparent 36rem),
    #171717;
}

.login-card {
  width: min(100%, 390px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #1d1d1d;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}
.brand-lockup { display: flex; align-items: center; gap: 11px; margin-bottom: 38px; color: var(--text-soft); font-size: 0.91rem; font-weight: 600; }
.login-card h1 { font-size: 1.45rem; line-height: 1.2; }
.login-copy { margin: 10px 0 26px; color: var(--muted); font-size: 0.9rem; }
label { display: block; margin-bottom: 7px; color: var(--text-soft); font-size: 0.82rem; font-weight: 600; }
.password-row { position: relative; }
.password-row .icon-button { position: absolute; top: 2px; right: 2px; }

input, textarea, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #181818;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
input { padding: 0 48px 0 12px; }
textarea { padding: 11px 12px; line-height: 1.55; resize: vertical; }
select { padding: 0 36px 0 12px; }
input:hover, textarea:hover, select:hover { border-color: #5a5a5a; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); background: #1b1b1b; box-shadow: 0 0 0 3px var(--blue-soft); outline: none; }

.primary-button {
  width: 100%;
  min-height: 46px;
  margin-top: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  color: #161616;
  background: var(--text);
  font-weight: 700;
  transition: background 160ms ease, opacity 160ms ease;
}
.primary-button:hover { background: #fff; }
.form-error { min-height: 22px; margin: 7px 0 2px; color: #ff9da2; font-size: 0.8rem; }
.trust-note { display: flex; align-items: center; gap: 7px; margin-top: 19px; color: var(--subtle); font-size: 0.72rem; }
.trust-note svg { width: 16px; height: 16px; color: var(--green); }

/* App shell */
.app-shell {
  min-height: 100dvh;
  background: var(--bg);
}

.workspace-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: min(88vw, 292px);
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--border);
  background: var(--sidebar);
  transform: translateX(-102%);
  transition: transform 190ms ease-out;
  overflow: hidden;
}
.app-shell.is-sidebar-open .workspace-sidebar { transform: translateX(0); }
.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  border: 0;
  background: rgba(0, 0, 0, 0.58);
}
.app-shell.is-sidebar-open .sidebar-scrim { display: block; }

.sidebar-brand { display: flex; align-items: center; min-height: 48px; padding: 0 4px 8px; gap: 10px; }
.sidebar-brand > div { display: grid; min-width: 0; }
.sidebar-brand strong { font-size: 0.88rem; }
.sidebar-brand span { color: var(--subtle); font-size: 0.7rem; }
.sidebar-brand .mobile-only { margin-left: auto; }

.new-task-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin: 4px 0 12px;
  padding: 0 12px;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #202020;
  font-size: 0.83rem;
  font-weight: 600;
  transition: border-color 160ms ease, background 160ms ease;
}
.new-task-button:hover { border-color: #595959; background: #282828; }
.new-task-button svg { width: 18px; height: 18px; }

.primary-nav, .project-nav { display: grid; gap: 2px; }
.sidebar-nav-item, .project-nav-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  gap: 8px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-size: 0.8rem;
  transition: color 150ms ease, background 150ms ease;
}
.sidebar-nav-item:hover, .project-nav-item:hover { color: var(--text); background: #202020; }
.sidebar-nav-item.is-active, .project-nav-item.is-active { color: var(--text); background: #282828; }
.sidebar-nav-item svg { width: 18px; height: 18px; }
.nav-count, .project-thread-count { color: var(--subtle); font-size: 0.68rem; font-variant-numeric: tabular-nums; }
.nav-count.is-alert { min-width: 20px; padding: 1px 6px; border-radius: 99px; color: var(--yellow); background: var(--yellow-soft); text-align: center; }

.sidebar-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  margin-top: 10px;
  padding: 0 10px;
  color: var(--subtle);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.project-nav { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.project-nav-item { grid-template-columns: 20px minmax(0, 1fr) auto; }
.project-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px; color: var(--text-soft); background: #303030; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; }
.project-nav-item > span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-spacer { flex: 1; min-height: 12px; }

.host-mini {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  align-items: center;
  min-height: 52px;
  margin: 8px 2px;
  padding: 8px 10px;
  gap: 8px;
  border-top: 1px solid var(--border);
}
.host-dot { width: 8px; height: 8px; border: 2px solid var(--subtle); border-radius: 99px; }
.host-dot.online { border-color: var(--green); background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.host-dot.offline { border-color: var(--red); background: var(--red); }
.host-mini div { display: grid; min-width: 0; }
.host-mini strong { font-size: 0.74rem; font-weight: 600; }
.host-mini span { color: var(--subtle); font-size: 0.65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.sidebar-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  gap: 6px;
  border: 0;
  border-radius: 7px;
  color: var(--subtle);
  background: transparent;
  font-size: 0.72rem;
}
.sidebar-action:hover { color: var(--text); background: #222; }
.sidebar-action svg { width: 16px; height: 16px; }

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 7px 0;
  border-bottom: 1px solid var(--border);
  background: rgba(23, 23, 23, 0.96);
  backdrop-filter: blur(16px);
}
.mobile-heading { display: grid; min-width: 0; text-align: center; }
.mobile-heading strong { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-heading span { color: var(--subtle); font-size: 0.64rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Thread list pane */
.thread-pane {
  min-height: calc(100dvh - 56px - env(safe-area-inset-top));
  background: var(--list);
}
.list-header {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 20;
  padding: 15px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(27, 27, 27, 0.96);
  backdrop-filter: blur(16px);
}
.list-title-row { display: flex; align-items: center; justify-content: space-between; min-height: 38px; gap: 8px; }
.list-title-row h1 { font-size: 1.05rem; line-height: 1.2; }
.list-title-row p { margin-top: 2px; color: var(--subtle); font-size: 0.7rem; }
.desktop-list-refresh { display: none; }
.search-box { position: relative; display: block; margin: 10px 0 9px; }
.search-box svg { position: absolute; top: 11px; left: 10px; width: 17px; height: 17px; color: var(--subtle); pointer-events: none; }
.search-box input { min-height: 40px; padding: 0 40px 0 34px; border-color: var(--border); border-radius: 8px; background: #222; font-size: 0.78rem; }
.search-box kbd { position: absolute; top: 9px; right: 9px; min-width: 22px; height: 22px; border: 1px solid var(--border-strong); border-radius: 5px; color: var(--subtle); background: #1a1a1a; font-family: inherit; font-size: 0.68rem; line-height: 20px; text-align: center; }

.filter-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.filter-chip {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.filter-chip span { margin-left: 3px; color: var(--subtle); font-variant-numeric: tabular-nums; }
.filter-chip:hover { color: var(--text); background: #252525; }
.filter-chip.is-active { border-color: var(--border); color: var(--text); background: #292929; }

.offline-banner {
  display: flex;
  align-items: flex-start;
  margin: 10px 10px 0;
  padding: 10px 11px;
  gap: 8px;
  border: 1px solid rgba(232, 189, 104, 0.22);
  border-radius: 8px;
  color: #d6bd8b;
  background: var(--yellow-soft);
  font-size: 0.72rem;
}
.offline-banner svg { width: 17px; height: 17px; margin-top: 1px; }
.thread-list { padding: 7px 7px 22px; }
.list-group + .list-group { margin-top: 10px; }
.list-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 0 8px;
  color: var(--subtle);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.025em;
}
.list-group-heading span:last-child { font-variant-numeric: tabular-nums; }

.thread-card-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  column-gap: 8px;
  align-items: stretch;
  width: 100%;
  border-radius: 8px;
  transition: background 150ms ease;
}
.thread-card-shell + .thread-card-shell { margin-top: 2px; }
.thread-card-shell:hover { background: var(--surface-hover); }
.thread-card-shell.is-selected { background: var(--surface-active); }
.thread-card-shell.is-selected::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--text-soft);
}
.thread-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 88px;
  padding: 12px 6px 11px 13px;
  gap: 8px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.thread-rename-button {
  display: grid;
  place-items: center;
  align-self: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--subtle);
  background: transparent;
  transition: color 160ms ease, background 160ms ease;
}
.thread-rename-button:hover, .thread-rename-button:active { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.thread-rename-button svg { width: 17px; height: 17px; }
.thread-copy { min-width: 0; }
.thread-title { display: block; color: var(--text); font-size: 0.81rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-preview { display: -webkit-box; margin-top: 4px; color: var(--muted); font-size: 0.72rem; line-height: 1.42; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.thread-meta { display: flex; align-items: center; gap: 6px; margin-top: 7px; color: var(--subtle); font-size: 0.65rem; }
.thread-meta span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-card-status { display: grid; justify-items: end; align-content: space-between; min-width: 70px; }
.thread-time { color: var(--subtle); font-size: 0.62rem; white-space: nowrap; }

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 99px;
  font-size: 0.64rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border: 1.5px solid currentColor; border-radius: 99px; }
.status-active, .status-online, .status-completed { color: var(--green); background: var(--green-soft); }
.status-active::before { background: var(--green); box-shadow: 0 0 0 3px rgba(112, 210, 138, 0.08); }
.status-warning { color: var(--yellow); background: var(--yellow-soft); }
.status-warning::before { background: var(--yellow); }
.status-danger { color: var(--red); background: var(--red-soft); }
.status-danger::before { background: var(--red); }
.status-info { color: var(--blue); background: var(--blue-soft); }
.status-info::before { background: var(--blue); }
.status-muted { color: #a8a8a8; background: rgba(160, 160, 160, 0.09); }

.automation-group {
  margin-bottom: 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.012);
  overflow: hidden;
}
.automation-group > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 54px;
  padding: 8px 10px;
  gap: 8px;
  list-style: none;
}
.automation-group > summary::-webkit-details-marker { display: none; }
.automation-group > summary:hover { background: #242424; }
.automation-group-title { display: grid; min-width: 0; }
.automation-group-title strong { font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.automation-group-title span { margin-top: 2px; color: var(--subtle); font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.61rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.automation-group-meta { display: flex; align-items: center; gap: 7px; color: var(--subtle); font-size: 0.63rem; }
.automation-group-meta svg { width: 15px; height: 15px; transition: transform 160ms ease; }
.automation-group[open] .automation-group-meta svg { transform: rotate(90deg); }
.automation-runs { padding: 3px 5px 6px; border-top: 1px solid var(--border); }
.automation-runs .thread-card { min-height: 82px; }

.empty-state { margin: 16px 10px; padding: 42px 20px; border: 1px dashed var(--border-strong); border-radius: 10px; color: var(--muted); text-align: center; }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 9px; color: var(--subtle); }
.empty-state h2 { color: var(--text-soft); font-size: 0.9rem; }
.empty-state p { margin-top: 5px; font-size: 0.74rem; }
.list-loading { display: grid; gap: 6px; padding: 12px 7px; }
.list-loading span { display: block; height: 82px; border-radius: 8px; background: #232323; animation: pulse 1.4s ease-in-out infinite; }

/* Detail pane */
.detail-pane {
  display: none;
  min-height: calc(100dvh - 56px - env(safe-area-inset-top));
  background: var(--detail);
}
.app-shell.is-detail-open .thread-pane { display: none; }
.app-shell.is-detail-open .detail-pane { display: block; }
.app-shell.is-detail-open .mobile-topbar { display: none; }
.app-shell.is-detail-open .detail-pane { min-height: 100dvh; }
.app-shell.is-detail-open .detail-header { top: 0; }
.workspace-overview {
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: calc(100dvh - 56px - env(safe-area-inset-top));
  padding: 36px 24px;
  color: var(--muted);
  text-align: center;
}
.overview-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 17px; border: 1px solid var(--border); border-radius: 14px; color: var(--text-soft); background: var(--surface); }
.overview-icon svg { width: 27px; height: 27px; }
.workspace-overview h2 { color: var(--text); font-size: 1.05rem; }
.workspace-overview > p { width: min(100%, 470px); margin-top: 8px; color: var(--muted); font-size: 0.8rem; }
.overview-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100%, 460px); margin-top: 22px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.overview-metric { padding: 12px 8px; background: #242424; }
.overview-metric + .overview-metric { border-left: 1px solid var(--border); }
.overview-metric strong { display: block; color: var(--text); font-size: 1rem; font-variant-numeric: tabular-nums; }
.overview-metric span { display: block; margin-top: 1px; color: var(--subtle); font-size: 0.65rem; }

.thread-view, .activity-view { min-height: 100%; }
.thread-view { display: flex; flex-direction: column; }
.detail-header {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 18;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  min-height: 64px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(32, 32, 32, 0.96);
  backdrop-filter: blur(16px);
}
.detail-heading { min-width: 0; }
.detail-heading h2 { color: var(--text); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb { color: var(--subtle); font-size: 0.64rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thread-state-panel {
  margin: 14px 12px 0;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #242424;
}
.state-main-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.state-time { color: var(--subtle); font-size: 0.66rem; }
.thread-state-panel h3 { margin-top: 12px; color: var(--text); font-size: 1rem; }
.thread-state-panel > p { margin-top: 5px; color: var(--muted); font-size: 0.76rem; }
.state-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.state-facts > div { min-width: 0; padding: 9px 10px; background: #202020; }
.state-facts > div:nth-child(even) { border-left: 1px solid var(--border); }
.state-facts > div:nth-child(n+3) { border-top: 1px solid var(--border); }
.state-facts dt, .state-evidence dt { color: var(--subtle); font-size: 0.61rem; }
.state-facts dd, .state-evidence dd { margin: 2px 0 0; color: var(--text-soft); font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state-evidence { margin-top: 10px; }
.state-evidence > summary { min-height: 34px; padding: 7px 2px; color: var(--subtle); font-size: 0.68rem; }
.state-evidence dl { display: grid; grid-template-columns: auto minmax(0, 1fr); margin: 4px 0 0; gap: 6px 12px; }
.state-evidence dd { white-space: normal; overflow-wrap: anywhere; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

.timeline-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 15px 8px; }
.timeline-heading h3 { font-size: 0.8rem; }
.timeline-tools { display: flex; align-items: center; gap: 6px; }
.timeline-tools > span { color: var(--subtle); font-size: 0.64rem; }
.timeline-jump-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 9px;
  gap: 3px;
  border: 0;
  border-radius: 7px;
  color: var(--text-soft);
  background: transparent;
  font-size: 0.67rem;
  font-weight: 600;
}
.timeline-jump-button:hover { background: var(--surface-hover); }
.timeline-jump-button svg { width: 15px; height: 15px; }
.timeline { display: grid; gap: 14px; padding: 4px 12px 170px; }
.load-older-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-soft);
  background: #242424;
  font-size: 0.7rem;
  font-weight: 600;
}
.load-older-button:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.timeline-message { display: grid; gap: 5px; width: min(100%, 760px); }
.timeline-message.user { justify-self: end; width: min(92%, 680px); }
.timeline-meta { display: flex; align-items: center; gap: 7px; color: var(--subtle); font-size: 0.64rem; }
.timeline-message.user .timeline-meta { justify-content: flex-end; }
.message-body {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-soft);
  background: #262626;
  font-size: 0.78rem;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.timeline-message.user .message-body { border-color: rgba(134, 170, 246, 0.2); background: #29303d; }

.activity-block { width: min(100%, 780px); border: 1px solid var(--border); border-radius: 9px; background: #232323; overflow: hidden; }
.activity-block > summary {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 46px;
  padding: 6px 10px;
  gap: 8px;
  list-style: none;
}
.activity-block > summary::-webkit-details-marker { display: none; }
.activity-block > summary:hover { background: #292929; }
.activity-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--muted); background: #303030; }
.activity-icon svg { width: 15px; height: 15px; }
.activity-title { min-width: 0; }
.activity-title strong { display: block; color: var(--text-soft); font-size: 0.71rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-title span { display: block; color: var(--subtle); font-size: 0.61rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-chevron { width: 15px; height: 15px; color: var(--subtle); transition: transform 150ms ease; }
.activity-block[open] .activity-chevron { transform: rotate(90deg); }
.activity-body { max-height: 420px; margin: 0; padding: 11px 12px; border-top: 1px solid var(--border); color: #bdbdbd; background: #1b1b1b; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.67rem; line-height: 1.55; white-space: pre-wrap; overflow: auto; overflow-wrap: anywhere; }

.composer {
  position: sticky;
  bottom: 0;
  z-index: 16;
  margin-top: auto;
  padding: 10px 12px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(32, 32, 32, 0.97);
  backdrop-filter: blur(16px);
}
.composer.is-collapsed {
  display: flex;
  justify-content: flex-end;
  border-top-color: transparent;
  background: linear-gradient(to bottom, transparent, rgba(32, 32, 32, 0.76));
  backdrop-filter: none;
  pointer-events: none;
}
.composer-toggle {
  display: none;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: #151515;
  background: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.38);
  pointer-events: auto;
}
.composer-toggle:hover { background: #fff; }
.composer-toggle svg { width: 20px; height: 20px; }
.composer.is-collapsed .composer-toggle { display: grid; }
.composer.is-collapsed .composer-panel { display: none; }
.composer-panel { width: 100%; }
.composer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 6px;
  color: var(--text-soft);
}
.composer-panel-header strong { font-size: 0.72rem; }
.composer-collapse {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 8px;
  gap: 4px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 0.66rem;
}
.composer-collapse:hover { color: var(--text); background: var(--surface-hover); }
.composer-collapse svg { width: 15px; height: 15px; }
.jump-latest-button {
  position: absolute;
  top: -52px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 13px;
  gap: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  color: var(--text);
  background: #2e2e2e;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.34);
  font-size: 0.7rem;
  font-weight: 650;
  pointer-events: auto;
}
.jump-latest-button:hover { background: #383838; }
.jump-latest-button svg { width: 16px; height: 16px; }
.composer textarea { min-height: 64px; max-height: 180px; resize: none; border-color: var(--border-strong); border-radius: 10px; background: #191919; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 7px; }
.composer-footer > span { color: var(--subtle); font-size: 0.62rem; }
.send-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 9px;
  color: #151515;
  background: var(--text);
  transition: background 150ms ease, opacity 150ms ease;
}
.send-button:hover { background: #fff; }
.send-button svg { width: 19px; height: 19px; }

/* Command activity */
.activity-intro { padding: 18px 14px 6px; }
.activity-intro h3 { font-size: 0.92rem; }
.activity-intro p { margin-top: 4px; color: var(--muted); font-size: 0.73rem; }
.activity-list { display: grid; gap: 10px; padding: 10px 12px 30px; }
.command-card { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #242424; }
.command-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.command-card-header > div { min-width: 0; }
.command-type { color: var(--subtle); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.command-card h3 { margin-top: 2px; color: var(--text); font-size: 0.82rem; }
.command-prompt { display: -webkit-box; margin-top: 10px; color: var(--text-soft); font-size: 0.73rem; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
.command-progress { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 14px; }
.command-stage { position: relative; display: grid; justify-items: center; gap: 5px; color: var(--subtle); font-size: 0.59rem; text-align: center; }
.command-stage::before { content: ""; position: absolute; top: 6px; right: 50%; left: -50%; height: 2px; background: var(--border-strong); }
.command-stage:first-child::before { display: none; }
.stage-dot { position: relative; z-index: 1; width: 13px; height: 13px; border: 2px solid var(--border-strong); border-radius: 99px; background: #242424; }
.command-stage.is-done { color: var(--text-soft); }
.command-stage.is-done::before { background: var(--green); }
.command-stage.is-done .stage-dot { border-color: var(--green); background: var(--green); }
.command-stage.is-current { color: var(--yellow); }
.command-stage.is-current .stage-dot { border-color: var(--yellow); background: var(--yellow); box-shadow: 0 0 0 4px var(--yellow-soft); }
.command-stage.is-failed { color: var(--red); }
.command-stage.is-failed .stage-dot { border-color: var(--red); background: var(--red); }
.command-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 13px; color: var(--subtle); font-size: 0.63rem; }
.command-error { margin-top: 10px; padding: 9px 10px; border-radius: 7px; color: #ffb0b4; background: var(--red-soft); font-size: 0.68rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.open-thread-button {
  min-height: 36px;
  margin-top: 11px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text-soft);
  background: #292929;
  font-size: 0.69rem;
  font-weight: 600;
}
.open-thread-button:hover { border-color: #5c5c5c; color: var(--text); }

/* Dialog and toast */
.task-dialog {
  width: min(calc(100% - 24px), 520px);
  max-height: min(88dvh, 690px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--text);
  background: #222;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.5);
}
.task-dialog::backdrop { background: rgba(0, 0, 0, 0.68); backdrop-filter: blur(5px); }
.task-dialog form { padding: 20px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 8px; }
.dialog-heading span { color: var(--subtle); font-size: 0.63rem; font-weight: 700; letter-spacing: 0.08em; }
.dialog-heading h2 { margin-top: 2px; font-size: 1.05rem; }
.task-dialog label:not(:first-of-type) { margin-top: 15px; }
.rename-dialog { width: min(calc(100% - 24px), 440px); }
.field-help { margin-top: 7px; color: var(--subtle); font-size: 0.68rem; }
.project-selection-help { overflow-wrap: anywhere; }
.project-selection-help.is-warning { color: var(--yellow); }
.toast {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 100;
  width: fit-content;
  max-width: calc(100% - 28px);
  margin: 0 auto;
  padding: 10px 13px;
  border: 1px solid #4b4b4b;
  border-radius: 8px;
  color: var(--text);
  background: #303030;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.38);
  font-size: 0.74rem;
}

@keyframes pulse { 0%, 100% { opacity: 0.52; } 50% { opacity: 1; } }
.is-refreshing svg { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 800px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }
  .mobile-topbar, .sidebar-scrim, .mobile-only { display: none !important; }
  .workspace-sidebar {
    position: relative;
    inset: auto;
    z-index: 1;
    width: var(--sidebar-width);
    transform: none;
  }
  .thread-pane, .detail-pane {
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .list-header, .detail-header { top: 0; }
  .desktop-list-refresh { display: inline-grid; }
  .app-shell.is-detail-open .thread-pane { display: none; }
  .app-shell.is-detail-open .detail-pane { display: block; }
  .detail-back { display: inline-grid; }
  .workspace-overview { min-height: 100dvh; }
  .thread-state-panel { margin: 18px 18px 0; padding: 17px; }
  .timeline { padding-right: 18px; padding-left: 18px; }
  .timeline-heading { padding-right: 20px; padding-left: 20px; }
  .composer { padding-right: 18px; padding-left: 18px; }
  .activity-list { padding-right: 18px; padding-left: 18px; }
  .toast { right: 18px; left: auto; margin: 0; }
}

@media (min-width: 1120px) {
  .app-shell { grid-template-columns: var(--sidebar-width) var(--list-width) minmax(0, 1fr); }
  .thread-pane, .app-shell.is-detail-open .thread-pane { display: block; border-right: 1px solid var(--border); }
  .detail-pane, .app-shell.is-detail-open .detail-pane { display: block; }
  .detail-back { display: none; }
  .list-header { padding: 18px 16px 11px; }
  .thread-list { padding-right: 8px; padding-left: 8px; }
  .detail-header { grid-template-columns: minmax(0, 1fr) 44px; padding-right: 12px; padding-left: 18px; }
  .detail-header .detail-heading { grid-column: 1; }
  .detail-header > .refresh-trigger { grid-column: 2; }
  .thread-state-panel { max-width: 900px; margin-right: auto; margin-left: auto; }
  .timeline-heading, .timeline, .composer { width: min(100%, 940px); margin-right: auto; margin-left: auto; }
  .activity-intro, .activity-list { width: min(100%, 880px); margin-right: auto; margin-left: auto; }
  .app-shell.is-command-scope { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .app-shell.is-command-scope .thread-pane { display: none; }
}

@media (min-width: 1500px) {
  :root { --sidebar-width: 270px; --list-width: 420px; }
}

@media (max-width: 420px) {
  .state-facts { grid-template-columns: 1fr; }
  .state-facts > div:nth-child(even) { border-left: 0; }
  .state-facts > div:nth-child(n+2) { border-top: 1px solid var(--border); }
  .composer-footer > span { max-width: 230px; }
  .thread-card-status { min-width: 66px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
