:root {
  color-scheme: dark;
  --bg: #0f1116;
  --panel: #171a21;
  --panel-alt: #1f2430;
  --panel-hover: #262d3d;
  --border: #2e3545;
  --text: #eef2ff;
  --text-muted: #a4adbf;
  --text-dim: #7d8698;
  --accent: #7c9cff;
  --accent-strong: #5f85ff;
  --success: #2dbf7f;
  --warning: #f0b429;
  --danger: #f97066;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
  --radius: 18px;
  --sidebar-width: 360px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1a2235, #0f1116 38%);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body {
  min-height: 100vh;
}

button,
input,
textarea,
summary {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  padding: 20px;
  border-right: 1px solid rgba(124, 156, 255, 0.12);
  background: rgba(15, 17, 22, 0.84);
  backdrop-filter: blur(18px);
  overflow-y: auto;
}

.chat-stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 32px 32px;
  gap: 18px;
}

.brand,
.chat-header,
.section-header,
.button-row,
.composer-footer,
.status-pill,
.message-meta,
.empty-state-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
  margin-bottom: 20px;
}

.brand h1,
.chat-header h2,
.panel h2 {
  margin: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #62d3ff);
  color: #06101f;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.panel {
  background: rgba(23, 26, 33, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel summary {
  list-style: none;
  font-weight: 600;
}

.panel summary::-webkit-details-marker {
  display: none;
}

.panel-copy,
.helper {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.helper {
  font-size: 0.86rem;
}

.section-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.badge,
.status-pill {
  border-radius: 999px;
  border: 1px solid rgba(124, 156, 255, 0.18);
  background: rgba(124, 156, 255, 0.12);
  color: var(--text);
  font-size: 0.8rem;
}

.badge {
  padding: 6px 10px;
}

.status-pill {
  gap: 10px;
  padding: 8px 14px;
  margin-left: auto;
}

.status-pill strong {
  font-size: 0.9rem;
}

.stack {
  display: grid;
  gap: 12px;
}

.memory-pack-options {
  margin: 16px 0 12px;
}

.stack label {
  display: grid;
  gap: 8px;
}

.stack span {
  color: var(--text-muted);
  font-size: 0.84rem;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(12, 15, 21, 0.88);
  color: var(--text);
  padding: 12px 14px;
  transition: border-color 120ms ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  min-height: 56px;
  max-height: 220px;
  resize: vertical;
}

.is-hidden {
  display: none !important;
}

.button-row {
  gap: 10px;
  flex-wrap: wrap;
}

.button,
.conversation-item,
.text-button,
.suggestion-chip,
.menu-button {
  border: 0;
}

.button {
  min-height: 42px;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 600;
  transition:
    transform 120ms ease,
    background 120ms ease,
    opacity 120ms ease;
}

.button:hover,
.text-button:hover,
.conversation-item:hover,
.suggestion-chip:hover,
.menu-button:hover {
  transform: translateY(-1px);
}

.button:disabled,
.text-button:disabled,
.conversation-item:disabled,
.suggestion-chip:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.button-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #08101d;
}

.button-secondary,
.conversation-item,
.menu-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.text-button {
  background: transparent;
  color: var(--accent);
  padding: 0;
}

.progress {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(135deg, var(--accent), #58d5ff);
  transition: width 220ms ease;
}

.conversation-list {
  display: grid;
  gap: 10px;
}

.conversation-item {
  width: 100%;
  display: grid;
  gap: 6px;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.conversation-item.is-active {
  background: rgba(124, 156, 255, 0.18);
  border-color: rgba(124, 156, 255, 0.38);
}

.conversation-item-title {
  font-weight: 600;
}

.conversation-item-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.chat-header {
  gap: 14px;
  padding-bottom: 12px;
}

.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
}

.notice {
  min-height: 0;
  padding: 0;
  color: var(--text-muted);
}

.notice:not(:empty) {
  padding: 14px 16px;
  border: 1px solid rgba(124, 156, 255, 0.16);
  border-radius: 16px;
  background: rgba(124, 156, 255, 0.1);
}

.notice[data-tone="error"]:not(:empty) {
  border-color: rgba(249, 112, 102, 0.26);
  background: rgba(249, 112, 102, 0.12);
  color: #ffd5cf;
}

.notice[data-tone="success"]:not(:empty) {
  border-color: rgba(45, 191, 127, 0.24);
  background: rgba(45, 191, 127, 0.12);
  color: #c8f5df;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
}

.message,
.empty-state {
  max-width: 920px;
  width: min(100%, 920px);
  align-self: center;
}

.message {
  display: grid;
  gap: 10px;
  padding: 18px 20px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(23, 26, 33, 0.86);
  box-shadow: var(--shadow);
}

.message--user {
  background: rgba(124, 156, 255, 0.14);
}

.message--assistant {
  background: rgba(255, 255, 255, 0.04);
}

.message--system {
  background: rgba(124, 156, 255, 0.08);
}

.message--error {
  border-color: rgba(249, 112, 102, 0.28);
}

.message-meta {
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.message-role {
  color: var(--text);
  font-weight: 700;
}

.message-content {
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
}

.message-content.is-pending::after {
  content: "|";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.empty-state {
  margin: auto auto 24px;
  padding: 28px;
  border-radius: 22px;
  border: 1px dashed rgba(124, 156, 255, 0.22);
  background: rgba(19, 22, 29, 0.72);
}

.empty-state h3 {
  margin: 0 0 10px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--text-muted);
  line-height: 1.6;
}

.empty-state-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.suggestion-chip {
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.composer {
  width: min(100%, 960px);
  align-self: center;
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(18, 20, 27, 0.9);
  border: 1px solid rgba(124, 156, 255, 0.14);
  box-shadow: var(--shadow);
}

.composer-footer {
  justify-content: space-between;
  gap: 16px;
}

.composer-footer .helper {
  flex: 1;
}

.status-online {
  background: rgba(45, 191, 127, 0.14);
  border-color: rgba(45, 191, 127, 0.28);
}

.status-warning {
  background: rgba(240, 180, 41, 0.12);
  border-color: rgba(240, 180, 41, 0.28);
}

.status-error {
  background: rgba(249, 112, 102, 0.12);
  border-color: rgba(249, 112, 102, 0.3);
}

@media (max-width: 1080px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

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

  .chat-stage {
    padding: 20px;
  }

  .menu-button {
    display: inline-grid;
    place-items: center;
  }
}

@media (max-width: 720px) {
  .chat-stage {
    padding: 16px;
  }

  .chat-header,
  .composer-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pill {
    margin-left: 0;
  }

  .composer,
  .message,
  .empty-state {
    width: 100%;
  }
}
