:root {
  --bg: #080b0d;
  --panel: #0d1114;
  --panel-soft: #11171b;
  --line: #20282d;
  --line-bright: #344047;
  --text: #e8efed;
  --muted: #84918e;
  --muted-strong: #aab6b3;
  --accent: #b6f36b;
  --accent-soft: rgba(182, 243, 107, 0.12);
  --accent-dim: #6f9440;
  --warning: #f1b85b;
  --danger: #ec7f74;
  --radius: 18px;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 18%, rgba(86, 131, 77, 0.08), transparent 27%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

.muted {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(8, 11, 13, 0.92);
  padding: 26px 20px 18px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 4px 25px;
}

.brand-mark {
  position: relative;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-bright);
  border-radius: 50%;
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span {
  position: absolute;
  content: "";
  background: var(--accent);
}

.brand-mark::before {
  top: 50%;
  left: 7px;
  width: 19px;
  height: 1px;
}

.brand-mark::after {
  top: 7px;
  left: 50%;
  width: 1px;
  height: 19px;
}

.brand-mark span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
}

.brand-mark span:nth-child(1) { top: 5px; left: 15px; }
.brand-mark span:nth-child(2) { right: 5px; top: 15px; }
.brand-mark span:nth-child(3) { bottom: 5px; left: 15px; }
.brand-mark span:nth-child(4) { left: 5px; top: 15px; }

.brand-name {
  font: 650 13px/1 var(--mono);
  letter-spacing: 0.14em;
}

.brand-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font: 9px/1 var(--mono);
  letter-spacing: 0.18em;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line-bright);
  border-radius: 12px;
  background: transparent;
  padding: 12px 14px;
  transition: border-color 160ms, background 160ms;
}

.new-chat:hover {
  border-color: var(--accent-dim);
  background: var(--accent-soft);
}

.plus {
  color: var(--accent);
  font: 300 20px/1 var(--sans);
}

.sidebar-label {
  display: flex;
  justify-content: space-between;
  margin: 28px 5px 10px;
  color: var(--muted);
  font: 10px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topic-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-bright) transparent;
}

.topic-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  width: 100%;
  margin-bottom: 3px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  padding: 11px 11px 10px 13px;
  color: var(--muted-strong);
  text-align: left;
  transition: background 150ms, color 150ms;
}

.topic-item:hover,
.topic-item.active {
  background: var(--panel-soft);
  color: var(--text);
}

.topic-item.active::before {
  position: absolute;
  top: 13px;
  bottom: 13px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
}

.topic-name {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-meta {
  margin-top: 6px;
  color: #66716e;
  font: 9px/1 var(--mono);
}

.topic-delete {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 3px;
  transition: opacity 150ms, color 150ms;
}

.topic-item:hover .topic-delete {
  opacity: 1;
}

.topic-delete:hover {
  color: var(--danger);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 18px 4px 0;
}

.system-state {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
}

.system-state .muted {
  margin-top: 4px;
  font-size: 9px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(241, 184, 91, 0.1);
}

.status-dot.online {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(182, 243, 107, 0.1);
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(236, 127, 116, 0.1);
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.icon-button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.main-panel {
  display: grid;
  min-width: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.013) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.013) 1px, transparent 1px);
  background-size: 36px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  min-height: 78px;
  border-bottom: 1px solid var(--line);
  padding: 13px 34px;
  background: rgba(8, 11, 13, 0.8);
  backdrop-filter: blur(16px);
}

.conversation-heading {
  min-width: 0;
  flex: 1;
}

.eyebrow {
  color: var(--accent-dim);
  font: 9px/1.2 var(--mono);
  letter-spacing: 0.16em;
}

.conversation-heading h1 {
  overflow: hidden;
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.route-control {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 10px;
}

.route-control select,
.memory-form select {
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--panel);
  padding: 8px 28px 8px 10px;
  color: var(--muted-strong);
  font-size: 11px;
}

.memory-button,
.admin-button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  padding: 8px 10px;
  color: var(--muted-strong);
  font-size: 11px;
  text-decoration: none;
}

.memory-button:hover,
.admin-button:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

