:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #101318;
  --surface-2: #15191f;
  --surface-3: #1b2027;
  --line: #262d35;
  --line-strong: #353e48;
  --text: #edf2f6;
  --muted: #8f9aa6;
  --faint: #68727d;
  --accent: #d8ff6b;
  --accent-ink: #1b2600;
  --blue: #7db7ff;
  --orange: #ffb45c;
  --red: #ff7878;
  --green: #80e29b;
  --shadow: 0 24px 80px rgba(0, 0, 0, .45);
  --topbar: 52px;
  --mobile-nav: 0px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mobile-only { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 20% 5%, rgba(216, 255, 107, .07), transparent 26rem),
    radial-gradient(circle at 90% 90%, rgba(125, 183, 255, .055), transparent 28rem),
    var(--bg);
}

.auth-card {
  width: min(100%, 430px);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(150deg, rgba(24, 29, 35, .95), rgba(13, 16, 20, .98));
  box-shadow: var(--shadow);
}

.brand-mark, .brand-mini {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.brand-mark { width: 58px; height: 58px; margin-bottom: 30px; border-radius: 16px; font-size: 21px; }
.brand-mini { width: 27px; height: 27px; border-radius: 8px; font-size: 11px; }
.brand-inline { display: flex; align-items: center; gap: 10px; margin-right: 6px; }
.auth-card h1 { margin: 6px 0 10px; font-size: clamp(28px, 5vw, 38px); letter-spacing: -.035em; }
.auth-card form { display: grid; gap: 10px; margin-top: 28px; }
.auth-card label, .account-card label { margin-top: 6px; color: #cdd4da; font-size: 13px; font-weight: 650; }
.auth-card input {
  width: 100%;
  min-height: 47px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #0d1014;
  color: var(--text);
}
.auth-card input:hover { border-color: #46515d; }
.auth-card input:focus { border-color: var(--accent); }
.session-note { margin: 18px 0 0; color: var(--faint); font-size: 11px; line-height: 1.5; }
.form-error { min-height: 20px; margin: 4px 0 0; color: var(--red); font-size: 13px; }
.fatal { padding: 40px; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-weight: 680;
}
button:hover { background: rgba(255, 255, 255, .055); }
button:disabled { cursor: not-allowed; opacity: .45; }
.primary { padding: 0 15px; background: var(--accent); color: var(--accent-ink); }
.primary:hover { background: #e4ff92; }
.wide { width: 100%; min-height: 46px; }
.quiet { padding: 0 11px; border-color: var(--line); background: var(--surface-2); color: #d9e0e5; }
.quiet:hover { border-color: var(--line-strong); background: var(--surface-3); }
.danger { padding: 0 15px; border-color: rgba(255, 120, 120, .4); background: rgba(255, 120, 120, .13); color: #ffaaaa; }
.danger-quiet { color: #ff9a9a; }
.warning { padding: 0 14px; background: var(--orange); color: #321c00; }
.icon-button { width: 36px; padding: 0; border-color: var(--line); color: var(--muted); }

.desktop { height: 100vh; min-height: 0; background: var(--bg); }
.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 16, .95);
}
.topbar-left, .topbar-actions, .resource-strip { display: flex; align-items: center; min-width: 0; }
.topbar-left { gap: 9px; overflow: hidden; }
.topbar-actions { gap: 8px; }
.divider { width: 1px; height: 20px; background: var(--line); }
.top-context { overflow: hidden; max-width: 180px; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(255,120,120,.1); }
.status-badge.online { color: var(--green); }
.status-badge.online .status-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(128,226,155,.1); }
.resource-strip { gap: 14px; color: var(--faint); font-size: 10px; letter-spacing: .02em; }
.resource-strip strong { margin-left: 4px; color: #bfc8d0; }

.workspace {
  height: calc(100vh - var(--topbar));
  min-height: 0;
  display: grid;
  grid-template-columns: 248px minmax(420px, 1fr) minmax(310px, 355px);
}

.sidebar, .inspector, .conversation { min-width: 0; min-height: 0; background: var(--surface); }
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding: 17px 11px 10px;
}
.sidebar-head, .thread-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.sidebar h2, .conversation h2 { margin: 0; font-size: 14px; letter-spacing: -.01em; }
.project-list { display: grid; gap: 4px; margin-top: 11px; max-height: 31%; overflow: auto; }
.project-button, .thread-button {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 9px;
  color: #cbd3d9;
  text-align: left;
}
.project-button:hover, .thread-button:hover { background: var(--surface-2); }
.project-button.active, .thread-button.active { background: var(--surface-3); color: var(--text); }
.project-icon { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 7px; background: #202731; color: var(--blue); font-size: 12px; }
.project-copy, .thread-copy { min-width: 0; }
.project-copy strong, .thread-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.project-copy span, .thread-copy span { display: block; overflow: hidden; margin-top: 2px; color: var(--faint); text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 500; }
.thread-heading { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--line); }
.new-thread { width: 31px; min-height: 31px; border: 1px solid var(--line); color: var(--accent); font-size: 19px; line-height: 1; }
.thread-list { flex: 1; min-height: 0; overflow: auto; margin-top: 8px; }
.thread-button { grid-template-columns: 14px minmax(0, 1fr); padding: 8px 9px; }
.thread-dot { width: 7px; height: 7px; border: 1px solid var(--faint); border-radius: 50%; }
.thread-button.running .thread-dot { border: 0; background: var(--green); }
.thread-button.approval-pending .thread-dot { border: 0; background: #f3b63f; box-shadow: 0 0 0 3px rgb(243 182 63 / 12%); }
.sidebar-foot { padding: 10px 8px 2px; border-top: 1px solid var(--line); color: var(--faint); font-size: 10px; }

.conversation { display: grid; grid-template-rows: 58px minmax(0, 1fr) auto auto; background: #0e1115; }
.conversation-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.conversation-actions { display: flex; align-items: center; gap: 9px; }
.turn-state { color: var(--faint); font-size: 11px; }
.turn-state.working { color: var(--green); }
.message-list { overflow: auto; padding: 24px max(20px, calc((100% - 780px) / 2)); scroll-behavior: smooth; }
.empty-state { max-width: 440px; margin: 15vh auto 0; color: var(--muted); text-align: center; }
.empty-state h3 { margin: 13px 0 6px; color: var(--text); font-size: 21px; }
.empty-state p { margin: 0; line-height: 1.6; font-size: 13px; }
.empty-glyph { color: var(--accent); font-size: 31px; }

.message { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 11px; margin: 0 0 21px; }
.message-avatar { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 800; }
.message.user .message-avatar { background: rgba(216,255,107,.1); color: var(--accent); }
.message-body { min-width: 0; }
.message-meta { display: flex; align-items: center; gap: 8px; height: 25px; color: var(--faint); font-size: 10px; }
.message-meta strong { color: #cad2d9; font-size: 11px; }
.message-content { color: #dfe5ea; font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.message.user .message-content { display: inline-block; padding: 11px 14px; border: 1px solid var(--line); border-radius: 4px 13px 13px 13px; background: var(--surface-2); }
.reasoning-card, .tool-card {
  margin: 8px 0 14px 41px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(21, 25, 31, .72);
  color: var(--muted);
  font-size: 12px;
}
.reasoning-card strong, .tool-card strong { display: block; margin-bottom: 6px; color: #c9d1d8; font-size: 11px; }
.reasoning-card p { margin: 0; white-space: pre-wrap; line-height: 1.55; }

.approval-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 16px; border-top: 1px solid rgba(255,180,92,.3); background: rgba(255,180,92,.08); }
.approval-banner div { display: grid; gap: 2px; min-width: 0; font-size: 11px; }
.approval-banner span { overflow: hidden; color: #c59c6a; text-overflow: ellipsis; white-space: nowrap; }

.composer { padding: 12px max(16px, calc((100% - 820px) / 2)) 14px; border-top: 1px solid var(--line); background: #0c0f12; }
.composer textarea { width: 100%; min-height: 58px; max-height: 180px; resize: none; padding: 13px 14px; border: 1px solid var(--line-strong); border-radius: 13px 13px 8px 8px; background: var(--surface-2); color: var(--text); line-height: 1.45; }
.composer textarea:focus { border-color: #53606c; outline: 0; }
.composer-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 7px; }
.selectors, .send-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.selectors label { display: flex; align-items: center; min-width: 0; }
.selectors label > span { display: none; }
.selectors select { max-width: 155px; height: 33px; padding: 0 24px 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: #bfc8cf; font-size: 10px; }
.permission-chip { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--faint); font-size: 10px; white-space: nowrap; }

.inspector { border-left: 1px solid var(--line); display: grid; grid-template-rows: auto minmax(0, 1fr); }
.inspector-head { display: flex; align-items: center; border-bottom: 1px solid var(--line); overflow: hidden; }
.tabs { display: flex; width: 100%; overflow-x: auto; padding: 0 8px; }
.tabs button { min-width: max-content; padding: 0 9px; border: 0; border-radius: 0; color: var(--faint); font-size: 10px; }
.tabs button.active { box-shadow: inset 0 -2px var(--accent); color: var(--text); }
.panel { display: none; min-height: 0; overflow: auto; }
.panel.active { display: block; }
.activity-list, .test-results { padding: 12px; }
.panel-empty { margin: 18px 10px; color: var(--faint); font-size: 11px; line-height: 1.6; }
.activity-item { display: grid; grid-template-columns: 23px minmax(0, 1fr); gap: 9px; padding: 10px 5px; border-bottom: 1px solid rgba(38,45,53,.75); }
.activity-icon { display: grid; place-items: center; width: 23px; height: 23px; border-radius: 6px; background: var(--surface-3); color: var(--blue); font-size: 10px; }
.activity-copy { min-width: 0; }
.activity-copy strong { display: block; color: #cdd5dc; font-size: 10px; }
.activity-copy span { display: block; overflow: hidden; margin-top: 4px; color: var(--faint); text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; }
.code-output { min-height: 100%; margin: 0; padding: 15px; overflow: auto; background: #0b0e11; color: #b7c1c9; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; line-height: 1.58; white-space: pre-wrap; word-break: break-word; }
.file-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px; border-bottom: 1px solid var(--line); }
.file-toolbar span { overflow: hidden; color: var(--faint); text-overflow: ellipsis; white-space: nowrap; font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.file-list { padding: 6px; }
.file-entry { width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 8px; color: #bdc6ce; text-align: left; font-size: 10px; }
.file-entry span:first-child { width: 16px; color: var(--blue); }
.file-entry span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.test-item { padding: 10px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 8px; background: var(--surface-2); font-size: 10px; }
.test-item.pass { border-color: rgba(128,226,155,.25); }
.test-item.fail { border-color: rgba(255,120,120,.28); }

.modal { width: min(92vw, 540px); padding: 0; border: 1px solid var(--line-strong); border-radius: 17px; background: transparent; color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(3, 5, 7, .75); backdrop-filter: blur(6px); }
.modal-card { position: relative; padding: 26px; border-radius: 16px; background: var(--surface); }
.modal-card h2 { margin: 5px 0 9px; font-size: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.approval-command { max-height: 260px; margin: 17px 0 0; padding: 13px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #090c0f; color: #c6d0d8; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 34px; font-size: 20px; color: var(--faint); }
.account-card { display: grid; gap: 12px; }
.account-card h2, .account-card p { margin-top: 0; }
.device-link { display: block; overflow: hidden; color: var(--blue); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.device-code { width: 100%; min-height: 62px; border: 1px dashed #53606c; background: #0b0e11; color: var(--accent); font: 700 25px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }
.connection-status { color: var(--orange); font-size: 12px; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: 360px; padding: 11px 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: #171c22; box-shadow: 0 12px 40px rgba(0,0,0,.4); color: #dce3e8; font-size: 11px; }
.mobile-nav { display: none; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 226px minmax(390px, 1fr) 310px; }
  .resource-strip { display: none; }
  .selectors select { max-width: 125px; }
}

@media (max-width: 860px) {
  :root { --mobile-nav: 0px; }
  .mobile-only { display: inline-flex !important; align-items: center; justify-content: center; }
  .workspace { grid-template-columns: minmax(0, 1fr); position: relative; }
  .sidebar, .inspector { position: fixed; top: var(--topbar); bottom: 0; z-index: 40; box-shadow: var(--shadow); }
  .sidebar { left: 0; width: min(82vw, 310px); transform: translateX(-105%); transition: transform .16s ease; }
  .sidebar.open { transform: translateX(0); }
  .inspector { right: 0; width: min(92vw, 420px); transform: translateX(105%); transition: transform .16s ease; }
  .inspector.open { transform: translateX(0); }
  .conversation { grid-column: 1; }
  .top-context { max-width: 130px; }
  .permission-chip { display: none; }
}

@media (max-width: 600px) {
  :root { --topbar: 49px; --mobile-nav: calc(57px + env(safe-area-inset-bottom)); }
  body { min-height: 100dvh; }
  .desktop { height: 100dvh; }
  .topbar { height: var(--topbar); padding: 0 9px; }
  .brand-inline strong, .divider, #topBranch, .topbar-actions .quiet { display: none; }
  .topbar-actions #connectAccountButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }
  .topbar-actions #connectAccountButton::before { content: '◎'; font-size: 17px; }
  .top-context { max-width: 42vw; }
  .workspace { height: calc(100dvh - var(--topbar) - var(--mobile-nav)); }
  .sidebar, .inspector { bottom: var(--mobile-nav); }
  .conversation { grid-template-rows: 52px minmax(0, 1fr) auto auto; }
  .conversation-head { padding: 0 12px; }
  .conversation-head h2 { max-width: 64vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .message-list { padding: 18px 13px; }
  .empty-state { margin-top: 10vh; }
  .composer { padding: 9px 9px max(9px, env(safe-area-inset-bottom)); }
  .composer textarea { min-height: 54px; }
  .composer-controls { align-items: flex-end; }
  .selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; flex: 1; }
  .selectors label:nth-child(3) { display: none; }
  .selectors select { width: 100%; max-width: none; }
  .send-actions { align-self: stretch; }
  .send-actions button { min-height: 100%; }
  .message { grid-template-columns: 26px minmax(0, 1fr); gap: 8px; }
  .message-avatar { width: 26px; height: 26px; border-radius: 7px; }
  .reasoning-card, .tool-card { margin-left: 34px; }
  .approval-banner { padding: 8px 10px; }
  .approval-banner span { max-width: 58vw; }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: var(--mobile-nav);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 4px 4px max(4px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #0b0e11;
  }
  .mobile-nav button { display: grid; place-items: center; gap: 1px; min-height: 45px; border-radius: 8px; color: var(--faint); font-size: 9px; }
  .mobile-nav button span { font-size: 15px; }
  .mobile-nav button.active { color: var(--accent); background: rgba(216,255,107,.055); }
  .auth-card { padding: 29px 22px; border-radius: 18px; }
  .brand-mark { margin-bottom: 22px; }
  .modal { width: calc(100vw - 18px); max-height: 88dvh; }
  .modal-card { padding: 22px 17px; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-actions .primary { grid-column: 1 / -1; grid-row: 1; }
  .toasts { right: 9px; bottom: calc(var(--mobile-nav) + 9px); left: 9px; }
}

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