:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c0e;
  --panel: #111317;
  --panel-2: #17191e;
  --panel-3: #1d2026;
  --border: #292c33;
  --text: #f2f3f5;
  --muted: #959ba6;
  --accent: #79e8b5;
  --accent-2: #3db88a;
  --green: #79e8b5;
  --green-2: #173d31;
  --blue: #9eb9ff;
  --red: #ff8e8e;
  --amber: #ffcf70;
  --purple: #c4a8ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, .45);
  --chip-bg: rgba(255,255,255,.04);
  --chip-border: rgba(255,255,255,.08);
  --chat-max: min(1280px, calc(100% - 48px));
  --chat-pad-x: max(20px, calc((100% - min(1280px, 100% - 48px)) / 2));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #eef0f5;
  --panel-3: #e4e7ef;
  --border: #d0d5e2;
  --text: #151821;
  --muted: #5c6478;
  --accent: #1a9f6a;
  --accent-2: #147a52;
  --green: #1a9f6a;
  --green-2: #d4f3e6;
  --blue: #3b5bdb;
  --red: #c23b3b;
  --amber: #b8860b;
  --purple: #7c5cbf;
  --shadow: 0 18px 50px rgba(30, 40, 70, .12);
  --chip-bg: rgba(20, 30, 60, .04);
  --chip-border: rgba(20, 30, 60, .1);
}
[data-accent="blue"] { --accent: #8b9cff; --accent-2: #5b6cff; }
[data-accent="purple"] { --accent: #b39dff; --accent-2: #7c5cbf; }
[data-accent="gold"] { --accent: #e0c06a; --accent-2: #b8942e; }
[data-accent="green"] { --accent: #79e8b5; --accent-2: #3db88a; }
[data-theme="light"][data-accent="blue"] { --accent: #4b5fd6; --accent-2: #3a4db8; }
[data-theme="light"][data-accent="purple"] { --accent: #6b4fc0; --accent-2: #5439a0; }
[data-theme="light"][data-accent="gold"] { --accent: #b8942e; --accent-2: #8f7320; }
[data-theme="light"][data-accent="green"] { --accent: #1a9f6a; --accent-2: #147a52; }
[data-density="compact"] .message { margin-bottom: 16px; }
[data-density="compact"] .message-body { font-size: 14px; line-height: 1.55; }
[data-density="compact"] .message-label { margin-bottom: 4px; }
* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
body {
  background: var(--bg);
  color: var(--text);
  height: 100%;
  height: 100dvh;
  height: 100svh;
  height: var(--app-height, 100svh);
}
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--green); outline-offset: 2px;
}
.hidden { display: none !important; }
.mobile-only { display: none; }

.shell {
  position: fixed;
  top: var(--app-top, 0px);
  left: var(--app-left, 0px);
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  width: var(--app-width, 100vw);
  height: 100%;
  height: 100dvh;
  height: 100svh;
  height: var(--app-height, 100svh);
  max-width: 100%;
  overflow: hidden;
}
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: 18px 14px 12px;
  background: #0e1013;
  border-right: 1px solid var(--border);
}
.brand-row { display: flex; align-items: center; gap: 11px; padding: 2px 6px 18px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row strong { font-size: 15px; }
.brand-row span { margin-top: 2px; color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.brand-mark {
  display: grid; place-items: center; width: 58px; height: 58px; border-radius: 18px;
  color: #07110d; background: linear-gradient(145deg, #b6ffd9, #53d59b);
  box-shadow: 0 12px 35px rgba(83, 213, 155, .22); font-size: 25px; font-weight: 800;
}
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
.new-thread {
  width: 100%; padding: 11px 14px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; text-align: left; transition: .18s ease;
}
.new-thread:hover { border-color: #3d424c; background: var(--panel-3); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.fleet-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.fleet-chip {
  display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--panel-2);
  color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .03em;
}
.fleet-chip.working { color: var(--green); border-color: rgba(121,232,181,.3); }
.fleet-chip.needs { color: var(--amber); border-color: rgba(255,207,112,.35); }
.fleet-chip.idle { color: var(--muted); }
.session-search { display: block; margin: 0 0 8px; }
.session-search input {
  width: 100%; min-height: 36px; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 12px;
}
.thread-item .pin-btn {
  flex: 0 0 auto; margin-left: auto; padding: 2px 6px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); font-size: 12px; cursor: pointer;
}
.thread-item .pin-btn:hover, .thread-item .pin-btn.pinned { color: var(--amber); }
.thread-item .item-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.thread-heading {
  display: flex; align-items: center; justify-content: space-between;
  margin: 24px 8px 9px; color: #707681; font-size: 10px; font-weight: 700; letter-spacing: .12em;
}
.icon-button, .text-button {
  padding: 5px 7px; color: var(--muted); background: none; border: 0; border-radius: 7px;
}
.icon-button:hover, .text-button:hover { color: var(--text); background: var(--panel-2); }
.thread-list { flex: 1; min-height: 0; overflow-y: auto; }
.thread-item {
  display: block; width: 100%; margin: 2px 0; padding: 10px 10px;
  color: #c5c9d0; background: transparent; border: 0; border-radius: 9px; text-align: left;
}
.thread-item:hover { background: #15171b; }
.thread-item.active { color: var(--text); background: var(--panel-2); }
.thread-item strong, .thread-item span {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-item strong { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 550; }
.thread-item span { margin-top: 4px; color: #6f7580; font-size: 11px; }
.thread-activity {
  flex: 0 0 auto; width: 7px; height: 7px; border: 2px solid var(--green);
  border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 11px 5px 0; border-top: 1px solid var(--border);
}
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection i, .status-pill i {
  width: 7px; height: 7px; border-radius: 50%; background: #606670;
}
.connection i.online, .status-pill.online i {
  background: var(--green); box-shadow: 0 0 9px rgba(121, 232, 181, .55);
}

/* Three rows: topbar | chat pane | composer */
.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 14, 17, .96);
  backdrop-filter: blur(18px);
}
.main-pane {
  grid-row: 2;
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.thread-meta { min-width: 0; }
.thread-meta strong, .thread-meta > span {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-meta strong { font-size: 14px; }
.thread-meta > span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.usage-strip {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; max-width: 100%;
}
.usage-chip {
  display: inline-flex; align-items: center; max-width: 100%;
  min-height: 22px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--chip-border); background: var(--chip-bg);
  color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.usage-chip.ok { color: var(--green); border-color: rgba(121, 232, 181, .25); }
.usage-chip.warn { color: var(--amber); }
.usage-chip.hidden { display: none !important; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.activity-toggle {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px;
  color: #c8cdd5; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; font-size: 11px;
}
.activity-toggle:hover, .activity-toggle.active {
  color: var(--text); border-color: #46534d; background: #19211d;
}
.activity-pulse {
  display: inline-block; flex: 0 0 auto; width: 7px; height: 7px;
  border-radius: 50%; background: #636973;
}
.workspace.has-activity .activity-pulse {
  background: var(--green); box-shadow: 0 0 10px rgba(121,232,181,.6);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; transform: scale(.82); } }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px;
  color: var(--muted); background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; font-size: 11px;
}
.mode-pill {
  padding: 6px 9px; color: #9bd9bd; background: #14241d;
  border: 1px solid #294b3c; border-radius: 999px; font-size: 10px;
}
.mode-pill.full-access {
  color: #ffd39b; background: #2b1f12; border-color: #69471f;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 24px 18px 28px;
  overflow-y: auto;
  text-align: center;
}
.empty-state > * { width: min(680px, 100%); }
.orb {
  display: grid; place-items: center; width: 74px; height: 74px; margin: 0 auto 25px;
  border: 1px solid #3a5147; border-radius: 24px; color: var(--green);
  background: radial-gradient(circle at 35% 25%, #263c33, #121815 68%);
  box-shadow: 0 20px 70px rgba(55, 170, 119, .13); font-size: 27px; font-weight: 800;
}
.eyebrow { color: var(--green); font-size: 10px; font-weight: 750; letter-spacing: .18em; }
.empty-state h1, .login-card h1 {
  margin: 10px 0 10px; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.045em;
}
.empty-state > p:not(.eyebrow) {
  max-width: 560px; margin: 0 auto; color: var(--muted); line-height: 1.65;
}
.workspace-picker {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin: 30px auto 0; padding: 12px 14px; max-width: 470px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  font-size: 12px; text-align: left;
}
select {
  max-width: 100%; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px;
}
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 28px; }
.suggestions button {
  padding: 13px 12px; color: #bfc4cc; background: #111317;
  border: 1px solid var(--border); border-radius: 10px; font-size: 12px;
}
.suggestions button:hover { color: var(--text); border-color: #414650; transform: translateY(-1px); }

.conversation {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 24px var(--chat-pad-x) 28px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}
.message { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 13px; margin-bottom: 28px; }
.message-main { min-width: 0; }
.avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  color: #07110d; background: var(--green); font-size: 11px; font-weight: 800;
  margin-top: 2px;
}
.message.user .avatar { color: #dbe5ff; background: #283550; }
.message-body {
  min-width: 0; color: #e6e8ef; font-size: 15px; line-height: 1.68;
  overflow-wrap: anywhere; letter-spacing: .005em;
}
.message-body.streaming { white-space: pre-wrap; color: #d9dce2; }
.message-body > p { margin: 0 0 .78em; }
.message-body > p:last-child { margin-bottom: 0; }
.message-body > .md-h {
  margin: 1.05em 0 .4em; color: var(--text); font-weight: 700;
  line-height: 1.28; letter-spacing: -.02em;
}
.message-body > .md-h:first-child { margin-top: 0; }
.message-body > .md-h1 { font-size: 1.32em; }
.message-body > .md-h2 { font-size: 1.16em; }
.message-body > .md-h3 { font-size: 1.05em; color: #dce0ea; font-weight: 650; }
.message-body > .md-list { margin: .35em 0 .85em; padding-left: 1.3em; }
.message-body > .md-list li { margin: .32em 0; padding-left: .15em; }
.message-body > blockquote {
  margin: .55em 0 .9em; padding: .15em 0 .15em .95em;
  border-left: 3px solid rgba(121, 232, 181, .4); color: #b6bdcc;
}
.message-body > blockquote p { margin: 0 0 .45em; }
.message-body > blockquote p:last-child { margin-bottom: 0; }
.message-body > hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.message-body strong { color: #f0f2f7; font-weight: 700; }
.message-body em { color: #d5dae6; font-style: italic; }
.message-body .md-link {
  color: #9ee6c4; text-decoration: underline; text-underline-offset: 2px;
}
.message-body .md-link:hover { color: #c6f5df; }
.message-body code.md-inline,
.message-body :not(pre) > code {
  padding: 1px 6px; border-radius: 6px; background: rgba(13, 15, 22, .9);
  border: 1px solid var(--border); color: #d7dceb;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.message-body .md-code-block {
  margin: .7em 0 1em; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: #090a0c;
}
.message-body .md-code-lang {
  padding: 6px 12px; color: #7a8294; font-size: 10px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  border-bottom: 1px solid var(--border); background: #0d0f14;
}
.message-body pre, .event-card pre, .approval-copy pre {
  margin: 0; padding: 13px 14px; overflow: auto; color: #cbd1da; background: #090a0c;
  border: 1px solid var(--border); border-radius: 9px;
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap;
}
.message-body .md-code-block pre { border: 0; border-radius: 0; }
.message.user .message-body {
  padding: 11px 14px; border-radius: 14px 14px 14px 6px;
  background: rgba(40, 53, 80, .32); border: 1px solid rgba(90, 110, 150, .22);
  color: #e4e8f2; font-size: 14.5px;
}
.message-image-link {
  display: block; width: fit-content; max-width: min(100%, 960px);
  margin: 10px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: #090a0c;
}
.message-image { display: block; width: auto; max-width: 100%; max-height: 75vh; object-fit: contain; }
.message-label {
  margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
}
.event-card {
  margin: -12px 0 24px 45px; padding: 10px 12px; color: var(--muted);
  background: #101216; border: 1px solid #23262c; border-radius: 9px; font-size: 11px;
}
.event-card strong { color: #bec4cd; font-weight: 600; }
.progress-card {
  margin: -10px 0 22px 45px; max-width: 820px; color: var(--muted);
  background: #101216; border: 1px solid #252a31; border-radius: 10px;
  font-size: 12px;
}
.progress-card summary {
  padding: 9px 12px; cursor: pointer; color: #aeb5c0; font-weight: 650;
  user-select: none;
}
.progress-card[open] summary { border-bottom: 1px solid #252a31; color: #c8ced8; }
.progress-updates { padding: 4px 12px; }
.progress-update { padding: 8px 0; line-height: 1.5; border-bottom: 1px solid rgba(255,255,255,.05); }
.progress-update:last-child { border-bottom: 0; }
.progress-update > p { margin: 0 0 .5em; }
.progress-update > p:last-child { margin-bottom: 0; }
.progress-update.streaming { white-space: pre-wrap; }
.jump-latest {
  position: absolute; z-index: 4; right: 50%; bottom: 16px; padding: 8px 12px;
  color: #dce1e8; background: #22262c; border: 1px solid #454b55; border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); transform: translateX(50%); font-size: 11px;
}
.jump-latest:hover { color: #07110d; background: var(--green); border-color: var(--green); }

.activity-rail {
  position: absolute; z-index: 6; top: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; width: min(340px, 100%);
  background: #0f1114; border-left: 1px solid var(--border);
  box-shadow: -18px 0 50px rgba(0,0,0,.2); transform: translateX(100%); transition: transform .2s ease;
}
.workspace.activity-open .activity-rail { transform: translateX(0); }
.workspace.activity-open .conversation { width: calc(100% - min(340px, 100%)); }
.workspace.activity-open .jump-latest { margin-right: 170px; }
.activity-header {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 70px; padding: 15px 16px; border-bottom: 1px solid var(--border);
}
.activity-header .eyebrow { margin: 0 0 4px; font-size: 9px; }
.activity-header strong { font-size: 14px; }
.activity-state {
  display: grid; grid-template-columns: 8px minmax(0,1fr); align-items: center; gap: 8px;
  padding: 12px 16px; color: #bec3cb; background: #13161a; border-bottom: 1px solid var(--border); font-size: 11px;
}
.activity-state #token-usage { grid-column: 2; color: #686f79; font-size: 9px; }
.plan-panel { padding: 15px 16px 16px; background: rgba(121,232,181,.035); border-bottom: 1px solid var(--border); }
.plan-panel h2, .activity-feed-wrap h2 {
  margin: 0 0 10px; color: #7e858f; font-size: 9px; letter-spacing: .12em; text-transform: uppercase;
}
.plan-panel > p { margin: -4px 0 12px; color: #969eaa; font-size: 10px; line-height: 1.5; }
.plan-panel ol { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.plan-step { display: grid; grid-template-columns: 24px minmax(0,1fr); gap: 9px; align-items: start; padding: 9px 10px; color: #c0c6d0; background: #14171d; border: 1px solid #282d36; border-radius: 9px; }
.plan-marker { display: grid; place-items: center; width: 22px; height: 22px; color: #7f8793; border: 1px solid #454c57; border-radius: 50%; font-size: 11px; font-weight: 800; }
.plan-copy { display: grid; gap: 3px; min-width: 0; }
.plan-copy strong { color: inherit; font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.plan-copy small { color: #747d89; font-size: 8px; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.plan-step.in-progress { color: var(--text); background: rgba(121,232,181,.09); border-color: rgba(121,232,181,.5); box-shadow: 0 0 0 1px rgba(121,232,181,.08); }
.plan-step.in-progress .plan-marker { color: #07110d; background: var(--accent); border-color: var(--accent); }
.plan-step.in-progress .plan-copy small { color: var(--accent); }
.plan-step.completed { color: #aeb6c1; background: rgba(78,148,117,.05); }
.plan-step.completed .plan-marker { color: #fff; background: #4e9475; border-color: #4e9475; }
.plan-step.completed .plan-copy small { color: #78c5a3; }
.activity-feed-wrap {
  display: flex; flex: 1; min-height: 0; flex-direction: column; padding: 14px 10px 10px 16px;
}
.activity-feed { flex: 1; min-height: 0; padding-right: 6px; overflow-y: auto; overscroll-behavior: contain; }
.activity-empty { color: #666d77; font-size: 10px; line-height: 1.6; }
.activity-entry {
  position: relative; margin: 0 0 8px 6px; padding: 9px 10px 9px 13px;
  background: #14171b; border: 1px solid #252930; border-radius: 9px;
}
.activity-entry::before {
  position: absolute; top: 13px; left: -10px; width: 6px; height: 6px;
  background: #555c67; border-radius: 50%; content: '';
}
.activity-entry.running::before { background: var(--green); box-shadow: 0 0 8px rgba(121,232,181,.55); }
.activity-entry.done::before { background: #4e9475; }
.activity-entry.error::before { background: var(--red); }
.activity-entry header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.activity-entry strong {
  overflow: hidden; color: #cbd0d8; font-size: 10px; text-overflow: ellipsis; white-space: nowrap;
}
.activity-entry time { flex: 0 0 auto; color: #5f6670; font-size: 8px; }
.activity-entry pre, .activity-entry p {
  max-height: 180px; margin: 7px 0 0; overflow: auto; color: #9299a4;
  font: 9px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.activity-entry.reasoning p { color: #aeb7c4; font-family: inherit; }

.approval-drawer {
  position: absolute; z-index: 8; right: 20px; bottom: 20px; left: 20px;
  display: grid; grid-template-columns: 35px minmax(0, 1fr) auto; gap: 13px; align-items: start;
  max-width: 1000px; margin: auto; padding: 16px; background: #1c1912;
  border: 1px solid #564728; border-radius: 14px; box-shadow: var(--shadow);
}
.approval-icon {
  display: grid; place-items: center; width: 32px; height: 32px;
  color: #171008; background: var(--amber); border-radius: 9px; font-weight: 800;
}
.approval-copy p { margin: 5px 0; color: #c8b88f; font-size: 12px; }
.approval-copy details { color: var(--muted); font-size: 11px; }
.approval-actions { display: flex; gap: 7px; align-self: center; }
.primary, .secondary, .danger {
  padding: 9px 12px; border-radius: 8px; border: 1px solid transparent; font-weight: 650; font-size: 12px;
}
.primary { color: #07110d; background: var(--accent); }
.secondary { color: var(--text); background: var(--panel-3); border-color: #40444d; }
.danger { color: #ffd5d5; background: #3b2023; border-color: #693136; }
.danger.subtle { padding: 6px 10px; }

.composer-wrap {
  grid-row: 3;
  z-index: 5;
  width: 100%;
  min-width: 0;
  padding: 8px var(--chat-pad-x) max(8px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.attach-preview {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 7px 10px; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; font-size: 11px;
}
.attach-chip img {
  width: 36px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--bg);
}
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip button {
  padding: 0 2px; color: var(--muted); background: transparent; border: 0; font-size: 14px;
}
.attach-chip button:hover { color: var(--red); }
.command-menu {
  max-height: 240px; margin-bottom: 8px; overflow-y: auto;
  background: #17191d; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
}
.command-item {
  display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 10px;
  width: 100%; padding: 10px 12px; border: 0; background: transparent;
  color: var(--text); text-align: left; border-bottom: 1px solid var(--border);
}
.command-item:last-child { border-bottom: 0; }
.command-item:hover, .command-item.active { background: var(--panel-3); }
.command-item.unavailable { opacity: .62; }
.command-item strong { color: var(--accent); font-size: 12px; }
.command-item span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.composer-top { display: flex; align-items: flex-start; gap: 8px; }
.attach-button {
  flex: 0 0 auto; width: 32px; height: 32px; margin-top: 2px;
  color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 16px;
}
.attach-button:hover { color: var(--text); background: var(--panel-3); }
.composer.drag { border-color: var(--accent); }
.composer {
  padding: 10px 12px 8px; background: #17191d; border: 1px solid #383c44;
  border-radius: 14px; box-shadow: 0 10px 36px rgba(0,0,0,.32);
}
.composer:focus-within { border-color: #587065; }
.composer textarea {
  display: block; width: 100%; min-height: 24px; max-height: 120px;
  padding: 4px 2px 8px; resize: none; color: var(--text);
  background: transparent; border: 0; outline: 0; line-height: 1.45;
}
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sidebar-footer-actions { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.tip-modal {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  padding: 18px; background: rgba(4, 5, 10, .78); backdrop-filter: blur(8px);
}
.tip-modal.hidden { display: none !important; }
.tip-dialog {
  position: relative; width: min(440px, 100%); padding: 28px 24px 22px;
  border: 1px solid rgba(139, 156, 255, .28); border-radius: 18px;
  background: linear-gradient(160deg, #151926, #10131c); box-shadow: var(--shadow); text-align: center;
}
.tip-close { position: absolute; top: 10px; right: 10px; }
.tip-icon {
  display: grid; place-items: center; width: 46px; height: 46px; margin: 0 auto 12px;
  border: 1px solid rgba(139, 156, 255, .3); border-radius: 50%;
  background: rgba(139, 156, 255, .1); color: var(--accent); font-size: 1.15rem;
}
.tip-dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
.tip-dialog > p { margin: 0 auto 18px; max-width: 34ch; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.tip-amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tip-amounts button {
  min-height: 58px; padding: 10px 6px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.tip-amounts button span { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; font-weight: 600; }
.tip-amounts button:hover { border-color: #4a5578; background: var(--panel-3); }
.tip-custom-link {
  width: 100%; min-height: 40px; margin-top: 2px; padding: 8px 10px;
  border: 0; border-radius: 10px; background: transparent; color: var(--accent);
  font: inherit; font-size: .84rem; font-weight: 650; cursor: pointer;
}
.tip-custom-link:hover { background: rgba(139, 156, 255, .08); }
.tip-fine { margin: 10px 0 0; color: #6b7285; font-size: .72rem; line-height: 1.45; }

.prefs-modal {
  position: fixed; inset: 0; z-index: 85; display: grid; place-items: center;
  padding: 16px; background: rgba(4, 5, 10, .78); backdrop-filter: blur(8px);
}
.prefs-modal.hidden { display: none !important; }
.prefs-dialog {
  position: relative; width: min(560px, 100%); max-height: min(90dvh, 900px);
  overflow: auto; padding: 24px 22px 18px; border: 1px solid var(--border);
  border-radius: 18px; background: var(--panel); box-shadow: var(--shadow);
}
.prefs-close { position: absolute; top: 10px; right: 10px; }
.prefs-dialog h2 { margin: 0 28px 6px 0; font-size: 1.2rem; }
.prefs-lede { margin: 0 0 16px; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.prefs-section {
  margin: 0 0 16px; padding: 14px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--panel-2);
}
.prefs-section h3 { margin: 0 0 12px; font-size: .92rem; font-weight: 750; }
.prefs-section h3 small, .prefs-field span small {
  color: var(--muted); font-weight: 550; font-size: .78em;
}
.prefs-section h4 { margin: 12px 0 8px; font-size: .8rem; color: var(--muted); }
.prefs-field { display: grid; gap: 6px; margin-bottom: 10px; }
.prefs-field span { color: var(--muted); font-size: .78rem; font-weight: 650; }
.prefs-field select, .prefs-field input, .prefs-field textarea {
  width: 100%; min-height: 40px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
.prefs-field textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.prefs-check {
  display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;
  color: var(--text); font-size: .86rem; cursor: pointer;
}
.prefs-check input { margin-top: 3px; }
.prefs-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prefs-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 4px; }
.prefs-actions button { min-height: 38px; font-size: .8rem; }
.prefs-hint { margin: 0 0 10px; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.prefs-amt-status {
  margin: 10px 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--muted); font-size: .82rem; line-height: 1.45;
}
.prefs-amt-status.ok { color: var(--green); border-color: rgba(121, 232, 181, .28); }
.prefs-amt-status.err { color: var(--red); }
.prefs-tools-list { display: grid; gap: 6px; max-height: 180px; overflow: auto; }
.prefs-tool {
  display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  font-size: .78rem;
}
.prefs-tool b { font-weight: 650; }
.prefs-tool .tier {
  flex: 0 0 auto; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); font-size: .68rem; font-weight: 700;
  text-transform: uppercase;
}
.prefs-tool .tier.free { color: var(--green); }
.prefs-tool .tier.paid, .prefs-tool .tier.agent, .prefs-tool .tier.login { color: var(--amber); }
.prefs-footer { display: flex; justify-content: flex-end; margin-top: 4px; }
.prefs-footer .primary { min-width: 140px; min-height: 42px; }
.gallery-dialog { width: min(920px, 100%); }
.gallery-toolbar { display: flex; gap: 10px; margin: 12px 0; }
.gallery-toolbar select { min-height: 38px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; min-height: 120px; }
.gallery-card { min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); }
.gallery-preview { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 3; border: 0; background: var(--bg); color: var(--muted); font-size: 2rem; cursor: pointer; overflow: hidden; }
.gallery-preview img { width: 100%; height: 100%; object-fit: cover; }
.gallery-meta { padding: 9px; }
.gallery-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; font-weight: 700; }
.gallery-detail { margin: 4px 0 8px; color: var(--muted); font-size: .68rem; }
.gallery-actions { display: flex; gap: 6px; }
.gallery-actions a { color: var(--accent); font-size: .72rem; text-decoration: none; }
.message-queue, .queue-choice { display: flex; align-items: center; gap: 8px; max-width: 860px; width: 100%; margin: 0 auto 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); font-size: .76rem; }
.message-queue { overflow-x: auto; }.message-queue.hidden, .queue-choice.hidden { display: none; }
.queue-choice span { flex: 1; color: var(--muted); }.queue-choice button { min-height: 32px; white-space: nowrap; }
.queued-message { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; max-width: 260px; padding: 5px 7px; border-radius: 8px; background: var(--panel-2); }
.queued-message span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.queued-message button { border: 0; background: none; color: var(--muted); cursor: pointer; }
@media (max-width: 560px) {
  .prefs-row, .prefs-actions { grid-template-columns: 1fr; }
  .usage-strip { gap: 4px; }
  .usage-chip { font-size: 9px; padding: 0 6px; }
}

.empty-badges {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 0 0 18px;
}
.empty-badge {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 11px;
  border: 1px solid rgba(121, 232, 181, .28); border-radius: 999px;
  background: rgba(121, 232, 181, .08); color: #b8f0d4; font-size: 11px; font-weight: 650;
  letter-spacing: .02em;
}
.login-tip-link { margin: 14px 0 0; text-align: center; }
.login-tip-link a {
  color: var(--accent); font-size: 12px; font-weight: 650; text-decoration: none;
}
.login-tip-link a:hover { text-decoration: underline; }
.composer-settings { display: flex; align-items: center; min-width: 0; gap: 8px; }
.composer-settings select {
  padding: 4px 6px; color: var(--muted); background: transparent; font-size: 10px; max-width: 150px;
}
#active-workspace {
  overflow: hidden; color: #747a84; font: 10px ui-monospace, monospace;
  text-overflow: ellipsis; white-space: nowrap; max-width: 180px;
}
.send-button {
  width: 32px; height: 32px; color: #07110d; background: var(--accent);
  border: 0; border-radius: 9px; font-size: 18px; font-weight: 800;
}
.send-button:disabled { cursor: not-allowed; opacity: .35; }
.composer-note { display: none; }

.toast-region { position: fixed; z-index: 20; top: 16px; right: 16px; display: grid; gap: 8px; }
.toast {
  max-width: 360px; padding: 11px 14px; color: #e7e9ed; background: #202329;
  border: 1px solid #3b4049; border-radius: 10px; box-shadow: var(--shadow); font-size: 12px;
}
.toast.error { border-color: #65373a; }

.login-page {
  display: grid; place-items: center; min-height: 100vh; min-height: 100dvh;
  padding: max(17px, env(safe-area-inset-top)) max(17px, env(safe-area-inset-right))
    max(17px, env(safe-area-inset-bottom)) max(17px, env(safe-area-inset-left));
  overflow: auto; background: radial-gradient(circle at 50% 30%, #17221d, var(--bg) 42%);
}
.login-card {
  width: min(420px, calc(100% - 34px)); padding: 38px;
  background: rgba(17,19,23,.9); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow);
}
.login-card .brand-mark { margin-bottom: 25px; }
.login-card .muted { color: var(--muted); line-height: 1.6; }
.login-card form { margin-top: 28px; }
.login-card label { display: block; margin-bottom: 7px; color: #b6bbc3; font-size: 12px; }
.login-card input {
  width: 100%; padding: 12px; color: var(--text); background: #0d0f12;
  border: 1px solid #343840; border-radius: 10px;
}
.wide { width: 100%; margin-top: 12px; padding: 12px; }
.error { min-height: 18px; color: var(--red); font-size: 11px; }
.secure-note { margin: 20px 0 0; color: #737a83; font-size: 10px; text-align: center; }
.secure-note span { color: var(--green); }

@media (min-width: 1600px) {
  :root {
    --chat-max: min(1480px, calc(100% - 64px));
    --chat-pad-x: max(24px, calc((100% - min(1480px, 100% - 64px)) / 2));
  }
}

@media (max-width: 760px) {
  :root { --chat-pad-x: max(12px, env(safe-area-inset-left)); }
  .mobile-only { display: inline-flex; }
  body { overscroll-behavior: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(340px, 92vw);
    height: 100%; max-height: none;
    padding: max(18px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
    box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .brand-row .mobile-only { margin-left: auto; }
  .workspace { width: 100%; height: 100%; }
  .topbar {
    min-width: 0;
    min-height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    gap: 9px;
  }
  .topbar > .mobile-only {
    flex: 0 0 42px; align-items: center; justify-content: center;
    width: 42px; height: 42px; margin-left: -8px; font-size: 19px;
  }
  .thread-meta { flex: 1; min-width: 0; }
  .thread-meta strong { font-size: 13px; }
  .thread-meta span { max-width: 44vw; font-size: 9px; }
  .top-actions { flex: 0 0 auto; gap: 6px; }
  .status-pill, .mode-pill { display: none; }
  .activity-toggle { min-width: 42px; min-height: 38px; padding: 7px 9px; font-size: 0; }
  .activity-toggle::after { font-size: 16px; content: '☷'; }
  .danger.subtle { min-height: 38px; padding: 7px 9px; }
  .empty-state { padding: 16px 14px 20px; }
  .empty-state h1 { font-size: 28px; }
  .empty-state > p:not(.eyebrow) { font-size: 13px; line-height: 1.55; }
  .orb { width: 58px; height: 58px; margin-bottom: 18px; border-radius: 18px; font-size: 21px; }
  .workspace-picker { align-items: stretch; flex-direction: column; gap: 8px; margin-top: 22px; }
  .workspace-picker select { width: 100%; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestions button { min-height: 45px; }
  .approval-drawer {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    grid-template-columns: 32px minmax(0, 1fr);
    max-height: min(58dvh, 420px); overflow-y: auto;
    padding: 14px; border-width: 2px;
  }
  .approval-copy strong { font-size: 15px; }
  .approval-copy p { font-size: 13px; line-height: 1.45; }
  .approval-actions { grid-column: 1 / -1; flex-wrap: wrap; gap: 8px; }
  .approval-actions button {
    flex: 1 1 30%; min-width: 96px; min-height: 48px; font-size: 14px; font-weight: 750;
  }
  .composer-wrap {
    padding: 10px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .composer { padding: 10px 11px 8px; border-radius: 14px; }
  .composer textarea { min-height: 28px; font-size: 16px; }
  .composer-settings { max-width: calc(100% - 45px); }
  .composer-settings select { max-width: 135px; min-height: 34px; font-size: 16px; }
  #active-workspace { display: none; }
  .send-button { flex: 0 0 auto; width: 38px; height: 38px; }
  .conversation {
    width: 100%;
    padding: 18px max(14px, env(safe-area-inset-right)) 20px max(14px, env(safe-area-inset-left));
    -webkit-overflow-scrolling: touch;
  }
  .message { grid-template-columns: 28px minmax(0,1fr); gap: 9px; margin-bottom: 22px; }
  .avatar { width: 27px; height: 27px; }
  .message-body { font-size: 14.5px; line-height: 1.64; }
  .message.user .message-body { font-size: 14px; padding: 10px 12px; }
  .message-body pre, .event-card pre { max-width: 100%; font-size: 11px; }
  .event-card { margin-left: 36px; }
  .progress-card { margin-left: 36px; }
  .jump-latest { right: 50%; bottom: 12px; white-space: nowrap; }
  .activity-rail {
    z-index: 40; width: 100%; max-width: none;
    padding-top: env(safe-area-inset-top); padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left);
  }
  .activity-header { min-height: 60px; }
  .activity-header .icon-button {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; font-size: 24px;
  }
  .activity-feed-wrap { padding-bottom: 8px; }
  .activity-entry pre, .activity-entry p { max-height: 34dvh; font-size: 10px; }
  .workspace.activity-open .conversation { width: 100%; }
  .workspace.activity-open .jump-latest { margin-right: 0; }
  .login-card { padding: 28px 22px; border-radius: 18px; }
  .login-card input { min-height: 48px; font-size: 16px; }
  .login-card .wide { min-height: 48px; }
}
@media (max-width: 390px) {
  .thread-meta span { max-width: 36vw; }
  .activity-toggle { padding-right: 7px; padding-left: 7px; }
  .empty-state { padding-top: 12px; }
  .suggestions { margin-top: 18px; }
  .tip-amounts { grid-template-columns: 1fr; }
  .empty-badges { margin-bottom: 12px; }
}
@media (max-height: 620px) and (max-width: 760px) {
  .empty-state .orb, .empty-state .eyebrow, .empty-state > p:not(.eyebrow), .empty-badges, .suggestions { display: none; }
  .empty-state { padding-top: 15px; }
  .workspace-picker { margin-top: 15px; }
}
