:root {
  color-scheme: dark;
  --bg: #08111f;
  --bg-soft: #0f1b31;
  --panel: rgba(13, 22, 39, 0.92);
  --panel-border: rgba(148, 163, 184, 0.18);
  --text: #e5eefc;
  --muted: #9aa8c2;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --bubble-user: linear-gradient(135deg, #1d4ed8, #2563eb);
  --bubble-ai: rgba(15, 23, 42, 0.92);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.2), transparent 30%),
    linear-gradient(160deg, var(--bg), #050913 72%);
  color: var(--text);
  overflow: hidden;
}

.chat-shell {
  min-height: 100vh;
  padding: 24px;
}

.app-layout {
  width: min(100%, 1480px);
  margin: 0 auto;
  display: flex;
  gap: 18px;
  height: calc(100vh - 48px);
}

.sidebar {
  width: 340px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: rgba(8, 15, 30, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow-y: auto;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-label {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.68rem;
}

.sidebar-tools {
  position: relative;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  cursor: pointer;
}

.more-menu {
  position: absolute;
  right: 0;
  top: 42px;
  min-width: 180px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  background: rgba(8, 15, 30, 0.98);
  box-shadow: var(--shadow);
  z-index: 4;
}

.more-menu button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
}

.more-menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  background: rgba(8, 15, 30, 0.9);
  color: var(--text);
  outline: none;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow-y: auto;
}

.thread-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.thread-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.thread-item.is-active {
  border-color: rgba(125, 211, 252, 0.45);
  background: rgba(125, 211, 252, 0.09);
}

.thread-item-title {
  font-weight: 700;
}

.thread-item-meta,
.thread-item-snippet {
  color: var(--muted);
  font-size: 0.82rem;
}

