:root {
  --bg: #0a0a0a;
  --bg-soft: #101012;
  --panel: #141416;
  --panel-2: #1a1a1d;
  --border: #232327;
  --border-soft: #1c1c1f;
  --text: #ececec;
  --text-dim: #9a9a9f;
  --text-faint: #6b6b70;
  --accent: #6d7cff;
  --accent-hover: #5b6bf0;
  --accent-soft: rgba(109, 124, 255, 0.14);
  --chip-bg: #1c1c1f;
  --chip-hover: #242428;
  --radius: 14px;
  --rail-w: 56px;
  --side-w: 264px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
textarea { font-family: inherit; }

#app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* ============ Icon rail ============ */
.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 6px;
}
.rail-logo { color: var(--text); margin-bottom: 10px; opacity: 0.9; }
.rail-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--text-dim);
  transition: background .12s, color .12s;
}
.rail-btn:hover { background: var(--chip-bg); color: var(--text); }
.rail-btn.active { background: var(--chip-bg); color: var(--text); }
.rail-spacer { flex: 1; }
.rail-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 600; font-size: 13px;
  margin-top: 8px;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--side-w);
  flex: 0 0 var(--side-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 4px;
  overflow: hidden;
}
.sidebar-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-dim);
  font-size: 13.5px; font-weight: 500;
  text-align: left;
  transition: background .12s, color .12s;
}
.side-link:hover { background: var(--chip-bg); color: var(--text); }
.side-link.active { background: var(--chip-bg); color: var(--text); }

.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-section.grow { flex: 1; overflow-y: auto; min-height: 40px; }
.side-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint);
  padding: 12px 10px 6px;
}
.side-empty { color: var(--text-faint); font-size: 13px; padding: 4px 10px; }
.recent-list { display: flex; flex-direction: column; gap: 1px; }
.recent-item {
  padding: 7px 10px; border-radius: 8px;
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.recent-item:hover { background: var(--chip-bg); color: var(--text); }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 10px; margin-top: 8px; }
.foot-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 9px; }
.foot-user:hover { background: var(--chip-bg); }
.foot-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 600; font-size: 12px;
}
.foot-meta { display: flex; flex-direction: column; line-height: 1.2; }
.foot-name { font-size: 13px; font-weight: 500; }
.foot-plan { font-size: 11.5px; color: var(--text-faint); }

/* ============ Canvas ============ */
.canvas {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas:
    "topbar"
    "scroll"
    "services"
    "composer";
  min-width: 0;
  background: var(--bg);
  position: relative;
  min-height: 0;
}
.topbar { grid-area: topbar; }
.canvas-scroll {
  grid-area: scroll;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}
.services { grid-area: services; }
.composer-wrap { grid-area: composer; }
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.welcome-title {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* ============ Demo badge ============ */
.demo-badge {
  margin-left: 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 3px 9px;
  vertical-align: 2px;
}
.hint-demo { color: var(--accent); font-weight: 600; }

/* ============ Messages ============ */
.messages { width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 24px 40px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 14px; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  flex: 0 0 30px; display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
}
.msg.user .msg-avatar { background: var(--panel-2); color: var(--text-dim); }
.msg.assistant .msg-avatar { background: var(--accent-soft); color: var(--accent); }
.msg-body { min-width: 0; flex: 1; padding-top: 4px; }
.msg-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.msg.user .msg-name { display: none; }
.msg-text { color: var(--text); white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text ul, .msg-text ol { margin: 0 0 10px 20px; }
.msg-text code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.msg-text pre {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}
.msg-text pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.6; }
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 0 -6px;
  font-size: 11.5px; color: var(--text-faint);
}
.code-copy { font-size: 11.5px; color: var(--text-faint); padding: 2px 8px; border-radius: 6px; }
.code-copy:hover { background: var(--chip-bg); color: var(--text); }
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
.caret { display: inline-block; color: var(--accent); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* ============ Composer ============ */
.composer-wrap {
  padding: 8px 24px 18px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.composer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: #34343a; box-shadow: 0 0 0 3px rgba(255,255,255,0.02); }
.composer textarea {
  width: 100%;
  background: none; border: none; outline: none; resize: none;
  color: var(--text); font-size: 15px; line-height: 1.5;
  max-height: 220px;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-bar {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; flex-wrap: wrap;
}
.composer-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--chip-bg);
  color: var(--text-dim);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12.5px; font-weight: 500;
  transition: background .12s, color .12s;
}
.chip:hover { background: var(--chip-hover); color: var(--text); }
.chip .chev { opacity: .6; }
.chip.model { background: transparent; color: var(--text-dim); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center; color: var(--text-dim);
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--chip-bg); color: var(--text); }
.send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  transition: background .12s, opacity .12s;
}
.send-btn:hover { background: #fff; }
.send-btn:disabled { opacity: .35; cursor: default; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--text-faint); margin-top: 10px; }

/* ============ Popover ============ */
.popover {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  padding: 6px;
  min-width: 240px;
  max-width: 320px;
  z-index: 100;
  max-height: 360px;
  overflow-y: auto;
}
.popover-title { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); padding: 8px 10px 6px; }
.popover-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; color: var(--text);
  cursor: pointer;
}
.popover-item:hover { background: var(--chip-bg); }
.popover-item .check { margin-left: auto; color: var(--accent); opacity: 0; }
.popover-item.selected .check { opacity: 1; }
.popover-item .meta { font-size: 11px; color: var(--text-faint); }

/* ============ Top bar (mode switch) ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}
.topbar-brand {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .01em;
}
.mode-switch {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.mode-btn {
  padding: 5px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: background .12s, color .12s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ============ Service chips (Chat mode) ============ */
.services {
  display: flex;
  gap: 8px;
  padding: 12px 24px 0;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  overflow-x: auto;
  flex: 0 0 auto;
}
.services::-webkit-scrollbar { height: 6px; }
.service-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 20px;
  background: var(--chip-bg);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.service-chip:hover {
  background: var(--chip-hover);
  color: var(--text);
}
.service-chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.service-chip svg { flex: 0 0 auto; }

/* ============ Welcome sub ============ */
.welcome-sub {
  font-size: 14px;
  color: var(--text-faint);
  margin-top: 8px;
  text-align: center;
}
.welcome { flex-direction: column; }

/* ============ Scrollbars ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2a2e; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #34343a; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar { display: none; }
}
@media (max-width: 640px) {
  .rail { width: 52px; flex-basis: 52px; }
  .welcome-title { font-size: 24px; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .canvas-scroll { scroll-behavior: auto; }
  .typing span, .caret { animation: none; }
  * { transition: none !important; }
}
