:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --text: #18181b;
  --muted: #71717a;
  --accent: #ea580c;
  --accent-press: #c2410c;
  --accent-glow: rgba(234,88,12,0.15);
  --bar: #18181b;
  --bar-text: #fafafa;
  --border: #e4e4e7;
  --shadow: 0 1px 2px rgba(24,24,27,0.04), 0 8px 24px rgba(24,24,27,0.06);
  --radius: 18px;
  --radius-sm: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b; --surface: #18181b; --surface-2: #27272a;
    --text: #fafafa; --muted: #a1a1aa; --accent: #f97316; --accent-press: #ea580c;
    --bar: #000000; --bar-text: #fafafa; --border: #27272a;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { display: flex; align-items: center; justify-content: center; }
.screen { min-height: 100dvh; }

/* Buttons */
.btn {
  border: none; border-radius: 980px; padding: 11px 20px; font-size: 15px;
  font-weight: 500; cursor: pointer; transition: transform .12s ease, background .2s ease;
  background: var(--surface-2); color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.small { padding: 6px 14px; font-size: 13px; }
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 20px;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: var(--border); }
.btn.wide { width: 100%; }

/* Agents modal */
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(640px, 100%); max-height: 90dvh; display: flex; flex-direction: column;
}
.modal-head, .modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.modal-foot { border-bottom: none; border-top: 1px solid var(--border); gap: 12px; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.agents-row { display: flex; gap: 10px; align-items: center; }
.agents-row select {
  flex: 1; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical;
}
.tool-toggles { display: flex; flex-direction: column; gap: 8px; }
.tool-toggle {
  display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text);
  background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.tool-toggle input { margin-top: 2px; accent-color: var(--accent); }
.example-row { display: flex; gap: 8px; margin-bottom: 8px; }
.example-row input {
  flex: 1; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px;
}
.example-row .ex-del { width: 32px; height: 32px; font-size: 14px; flex: none; }
.save-status { font-size: 13px; color: var(--muted); font-weight: 400; }

/* Sign-in */
#signin { background: var(--bar); }
.signin-card {
  background: transparent; text-align: center; width: min(360px, 86vw);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.signin-card .logo-img { width: 200px; max-width: 70vw; height: auto; margin-bottom: 8px; }
.signin-sub { color: #a1a1aa; margin: 0 0 28px; font-size: 15px; letter-spacing: .01em; }
.signin-card .btn { width: 100%; }

/* App shell */
#app { height: 100dvh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: 300px 1fr;
       grid-template-areas: "top top" "side chat"; }
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--bar); color: var(--bar-text);
  position: sticky; top: 0; z-index: 20;
}
.topbar-logo { height: 26px; width: auto; flex: 1; object-fit: contain; object-position: center; }
.topbar .icon-btn { color: var(--bar-text); }
.topbar .icon-btn:active { background: rgba(255,255,255,0.12); }
.topbar #menu-btn { display: none; }

.sidebar {
  grid-area: side; border-right: 1px solid var(--border); overflow-y: auto;
  background: var(--surface-2); padding: 8px;
  display: flex; flex-direction: column;
}
.sidebar .session-list { flex: 1; overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.session-list { list-style: none; margin: 0; padding: 0; }
.session-item {
  padding: 12px 14px; border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 4px;
  transition: background .15s ease; border: 1px solid transparent;
}
.session-item:hover { background: var(--surface); }
.session-item.active { background: var(--surface); border-color: var(--border); box-shadow: inset 3px 0 0 var(--accent); }
.session-item .si-title { font-size: 15px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.session-item .si-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge { font-size: 10px; padding: 1px 7px; border-radius: 980px; background: var(--border);
  color: var(--muted); margin-left: 6px; vertical-align: middle; }
.badge.web { background: var(--accent); color: #fff; }

/* Chat */
.chat { grid-area: chat; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px clamp(16px, 6vw, 80px);
  display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; }
.bubble { max-width: min(680px, 92%); padding: 13px 16px; border-radius: var(--radius);
  font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--shadow); animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff;
  border-bottom-right-radius: 6px; }
.bubble.boss { align-self: flex-start; background: var(--surface);
  border-bottom-left-radius: 6px; }
.bubble.boss pre { margin: 0; white-space: pre-wrap; font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 13px; }
.bubble .b-meta { font-size: 11px; color: var(--muted); margin-top: 6px; }

.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 18px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.composer { display: flex; gap: 10px; padding: 12px clamp(16px, 6vw, 80px);
  padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: saturate(180%) blur(20px); }
.prompt-input { flex: 1; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 980px; padding: 13px 20px; font-size: 16px; outline: none;
  transition: border-color .2s ease; }
.prompt-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }
.send { width: 46px; height: 46px; border-radius: 50%; padding: 0; font-size: 20px; flex: 0 0 auto; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 15; }

/* Mobile */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "chat"; }
  .topbar #menu-btn { display: block; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 82vw; max-width: 320px;
    z-index: 16; transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
    padding-top: max(8px, env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
}