.chat-panel {
  width: auto;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.composer-shell {
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(180deg, rgba(13, 22, 39, 0), rgba(13, 22, 39, 0.88) 20%, rgba(13, 22, 39, 0.98));
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: 0.08em;
}

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

.brand-subtitle {
  margin: 0;
  max-width: 48ch;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.96rem;
}

.status {
  margin: 6px 0 0;
  max-width: 36ch;
  color: var(--muted);
  text-align: right;
  font-size: 0.95rem;
}

.status[data-state="ok"] {
  color: var(--text);
}

.status[data-state="error"] {
  color: #fca5a5;
}

.status-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.status-label {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.ghost-button {
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.ghost-button:hover {
  transform: translateY(-1px);
  border-color: rgba(125, 211, 252, 0.45);
  background: rgba(15, 23, 42, 0.82);
}

.coding-workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 20px;
  background: rgba(8, 15, 30, 0.55);
}

.coding-workspace.is-active {
  border-color: rgba(125, 211, 252, 0.34);
  background: rgba(8, 15, 30, 0.72);
}

.coding-workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.workspace-label {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
}

.coding-workspace h2 {
  margin: 0;
  font-size: 1.15rem;
}

.workspace-note {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  accent-color: var(--accent-strong);
}

.coding-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.coding-controls input {
  flex: 1 1 320px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  background: rgba(8, 15, 30, 0.9);
  color: var(--text);
  outline: none;
}

.coding-controls input:focus {
  border-color: rgba(125, 211, 252, 0.7);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.coding-summary {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.coding-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.coding-summary-card {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(255, 255, 255, 0.03);
}

.summary-label {
  margin: 0 0 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
}

.coding-summary-card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.coding-summary-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.coding-list {
  margin: 0;
  padding-left: 1rem;
  color: var(--text);
}

.coding-list li + li {
  margin-top: 8px;
}

.coding-list strong {
  display: block;
  margin-bottom: 2px;
}

.coding-list span {
  color: var(--muted);
}

.coding-empty {
  margin: 0;
  color: var(--muted);
}

.chat-box {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  max-width: 420px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(148, 163, 184, 0.2);
  border-radius: 24px;
  background: rgba(8, 15, 30, 0.42);
}

.empty-state-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #04101c;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  font-weight: 800;
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.message {
  display: flex;
  gap: 12px;
  max-width: min(82%, 760px);
  animation: fadeInUp 0.2s ease both;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-assistant {
  align-self: flex-start;
}

.message-avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(125, 211, 252, 0.24), rgba(56, 189, 248, 0.74));
  color: #04101c;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  width: 100%;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.message-user .message-meta {
  justify-content: flex-end;
}

.message-label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-bubble {
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(148, 163, 184, 0.12);
  max-width: 100%;
}

.message-user .message-bubble {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 6px;
}

.message-assistant .message-bubble {
  background: var(--bubble-ai);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.message-time {
  font-size: 0.72rem;
  color: rgba(154, 168, 194, 0.82);
}

.message-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  position: relative;
  flex-wrap: wrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
  opacity: 1;
  transform: translateY(0);
}

.message-action {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: rgba(229, 238, 252, 0.72);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.message-action:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.message-action.is-active {
  color: #ffffff;
  background: rgba(125, 211, 252, 0.16);
}

.message-action-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
}

.message-action svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.markdown-body p {
  margin: 0;
}

.markdown-body p + p,
.markdown-body ul + p,
.markdown-body ol + p,
.markdown-body blockquote + p,
.markdown-body pre + p,
.markdown-body p + ul,
.markdown-body p + ol,
.markdown-body p + blockquote,
.markdown-body p + pre {
  margin-top: 10px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0;
  padding-left: 1.25rem;
}

.markdown-body li + li {
  margin-top: 6px;
}

.markdown-body blockquote {
  margin: 0;
  padding: 10px 14px;
  border-left: 3px solid rgba(125, 211, 252, 0.55);
  background: rgba(125, 211, 252, 0.06);
  border-radius: 10px;
}

.inline-code {
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  background: rgba(8, 15, 30, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.12);
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 0.92em;
}

.code-block {
  margin: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(8, 15, 30, 0.98);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.code-lang {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.code-block code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  white-space: pre;
}

.code-copy {
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

.code-copy:hover {
  background: rgba(255, 255, 255, 0.08);
}

.markdown-body a {
  color: #8fdcff;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.typing-bubble {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(229, 238, 252, 0.78);
  animation: typingPulse 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.input-area {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-top: 6px;
}

.input-area textarea {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  background: rgba(8, 15, 30, 0.9);
  color: var(--text);
  outline: none;
  resize: none;
  min-height: 54px;
  max-height: 180px;
  line-height: 1.5;
  font: inherit;
  overflow-y: auto;
}

.input-area textarea::-webkit-scrollbar,
.chat-box::-webkit-scrollbar {
  width: 10px;
}

.input-area textarea::-webkit-scrollbar-thumb,
.chat-box::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.24);
  border-radius: 999px;
}

.input-area textarea::placeholder {
  color: #7c8aa6;
}

.input-area textarea:focus {
  border-color: rgba(125, 211, 252, 0.7);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.input-area button {
  padding: 14px 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #04101c;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.input-area button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.input-area button:disabled,
.input-area textarea:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.floating-latest {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 50%;
  background: rgba(13, 22, 39, 0.92);
  color: var(--text);
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}

.floating-latest.show {
  display: inline-flex;
}

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

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .chat-shell {
    padding: 12px;
    overflow: auto;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 24px);
  }

  .sidebar,
  .chat-panel {
    width: 100%;
  }

  .chat-header {
    flex-direction: column;
  }

  .status {
    text-align: left;
  }

  .status-panel {
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-panel {
    min-height: calc(100vh - 340px);
    padding: 18px;
    border-radius: 18px;
  }

  .sidebar {
    max-height: none;
  }

  .coding-workspace-header {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-toggle {
    align-self: flex-start;
  }

  .coding-controls {
    flex-direction: column;
  }

  .coding-controls input {
    width: 100%;
  }

  .coding-summary-grid,
  .coding-summary-columns {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  .input-area {
    flex-direction: column;
    align-items: stretch;
  }

  .input-area textarea {
    width: 100%;
  }

  .composer-shell {
    position: static;
  }

  .floating-latest {
    right: 14px;
    bottom: 14px;
  }
}
