:root {
  --bg: #0b0b0f;
  --panel: rgba(20, 20, 27, 0.88);
  --panel-strong: rgba(27, 27, 36, 0.96);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f7fb;
  --muted: #a2a7b8;
  --muted-strong: #c8ccda;
  --accent: #8b5cf6;
  --accent-2: #6d4ce5;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --danger: #ff6b7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(139, 92, 246, 0.18), transparent 24%),
    linear-gradient(180deg, #0d0d12 0%, #09090d 100%);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  padding: 22px;
  border-right: 1px solid var(--border);
  background: rgba(8, 8, 13, 0.82);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}

.sidebar-backdrop {
  display: none;
}

.brand-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.35), transparent 30%),
    linear-gradient(135deg, var(--accent), #2d2c43);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 16px 36px rgba(92, 62, 176, 0.4);
  display: grid;
  place-items: center;
}

.brand-mark span {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.35);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-card h1,
.topbar-title h2,
.welcome-card h3 {
  margin: 0;
}

.brand-card h1 {
  font-size: 18px;
  font-weight: 700;
}

.new-chat-button,
.ghost-button,
.prompt-chip,
.thread-button,
.icon-button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.new-chat-button:hover,
.ghost-button:hover,
.prompt-chip:hover,
.thread-button:hover,
.icon-button:hover,
.send-button:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 92, 246, 0.45);
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.18), rgba(255, 255, 255, 0.03));
  flex-shrink: 0;
}

.new-chat-button span {
  font-size: 20px;
  line-height: 1;
}

.sidebar-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.thread-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.thread-button {
  width: 100%;
  text-align: left;
  padding: 14px 14px;
  border-radius: var(--radius-md);
}

.thread-button.active {
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.2), rgba(255, 255, 255, 0.04));
  border-color: rgba(139, 92, 246, 0.5);
}

.thread-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-date {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-footer {
  padding-top: 8px;
  flex-shrink: 0;
}

.footer-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted-strong);
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #7ef29a;
  box-shadow: 0 0 20px rgba(126, 242, 154, 0.65);
}

.main-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 14px;
  flex-shrink: 0;
}

.topbar-title {
  min-width: 0;
}

.topbar-title h2 {
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  flex-shrink: 0;
}

.danger-button {
  border-color: rgba(255, 107, 122, 0.25);
  color: #ffd7dc;
}

.danger-button:hover {
  border-color: rgba(255, 107, 122, 0.6);
  background: rgba(255, 107, 122, 0.08);
}

.ghost-button,
.icon-button {
  border-radius: 14px;
  padding: 10px 14px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: none;
  align-items: center;
  justify-content: center;
}

.welcome-state,
.chat-view {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 28px 32px;
  scrollbar-gutter: stable;
}

.welcome-state {
  display: grid;
  place-items: center;
  position: relative;
}

.hero-glow {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.18), transparent 66%);
  filter: blur(18px);
  pointer-events: none;
}

.welcome-card {
  position: relative;
  max-width: 760px;
  width: 100%;
  padding: 34px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(18, 18, 25, 0.95), rgba(10, 10, 16, 0.92));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.welcome-card h3 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
  letter-spacing: -0.03em;
  max-width: 14ch;
}

.welcome-card p:not(.eyebrow) {
  margin: 14px 0 0;
  color: var(--muted-strong);
  font-size: 16px;
  max-width: 58ch;
}

.prompt-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.prompt-chip {
  padding: 15px 16px;
  text-align: left;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
}

.chat-view {
  display: none;
}

.chat-view.active {
  display: block;
}

.welcome-state.hidden {
  display: none;
}

.message-stack {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.9), rgba(56, 54, 83, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.12);
  position: sticky;
  top: 0;
}

.message-row.user .avatar {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(67, 67, 86, 0.9));
}

.message-card {
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(22, 22, 30, 0.92), rgba(13, 13, 18, 0.92));
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.22);
}

