:root {
  --ink: #ececec;
  --muted: #999b9f;
  --quiet: #707277;
  --background: #101010;
  --sidebar: #171717;
  --surface: #1d1d1d;
  --surface-raised: #242424;
  --surface-hover: #2b2b2b;
  --line: #303030;
  --line-soft: #272727;
  --accent: #d8ff91;
  --accent-strong: #b9ef5d;
  --accent-ink: #172005;
  --danger: #ff8b8b;
  --warning: #e8bd68;
  --info: #94b8ff;
  --sidebar-width: 304px;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  color-scheme: dark;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: var(--background); }
button, input, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
button, input, select, textarea { outline: none; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
.skip-link { position: fixed; z-index: 100; top: 10px; left: 10px; transform: translateY(-150%); border-radius: 8px; background: var(--accent); color: var(--accent-ink); padding: 9px 13px; font-weight: 750; text-decoration: none; }
.skip-link:focus { transform: translateY(0); }

/* Authentication */
.auth-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% -20%, #243015 0, transparent 34rem), var(--background); }
.auth-shell { width: min(100%, 440px); }
.auth-card { border: 1px solid var(--line); border-radius: 22px; background: color-mix(in srgb, var(--surface) 96%, transparent); padding: clamp(26px, 7vw, 42px); box-shadow: 0 30px 90px rgb(0 0 0 / 38%); }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; margin-bottom: 26px; border: 1px solid #475633; border-radius: 12px; background: #252c1b; color: var(--accent); font-size: 13px; font-weight: 850; letter-spacing: -.03em; }
.eyebrow { margin: 0 0 8px; color: var(--accent-strong); font-size: 11px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.auth-card h1 { margin-bottom: 13px; font-size: clamp(30px, 8vw, 42px); line-height: 1.02; letter-spacing: -.045em; }
.lede { color: var(--muted); line-height: 1.6; }
.stack { display: grid; gap: 18px; margin-top: 28px; }
.stack label { display: grid; gap: 8px; color: #d1d1d1; font-size: 13px; font-weight: 650; }
.stack input { width: 100%; min-height: 48px; border: 1px solid #393939; border-radius: 11px; background: #111; color: var(--ink); padding: 11px 13px; }
.stack input:focus { border-color: #778f4a; box-shadow: 0 0 0 3px rgb(185 239 93 / 10%); }
.stack button { min-height: 48px; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-ink); padding: 11px 16px; font-weight: 800; }
.message { margin: 18px 0; border-radius: 11px; padding: 12px 14px; font-size: 14px; line-height: 1.45; }
.message-error { border: 1px solid rgb(255 139 139 / 30%); background: rgb(255 139 139 / 9%); color: #ffb5b5; }
.secret { margin: 22px 0 14px; overflow-wrap: anywhere; border: 1px dashed #4c4c4c; border-radius: 11px; background: #111; padding: 14px; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 16px; letter-spacing: .08em; }
.back-link { display: inline-block; margin-top: 18px; color: var(--accent); font-size: 13px; font-weight: 700; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* Application shell */
.dashboard-page { overflow: hidden; }
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); height: 100dvh; min-height: 560px; }
.sidebar { position: relative; z-index: 20; display: flex; min-width: 0; flex-direction: column; overflow: hidden; border-right: 1px solid var(--line-soft); background: var(--sidebar); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; min-height: 66px; padding: 0 16px; }
.wordmark { display: inline-flex; align-items: center; gap: 10px; color: #f3f3f3; font-size: 14px; font-weight: 720; letter-spacing: -.01em; text-decoration: none; }
.wordmark span { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid #3c4730; border-radius: 9px; background: #242a1d; color: var(--accent); font-size: 10px; font-weight: 850; }
.icon-button { display: grid; width: 38px; height: 38px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font-size: 18px; }
.icon-button:hover { background: var(--surface-hover); }
.sidebar-close { display: none; }
.new-query { display: flex; min-height: 43px; align-items: center; gap: 10px; margin: 3px 12px 18px; border: 1px solid #3c3c3c; border-radius: 10px; padding: 0 12px; background: #202020; color: #f0f0f0; font-size: 13px; font-weight: 680; text-decoration: none; }
.new-query:hover { border-color: #555; background: #292929; }
.new-query span { color: var(--accent); font-size: 18px; font-weight: 400; }
.presence { padding: 0 12px 16px; border-bottom: 1px solid var(--line-soft); }
.sidebar-section-title { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 8px; }
.sidebar-section-title h2 { margin: 0; color: #858585; font-size: 11px; font-weight: 720; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-section-title > span { color: #747474; font-size: 11px; }
.presence-list, .thread-list { margin: 0; padding: 0; list-style: none; }
.presence-list { display: grid; gap: 3px; }
.presence-item { display: grid; grid-template-columns: 9px minmax(0, 1fr); align-items: start; gap: 10px; border-radius: 9px; padding: 8px; }
.presence-item:hover { background: rgb(255 255 255 / 3%); }
.presence-item strong { display: block; overflow: hidden; color: #d8d8d8; font-size: 12px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.presence-item small { display: block; margin-top: 3px; color: #7f8185; font-size: 10px; line-height: 1.35; }
.presence-dot { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: #595959; }
.presence-idle, .presence-running, .presence-busy { background: var(--accent-strong); box-shadow: 0 0 7px rgb(185 239 93 / 45%); }
.presence-attention, .presence-waiting { background: var(--warning); }
.presence-paused { background: var(--info); }
.threads { min-height: 0; flex: 1; overflow-y: auto; padding: 16px 8px; scrollbar-color: #444 transparent; scrollbar-width: thin; }
.thread-list { display: grid; gap: 2px; }
.thread-link { display: grid; gap: 7px; border-radius: 9px; padding: 10px 12px; color: #cbcbcb; text-decoration: none; }
.thread-link:hover { background: #202020; }
.thread-link.is-active { background: #292929; color: #fff; }
.thread-title { overflow: hidden; font-size: 13px; font-weight: 550; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { display: flex; align-items: center; overflow: hidden; color: #818181; font-size: 10px; text-overflow: ellipsis; text-transform: capitalize; white-space: nowrap; }
.mini-status { width: 6px; height: 6px; flex: 0 0 auto; margin-right: 6px; border-radius: 50%; background: #666; }
.status-dot-running, .status-dot-completed { background: var(--accent-strong); }
.status-dot-queued, .status-dot-waiting { background: var(--warning); }
.status-dot-failed { background: var(--danger); }
.sidebar-empty { margin: 8px 12px; color: #737373; font-size: 12px; }
.sidebar-footer { flex: 0 0 auto; border-top: 1px solid var(--line-soft); padding: 8px; }
.settings { position: relative; }
.settings > summary { display: flex; min-height: 38px; align-items: center; gap: 9px; border-radius: 8px; padding: 0 9px; color: #a8a8a8; font-size: 12px; list-style: none; }
.settings > summary::-webkit-details-marker { display: none; }
.settings > summary:hover { background: #222; color: #ddd; }
.settings-panel { position: absolute; right: 2px; bottom: calc(100% + 8px); left: 2px; max-height: min(420px, 60vh); overflow: auto; border: 1px solid #383838; border-radius: 12px; background: #222; padding: 14px; box-shadow: 0 18px 50px rgb(0 0 0 / 45%); }
.settings-label { margin: 0 0 8px; color: #808080; font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.settings-worker { display: grid; gap: 5px; border-top: 1px solid #343434; padding: 10px 0; }
.settings-worker strong { font-size: 12px; }
.settings-worker span { display: flex; gap: 12px; }
.settings-worker a { color: var(--accent); font-size: 11px; text-decoration: none; }
.settings-worker a:hover { text-decoration: underline; }
.policy-list { margin: 6px 0 0; }
.policy-list div { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid #343434; padding: 8px 0; font-size: 10px; }
.policy-list dt { color: #888; }
.policy-list dd { margin: 0; text-align: right; }
.account-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 42px; border-radius: 8px; padding: 4px 6px; font-size: 12px; }
.account-avatar { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 8px; background: #333; font-size: 11px; font-weight: 750; }
.account-row form { margin: 0; }
.sign-out { border: 0; background: transparent; color: #888; padding: 5px; font-size: 10px; }
.sign-out:hover { color: #ddd; }
.sidebar-scrim { display: none; }

/* Conversation workspace */
.workspace { display: grid; min-width: 0; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; background: var(--background); }
.mobile-bar { display: none; }
.task-stage { min-height: 0; overflow-y: auto; scroll-behavior: smooth; scrollbar-color: #454545 transparent; scrollbar-width: thin; }
.conversation { width: min(820px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 72px; }
.conversation-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line-soft); padding-bottom: 28px; }
.conversation-head h1 { margin: 15px 0 0; font-size: clamp(24px, 3vw, 32px); line-height: 1.12; letter-spacing: -.035em; }
.conversation-kicker { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #3a3a3a; border-radius: 99px; padding: 5px 8px; color: #bcbcbc; font-size: 10px; font-weight: 750; text-transform: capitalize; white-space: nowrap; }
.status i { width: 6px; height: 6px; border-radius: 50%; background: #686868; }
.status-running i, .status-completed i, .status-busy i, .status-idle i { background: var(--accent-strong); }
.status-queued i, .status-waiting i { background: var(--warning); }
.status-failed i { background: var(--danger); }
.status-paused i { background: var(--info); }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; margin-top: 3px; color: #7f817d; font-size: 11px; }
.live-indicator i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-strong); animation: pulse 2.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.message-block { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; margin-top: 34px; }
.message-avatar { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 9px; background: #303030; color: #ddd; font-size: 11px; font-weight: 750; }
.message-block h2, .activity-heading h2 { margin: 1px 0 7px; color: #aaa; font-size: 11px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.message-block p { max-width: 700px; margin: 0; color: #dfdfdf; font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.activity-block { margin: 44px 0 0 48px; }
.activity-heading { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); padding-bottom: 10px; }
.activity-heading h2 { margin: 0; }
.activity-heading span { color: #696969; font-size: 10px; }
.activity-list { margin: 0; padding: 16px 0 0; list-style: none; }
.activity-list li { position: relative; display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 11px; min-height: 47px; padding-bottom: 13px; }
.activity-list li::before { position: absolute; top: 11px; bottom: -1px; left: 4px; width: 1px; background: #333; content: ""; }
.activity-list li:last-child::before { display: none; }
.activity-list li > i { position: relative; z-index: 1; width: 9px; height: 9px; margin-top: 5px; border: 2px solid var(--background); border-radius: 50%; background: #6d6d6d; box-shadow: 0 0 0 1px #565656; }
.activity-list .activity-completed > i, .activity-list .activity-progress > i { background: var(--accent-strong); box-shadow: 0 0 0 1px #718d41; }
.activity-list .activity-error > i, .activity-list .activity-failed > i { background: var(--danger); }
.activity-list li p { margin: 0; color: #c9c9c9; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.activity-list time { display: block; margin-top: 4px; color: #666; font-size: 10px; }
.result-card { margin: 36px 0 0 48px; border: 1px solid #354225; border-radius: var(--radius); background: linear-gradient(145deg, #1b2017, #171917); padding: 22px; }
.result-card > span { color: var(--accent-strong); font-size: 10px; font-weight: 760; letter-spacing: .09em; text-transform: uppercase; }
.result-card h2 { margin: 8px 0 12px; font-size: 17px; letter-spacing: -.02em; }
.result-card p { margin: 0; color: #d2d4cf; font-size: 14px; line-height: 1.65; white-space: pre-wrap; }
.result-error { border-color: #543131; background: #231919; }
.result-error > span { color: var(--danger); }
.response-pending { display: flex; align-items: center; gap: 12px; margin: 32px 0 0 48px; color: #858585; font-size: 12px; }
.response-pending p { margin: 0; }
.typing-dots { display: flex; gap: 3px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: #898989; animation: dots 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 50% { transform: translateY(-3px); opacity: .45; } }
.welcome-state { display: grid; width: min(650px, calc(100% - 48px)); min-height: 100%; place-content: center; justify-items: center; margin: 0 auto; padding: 60px 0 90px; text-align: center; }
.welcome-symbol { display: grid; width: 52px; height: 52px; place-items: center; margin-bottom: 24px; border: 1px solid #39432d; border-radius: 15px; background: #20251b; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 18px; }
.welcome-state h1 { margin-bottom: 12px; font-size: clamp(29px, 5vw, 42px); letter-spacing: -.045em; }
.welcome-state p { max-width: 500px; color: var(--muted); line-height: 1.6; }
.button-secondary { min-height: 41px; margin-top: 9px; border: 1px solid #3d3d3d; border-radius: 10px; background: #222; color: #e6e6e6; padding: 8px 14px; font-weight: 650; }
.button-secondary:hover { background: #2a2a2a; }

/* Composer */
.composer-wrap { position: relative; z-index: 5; padding: 14px max(24px, calc((100% - 820px) / 2)) 16px; background: linear-gradient(transparent, var(--background) 17%); }
.composer { overflow: hidden; border: 1px solid #3a3a3a; border-radius: 17px; background: #202020; box-shadow: 0 13px 34px rgb(0 0 0 / 25%); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #586847; box-shadow: 0 0 0 3px rgb(185 239 93 / 6%), 0 13px 34px rgb(0 0 0 / 25%); }
.composer textarea { display: block; width: 100%; border: 0; background: transparent; color: #eee; }
.composer textarea { min-height: 62px; max-height: 180px; resize: none; padding: 12px 15px 7px; font-size: 14px; line-height: 1.45; }
.composer textarea::placeholder { color: #777; }
.composer-actions { display: flex; align-items: center; gap: 8px; min-height: 45px; padding: 6px 8px 8px; }
.composer-actions select { min-height: 31px; max-width: 180px; border: 1px solid #3a3a3a; border-radius: 8px; background: #282828; color: #bfc0bd; padding: 4px 26px 4px 9px; font-size: 11px; }
.composer-state { min-width: 0; flex: 1; overflow: hidden; color: #8e9f75; font-size: 10px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.composer-state.is-error { color: var(--danger); }
.send-button { display: inline-flex; min-height: 33px; align-items: center; gap: 8px; border: 0; border-radius: 9px; background: var(--accent); color: var(--accent-ink); padding: 6px 9px 6px 12px; font-size: 11px; font-weight: 800; }
.send-button:hover { background: #e3ffa9; }
.send-button:disabled { cursor: wait; opacity: .55; }
.send-button i { display: grid; width: 18px; height: 18px; place-items: center; border-radius: 6px; background: rgb(0 0 0 / 13%); font-style: normal; }
.composer-help { margin: 7px 10px 0; color: #626262; font-size: 9px; line-height: 1.35; text-align: center; }
.toast { position: fixed; z-index: 90; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 48px)); border: 1px solid #404040; border-radius: 11px; background: #282828; padding: 11px 14px; box-shadow: 0 15px 45px rgb(0 0 0 / 40%); color: #ddd; font-size: 12px; }

@media (max-width: 840px) {
  .dashboard-page { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(var(--sidebar-width), calc(100vw - 44px)); transform: translateX(-105%); box-shadow: 18px 0 60px rgb(0 0 0 / 40%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: grid; }
  .sidebar-scrim { position: fixed; z-index: 15; inset: 0; display: block; visibility: hidden; background: rgb(0 0 0 / 58%); opacity: 0; transition: opacity .2s, visibility .2s; }
  body.sidebar-open .sidebar-scrim { visibility: visible; opacity: 1; }
  .workspace { height: 100dvh; grid-template-rows: 54px minmax(0, 1fr) auto; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); padding: 0 12px; background: rgb(16 16 16 / 92%); backdrop-filter: blur(15px); color: #cacaca; font-size: 12px; font-weight: 680; }
  .mobile-status { display: grid; min-width: 25px; min-height: 25px; place-items: center; border: 1px solid #363636; border-radius: 8px; color: #929292; font-size: 10px; }
  .conversation { width: min(100% - 30px, 720px); padding-top: 28px; }
  .composer-wrap { padding-right: 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); padding-left: 12px; }
}

@media (max-width: 560px) {
  .conversation-head { gap: 10px; padding-bottom: 20px; }
  .conversation-head h1 { font-size: 27px; }
  .live-indicator { font-size: 0; }
  .message-block { margin-top: 25px; }
  .activity-block, .result-card, .response-pending { margin-left: 0; }
  .composer-actions { flex-wrap: wrap; }
  .composer-actions label { max-width: calc(50% - 4px); }
  .composer-actions select { width: 100%; max-width: 100%; }
  .composer-state { order: 3; min-width: calc(100% - 76px); text-align: left; }
  .send-button { margin-left: auto; }
  .composer-help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