.admin-button svg {
  width: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.memory-glyph {
  width: 9px;
  height: 12px;
  border: 1px solid currentColor;
  border-radius: 50% 50% 45% 45%;
}

.memory-count {
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 9px/1 var(--mono);
}

.mobile-menu {
  display: none;
}

.chat-viewport {
  overflow-y: auto;
  padding: 34px max(34px, calc((100% - 860px) / 2));
  scroll-behavior: smooth;
}

.welcome {
  width: min(760px, 100%);
  margin: max(20px, 8vh) auto 0;
  text-align: center;
}

.welcome-orbit {
  position: relative;
  width: 104px;
  height: 104px;
  margin: 0 auto 28px;
}

.orbit-ring {
  position: absolute;
  border: 1px solid var(--line-bright);
  border-radius: 50%;
}

.ring-one {
  inset: 10px;
  border-top-color: var(--accent);
  animation: spin 10s linear infinite;
}

.ring-two {
  inset: 24px;
  border-right-color: var(--accent-dim);
  animation: spin 7s linear infinite reverse;
}

.core-light {
  position: absolute;
  inset: 39px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 20px rgba(182, 243, 107, 0.5),
    0 0 55px rgba(182, 243, 107, 0.22);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.welcome h2 {
  margin: 15px 0 12px;
  font-size: clamp(25px, 3vw, 38px);
  font-weight: 450;
  letter-spacing: -0.03em;
}

.welcome > p {
  max-width: 590px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.capability-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 42px;
  text-align: left;
}

.capability {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(13, 17, 20, 0.72);
  padding: 17px;
}

.capability span {
  color: var(--accent-dim);
  font: 9px/1 var(--mono);
}

.capability strong {
  display: block;
  margin: 13px 0 7px;
  font-size: 12px;
  font-weight: 550;
}

.capability p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.65;
}

.message-list {
  display: flex;
  width: min(860px, 100%);
  margin: 0 auto;
  flex-direction: column;
  gap: 28px;
}

.message {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 14px;
  animation: arrive 180ms ease-out;
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 30px;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
}

.message.user .message-body {
  grid-column: 1;
  grid-row: 1;
  align-items: flex-end;
}

.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line-bright);
  border-radius: 9px;
  color: var(--accent);
  font: 9px/1 var(--mono);
}

.message.user .avatar {
  border-color: var(--line);
  color: var(--muted-strong);
}

.message-body {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #66716e;
  font: 9px/1 var(--mono);
}

.message-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.78;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .message-text {
  max-width: 86%;
  border: 1px solid var(--line);
  border-radius: 15px 4px 15px 15px;
  background: var(--panel-soft);
  padding: 12px 15px;
}

.message.assistant .message-text {
  padding-top: 1px;
}

.message.error .message-text {
  color: var(--danger);
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-dim);
  animation: pulse 1s ease-in-out infinite;
}

.typing i:nth-child(2) { animation-delay: 120ms; }
.typing i:nth-child(3) { animation-delay: 240ms; }

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

.composer-wrap {
  min-width: 0;
  padding: 12px max(34px, calc((100% - 860px) / 2)) 18px;
  background: linear-gradient(transparent, rgba(8, 11, 13, 0.96) 22%);
}

.composer {
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: rgba(13, 17, 20, 0.96);
  padding: 14px 14px 10px 17px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.24);
  transition: border-color 150ms;
}

.composer:focus-within {
  border-color: var(--accent-dim);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 190px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.composer textarea::placeholder,
.memory-search input::placeholder,
.memory-form input::placeholder,
.memory-form textarea::placeholder {
  color: #5e6966;
}

.composer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
}

.composer-hint {
  color: #59635f;
  font: 9px/1 var(--mono);
}

.key {
  color: #7d8985;
}

.separator {
  margin: 0 7px;
}

.send-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #15200b;
  transition: opacity 150ms, transform 150ms;
}

.send-button:hover {
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.4;
  transform: none;
}

.send-button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.privacy-note {
  margin: 9px 0 0;
  color: #505a57;
  text-align: center;
  font-size: 9px;
}