.message-row.user .message-card {
  background: linear-gradient(180deg, rgba(34, 34, 44, 0.95), rgba(18, 18, 24, 0.95));
}

.message-meta {
  margin-bottom: 8px;
}

.role-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.message-body {
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
}

.message-body p {
  margin: 0 0 14px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 8px;
  font-size: 0.92em;
}

.message-body pre {
  margin: 14px 0;
  padding: 16px;
  border-radius: 18px;
  overflow: auto;
  background: #11111a;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.message-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
  display: block;
  white-space: pre-wrap;
}

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

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  animation: bounce 1.1s infinite ease-in-out;
}

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

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

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

.composer-shell {
  padding: 14px 28px 26px;
  flex-shrink: 0;
}

.composer-form {
  max-width: 860px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: rgba(16, 16, 23, 0.94);
  box-shadow: var(--shadow);
}

.composer-form:focus-within {
  border-color: rgba(139, 92, 246, 0.55);
  box-shadow: 0 24px 80px rgba(35, 17, 74, 0.4);
}

#composerInput {
  resize: none;
  max-height: 220px;
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 0;
  outline: none;
  padding: 8px 8px 8px 6px;
  line-height: 1.55;
}

#composerInput::placeholder {
  color: #8f93a3;
}

.send-button {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  border: 1px solid rgba(139, 92, 246, 0.38);
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: white;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 26px rgba(109, 76, 229, 0.3);
}

.send-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.send-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.composer-note {
  max-width: 860px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.empty-state {
  max-width: 760px;
  margin: 50px auto 0;
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

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

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 30;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .icon-button.mobile-only {
    display: inline-flex;
  }

  .topbar {
    padding: 14px 16px 10px;
    align-items: center;
    gap: 12px;
  }

  .topbar-actions {
    flex-direction: row;
    gap: 8px;
  }

  .ghost-button {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 16px;
  }

  .welcome-state,
  .chat-view {
    padding: 8px 16px 16px;
  }

  .welcome-state {
    align-items: center;
  }

  .welcome-card {
    max-width: 100%;
    padding: 22px;
  }

  .welcome-card h3 {
    font-size: clamp(24px, 6vw, 32px);
    max-width: none;
  }

  .welcome-card p:not(.eyebrow) {
    margin-top: 10px;
    font-size: 15px;
  }

  .prompt-grid {
    margin-top: 18px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .prompt-chip {
    min-height: 68px;
    display: flex;
    align-items: flex-start;
    font-size: 14px;
    line-height: 1.35;
  }

  .composer-shell {
    padding: 10px 16px 14px;
  }

  .composer-form {
    padding: 10px;
    border-radius: 22px;
    gap: 10px;
  }
}

@media (max-width: 640px) {
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "menu title"
      "actions actions";
    align-items: center;
    row-gap: 10px;
    column-gap: 12px;
  }

  #toggleSidebarButton {
    grid-area: menu;
  }

  .topbar-title {
    grid-area: title;
  }

  .topbar-title h2 {
    font-size: 18px;
  }

  .topbar-actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
  }

  .ghost-button {
    width: 100%;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    padding-inline: 10px;
  }

  .welcome-card {
    padding: 18px;
    border-radius: 22px;
  }

  .welcome-card h3 {
    font-size: 24px;
    line-height: 1.12;
  }

  .welcome-card p:not(.eyebrow) {
    font-size: 14px;
  }

  .prompt-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .prompt-chip {
    padding: 12px;
    min-height: 60px;
    font-size: 13px;
  }

  .message-row {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
  }

  .avatar {
    width: 36px;
    height: 36px;
    border-radius: 14px;
  }

  .message-card {
    padding: 14px;
    border-radius: 18px;
  }

  .composer-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .send-button {
    width: 48px;
    height: 48px;
  }

  .composer-note {
    display: none;
  }
}

@media (max-width: 420px) {
  .prompt-grid {
    grid-template-columns: 1fr;
  }
}
