:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #181816;
  --panel-raised: #20201d;
  --panel-soft: #292925;
  --line: #32322d;
  --line-bright: #45453f;
  --text: #f1efe7;
  --muted: #99978d;
  --faint: #6f6d65;
  --accent: #d9ff72;
  --accent-ink: #161811;
  --danger: #ff8f82;
  --warn: #f5c96a;
  --sidebar-width: 320px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.login-view {
  min-height: 100%; display: grid; place-items: center; padding: 28px;
  background:
    radial-gradient(circle at 15% 15%, rgba(217, 255, 114, .1), transparent 24rem),
    radial-gradient(circle at 80% 90%, rgba(255, 255, 255, .055), transparent 30rem), var(--bg);
}
.login-card { width: min(100%, 500px); padding: 46px; border: 1px solid var(--line); border-radius: 24px; background: rgba(25, 25, 22, .88); box-shadow: 0 28px 90px rgba(0, 0, 0, .36); backdrop-filter: blur(24px); }
.brand-mark, .mini-mark { display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.brand-mark { width: 50px; height: 50px; margin-bottom: 32px; font-size: 24px; }
.mini-mark { width: 28px; height: 28px; font-size: 14px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font: 650 11px/1.2 ui-monospace, "SFMono-Regular", monospace; letter-spacing: .14em; }
.login-card h1 { margin: 0; font-size: clamp(34px, 8vw, 48px); letter-spacing: -.045em; }
.login-copy { margin: 14px 0 32px; color: var(--muted); line-height: 1.65; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
input, textarea, select { width: 100%; border: 1px solid var(--line-bright); border-radius: 12px; outline: 0; background: #121210; color: var(--text); }
input, select { min-height: 46px; padding: 0 13px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217, 255, 114, .1); }
.token-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.primary, .secondary { min-height: 44px; padding: 0 18px; border-radius: 11px; cursor: pointer; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.primary:hover { filter: brightness(1.05); }
.secondary { border: 1px solid var(--line-bright); background: transparent; }
.form-error { min-height: 18px; margin: 9px 0 0; color: var(--danger); font-size: 12px; }
.secure-note { margin: 28px 0 0; color: var(--faint); font-size: 11px; }
.secure-note span { color: var(--accent); margin-right: 6px; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; height: 100dvh; }
.sidebar { display: flex; min-width: 0; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: max(18px, env(safe-area-inset-top)) 18px 14px; }
.wordmark { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.02em; }
.icon-button { display: grid; width: 36px; height: 36px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: transparent; cursor: pointer; font-size: 20px; }
.icon-button:hover { border-color: var(--line-bright); background: var(--panel-soft); }
.search-box { display: flex; align-items: center; gap: 8px; margin: 4px 14px 16px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; background: #141412; color: var(--faint); }
.search-box input { min-height: 38px; padding: 0; border: 0; box-shadow: none; background: transparent; font-size: 13px; }
.nav-scroll { min-height: 0; flex: 1; overflow-y: auto; padding: 0 9px 20px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 7px; color: var(--faint); font: 650 10px/1 ui-monospace, "SFMono-Regular", monospace; letter-spacing: .12em; text-transform: uppercase; }
.text-button { padding: 3px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.text-button:hover { color: var(--text); }
.project-button, .thread-button { width: 100%; border: 0; text-align: left; cursor: pointer; }
.project-button { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; }
.project-button:hover, .project-button.active { background: var(--panel-soft); color: var(--text); }
.project-icon { display: grid; width: 27px; height: 27px; place-items: center; border: 1px solid var(--line); border-radius: 7px; font: 700 11px/1 ui-monospace, monospace; }
.project-count { color: var(--faint); font-size: 11px; }
.thread-section { margin-top: 12px; }
.thread-button { position: relative; display: block; padding: 11px 10px 11px 14px; border-radius: 9px; background: transparent; }
.thread-button:hover { background: #22221f; }
.thread-button.active { background: var(--panel-soft); }
.thread-button.active::before { position: absolute; top: 12px; bottom: 12px; left: 3px; width: 2px; border-radius: 2px; background: var(--accent); content: ""; }
.thread-name { display: block; overflow: hidden; color: #d9d7cf; font-size: 13px; font-weight: 530; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { display: flex; gap: 8px; margin-top: 5px; color: var(--faint); font: 10px/1.2 ui-monospace, monospace; }
.sidebar-footer { display: flex; align-items: center; gap: 8px; padding: 13px 18px max(13px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 201, 106, .08); }
.connection-dot.online { background: var(--accent); box-shadow: 0 0 0 3px rgba(217, 255, 114, .08); }
.connection-dot.offline { background: var(--danger); }
.footer-action { margin-left: auto; }

.workspace { position: relative; display: grid; min-width: 0; grid-template-rows: auto 1fr auto; background: var(--bg); }
.topbar { display: flex; min-width: 0; align-items: center; gap: 12px; padding: max(16px, env(safe-area-inset-top)) 24px 14px; border-bottom: 1px solid var(--line); background: rgba(17, 17, 15, .9); backdrop-filter: blur(16px); }
.thread-identity { min-width: 0; flex: 1; }
.thread-identity h1 { overflow: hidden; margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.015em; text-overflow: ellipsis; white-space: nowrap; }
.thread-identity p { overflow: hidden; margin: 4px 0 0; color: var(--faint); font: 10px/1.2 ui-monospace, monospace; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.status-pill { padding: 5px 8px; border: 1px solid rgba(217, 255, 114, .25); border-radius: 999px; background: rgba(217, 255, 114, .07); color: var(--accent); font: 10px/1 ui-monospace, monospace; }
.stop-button { width: 32px; height: 32px; border: 1px solid rgba(255, 143, 130, .3); border-radius: 9px; background: rgba(255, 143, 130, .08); color: var(--danger); cursor: pointer; }
.conversation { min-height: 0; overflow-y: auto; }
.transcript { width: min(100%, 880px); margin: 0 auto; padding: 40px 32px 120px; }
.message { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; margin-bottom: 26px; }
.message-avatar { display: grid; width: 28px; height: 28px; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font: 700 11px/1 ui-monospace, monospace; }
.message.agent .message-avatar { border-color: rgba(217, 255, 114, .35); color: var(--accent); }
.message-copy { min-width: 0; padding-top: 4px; color: #e8e6df; font-size: 14px; line-height: 1.72; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-copy { color: var(--muted); }
.tool-card { margin: 10px 0 18px 40px; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: #151513; }
.tool-card summary { display: flex; align-items: center; gap: 9px; padding: 10px 12px; color: var(--muted); cursor: pointer; font: 11px/1.45 ui-monospace, monospace; list-style: none; }
.tool-card summary::-webkit-details-marker { display: none; }
.tool-card summary::before { color: var(--accent); content: "›"; font-size: 16px; }
.tool-card[open] summary::before { transform: rotate(90deg); }
.tool-status { margin-left: auto; color: var(--faint); }
.tool-card pre { max-height: 340px; margin: 0; overflow: auto; padding: 12px; border-top: 1px solid var(--line); color: #aaa89f; font: 11px/1.55 ui-monospace, "SFMono-Regular", monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.reasoning-card { margin: 0 0 18px 40px; color: var(--faint); font-size: 12px; }
.reasoning-card summary { cursor: pointer; }
.turn-divider { margin: 34px 0; border: 0; border-top: 1px solid var(--line); }
.empty-state { display: grid; align-content: center; justify-items: center; min-height: 0; padding: 34px; text-align: center; }
.empty-orbit { display: grid; width: 84px; height: 84px; place-items: center; margin-bottom: 22px; border: 1px solid var(--line-bright); border-radius: 50%; box-shadow: inset 0 0 0 12px #151513, 0 0 80px rgba(217, 255, 114, .06); }
.empty-orbit span { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 800; }
.empty-state h2 { margin: 0; font-size: 24px; letter-spacing: -.04em; }
.empty-state p { max-width: 430px; margin: 12px 0 24px; color: var(--muted); line-height: 1.6; }
.composer { width: min(calc(100% - 40px), 840px); margin: 0 auto max(18px, env(safe-area-inset-bottom)); padding: 12px; border: 1px solid var(--line-bright); border-radius: 16px; background: rgba(31, 31, 28, .95); box-shadow: 0 14px 50px rgba(0, 0, 0, .34); backdrop-filter: blur(20px); }
.composer textarea { max-height: 200px; min-height: 30px; resize: none; padding: 4px; border: 0; background: transparent; box-shadow: none; line-height: 1.5; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; padding: 7px 0 0 4px; color: var(--faint); font-size: 10px; }
.send-button { width: 32px; height: 32px; border: 0; border-radius: 9px; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-size: 18px; font-weight: 800; }
.send-button:disabled { background: var(--panel-soft); color: var(--faint); cursor: default; }

.modal { width: min(calc(100% - 30px), 560px); padding: 0; border: 1px solid var(--line-bright); border-radius: 18px; background: var(--panel-raised); color: var(--text); box-shadow: 0 28px 90px #0009; }
.modal::backdrop { background: rgba(0, 0, 0, .68); backdrop-filter: blur(5px); }
.modal form { display: grid; gap: 18px; padding: 24px; }
.modal-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.modal-heading h2 { margin: 0; font-size: 21px; letter-spacing: -.03em; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 2px; }
.request-body { display: grid; gap: 14px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.request-body pre { max-height: 260px; margin: 0; overflow: auto; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #121210; color: var(--text); font: 11px/1.55 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.request-question { display: grid; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; }
.request-question strong { color: var(--text); }
.request-option { display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: start; cursor: pointer; }
.request-option input { width: auto; min-height: 0; margin-top: 3px; }
.request-option small { display: block; margin-top: 2px; color: var(--faint); }
.request-actions { flex-wrap: wrap; }
.danger-button { min-height: 40px; padding: 0 14px; border: 1px solid rgba(255, 143, 130, .3); border-radius: 10px; background: rgba(255, 143, 130, .08); color: var(--danger); cursor: pointer; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(400px, calc(100% - 40px)); padding: 12px 14px; border: 1px solid var(--line-bright); border-radius: 11px; background: var(--panel-raised); color: var(--text); box-shadow: 0 16px 50px #0008; font-size: 12px; }
.sidebar-scrim, .mobile-only { display: none; }

@media (max-width: 760px) {
  .login-card { padding: 30px 24px; }
  .token-row { grid-template-columns: 1fr; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: min(88vw, var(--sidebar-width)); transform: translateX(-102%); box-shadow: 30px 0 80px #0008; transition: transform .2s ease; }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 9; display: block; visibility: hidden; background: rgba(0, 0, 0, .56); opacity: 0; transition: opacity .2s, visibility .2s; }
  .app-shell.sidebar-open .sidebar-scrim { visibility: visible; opacity: 1; }
  .workspace { height: 100dvh; }
  .mobile-only { display: grid; flex: 0 0 auto; }
  .topbar { padding-right: 14px; padding-left: 14px; }
  .transcript { padding: 28px 17px 112px; }
  .message { grid-template-columns: 24px minmax(0, 1fr); gap: 9px; }
  .message-avatar { width: 24px; height: 24px; }
  .message-copy { font-size: 13px; line-height: 1.68; }
  .tool-card, .reasoning-card { margin-left: 33px; }
  .composer { width: calc(100% - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .status-pill { display: none; }
  .field-grid { grid-template-columns: 1fr; }
  .modal { max-height: calc(100dvh - 24px); overflow: auto; }
  .modal form { padding: 20px; }
}

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