.privacy-note code,
.dialog-copy code {
  color: #73807c;
  font-family: var(--mono);
}

.memory-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  width: min(380px, 94vw);
  flex-direction: column;
  border-left: 1px solid var(--line-bright);
  background: #0b0f12;
  padding: 24px 22px;
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.38);
  transform: translateX(105%);
  transition: transform 220ms ease;
}

.memory-drawer.open {
  transform: translateX(0);
}

.drawer-header,
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.drawer-header h2,
.dialog-header h2 {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 500;
}

.memory-search {
  margin: 23px 0 10px;
}

.memory-search input,
.memory-form input,
.memory-form textarea,
.dialog-card > input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: var(--panel);
  padding: 10px 12px;
  color: var(--text);
  font-size: 12px;
}

.memory-search input:focus,
.memory-form input:focus,
.memory-form textarea:focus,
.dialog-card > input:focus {
  border-color: var(--accent-dim);
}

.memory-form {
  display: grid;
  gap: 7px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.memory-form textarea {
  resize: vertical;
  line-height: 1.5;
}

.memory-form-row {
  display: flex;
  gap: 6px;
}

.memory-form-row select {
  min-width: 0;
  flex: 1;
  padding-right: 18px;
}

.memory-form-row button {
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  background: var(--accent-soft);
  padding: 7px 13px;
  color: var(--accent);
  font-size: 10px;
}

.memory-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding-top: 17px;
}

.memory-card {
  position: relative;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 13px 35px 13px 13px;
}

.memory-card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.memory-kind {
  border-radius: 5px;
  background: var(--accent-soft);
  padding: 3px 6px;
  color: var(--accent);
  font: 8px/1 var(--mono);
  text-transform: uppercase;
}

.memory-scope {
  color: #65706d;
  font: 8px/1 var(--mono);
}

.memory-card p {
  margin: 0;
  color: var(--muted-strong);
  font-size: 11px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.memory-card .delete-memory {
  position: absolute;
  top: 9px;
  right: 9px;
  border: 0;
  background: transparent;
  color: #59635f;
  font-size: 17px;
}

.memory-card .delete-memory:hover {
  color: var(--danger);
}

.empty-state {
  padding: 40px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  line-height: 1.7;
}

dialog {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(2, 5, 6, 0.7);
  backdrop-filter: blur(6px);
}

.dialog-card {
  border: 1px solid var(--line-bright);
  border-radius: 17px;
  background: #0d1215;
  padding: 22px;
}

.dialog-copy {
  margin: 20px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font: 9px/1 var(--mono);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.primary-button,
.secondary-button {
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 11px;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #142008;
}

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted-strong);
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 80;
  max-width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--line-bright);
  border-radius: 9px;
  background: #141b1e;
  padding: 10px 14px;
  color: var(--muted-strong);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms, transform 160ms;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 88vw);
    transform: translateX(-103%);
    transition: transform 220ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-grid;
  }

  .topbar {
    gap: 8px;
    min-height: 68px;
    padding: 10px 12px;
  }

  .route-control > span {
    display: none;
  }

  .route-control select {
    max-width: 74px;
    padding-right: 8px;
  }

  .memory-button > span:nth-child(2) {
    display: none;
  }

  .admin-button > span {
    display: none;
  }

  .chat-viewport {
    padding: 26px 18px;
  }

  .composer-wrap {
    padding: 8px 14px 12px;
  }

  .capability-grid {
    grid-template-columns: 1fr;
  }

  .capability {
    display: grid;
    grid-template-columns: 26px 85px 1fr;
    align-items: center;
    gap: 8px;
    padding: 13px;
  }

  .capability strong {
    margin: 0;
  }

  .capability p {
    font-size: 9px;
  }
}

@media (max-width: 520px) {
  .conversation-heading .eyebrow {
    display: none;
  }

  .conversation-heading h1 {
    margin-top: 0;
    font-size: 14px;
  }

  .message {
    gap: 9px;
  }

  .message.user .message-text {
    max-width: 100%;
  }

  .composer-hint {
    display: none;
  }

  .privacy-note {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

