:root {
  --bg: #0a1014;
  --bg-accent: #0f1c22;
  --surface: rgba(13, 20, 26, 0.88);
  --surface-strong: #111a20;
  --surface-soft: rgba(24, 34, 41, 0.92);
  --surface-user: linear-gradient(135deg, #0c8b84, #12736d);
  --line: rgba(119, 145, 158, 0.18);
  --line-strong: rgba(119, 145, 158, 0.28);
  --text: #eef4f6;
  --text-soft: #d6e2e7;
  --muted: #8ea0aa;
  --accent: #4de0d4;
  --accent-strong: #1ac0b4;
  --accent-soft: rgba(77, 224, 212, 0.12);
  --danger: #ff7d7d;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Inter", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(25, 112, 106, 0.24), transparent 26%),
    radial-gradient(circle at top right, rgba(55, 90, 134, 0.16), transparent 24%),
    radial-gradient(circle at bottom center, rgba(21, 164, 149, 0.1), transparent 32%),
    linear-gradient(180deg, #0a1014 0%, #0c1217 48%, #0a1116 100%);
  position: fixed;
  inset: 0;
}

body.sidebar-open {
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  height: 100dvh;
  padding: 16px;
  overflow: hidden;
}

.sidebar,
.workspace,
.composer-panel,
.message-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar-backdrop,
.mobile-nav-button,
.sidebar-close {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  border: 0;
  background: rgba(3, 8, 12, 0.68);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
  padding: 16px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(17, 26, 32, 0.96), rgba(13, 20, 26, 0.96));
  overflow: hidden;
}

.sidebar-top {
  display: grid;
  gap: 12px;
}

.sidebar-brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.brand {
  display: grid;
  gap: 4px;
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.85rem;
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.brand-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.new-chat-button,
.send-button,
.topbar-button,
.sidebar-tool-button {
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.new-chat-button,
.sidebar-tool-button,
.topbar-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.new-chat-button:hover,
.send-button:hover,
.icon-button:hover,
.topbar-button:hover,
.sidebar-tool-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.new-chat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 14px;
  font-weight: 600;
}

.sidebar-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.conversation-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.conversation-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.conversation-list li {
  min-height: 0;
  min-width: 0;
}

.conversation-list-item {
  position: relative;
  min-width: 0;
}

.conversation-item-shell {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.conversation-item {
  width: 100%;
  display: block;
  text-align: left;
  min-width: 0;
  padding: 8px 40px 8px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.conversation-item.active {
  background: rgba(77, 224, 212, 0.1);
  border-color: rgba(77, 224, 212, 0.22);
}

.conversation-item-shell:hover .conversation-item,
.conversation-list-item.active .conversation-item {
  border-color: rgba(77, 224, 212, 0.22);
}

.conversation-item-title {
  display: block;
  font-weight: 600;
  font-size: 0.87rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-menu-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  min-width: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.conversation-item-shell:hover .conversation-menu-toggle,
.conversation-list-item.active .conversation-menu-toggle,
.conversation-list-item.menu-open .conversation-menu-toggle {
  opacity: 1;
  pointer-events: auto;
}

.conversation-menu-toggle:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
}

.conversation-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 192px;
  display: none;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(17, 26, 32, 0.98);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

.conversation-menu.open {
  display: grid;
  gap: 4px;
}

.conversation-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.conversation-menu-item.danger {
  color: var(--danger);
}

.sidebar-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.sidebar-tool-button {
  padding: 0;
  color: var(--text-soft);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  min-height: 0;
  padding: 16px 18px 18px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(13, 20, 26, 0.88), rgba(11, 17, 22, 0.92));
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
  width: 100%;
  margin: 0;
  padding: 4px 6px 0;
}

.topbar-main {
  grid-column: 2;
  min-width: 0;
  text-align: center;
}

.topbar h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2.8vw, 2.2rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.topbar-meta {
  margin: 8px 0 0;
  color: var(--muted);
  min-height: 1.1rem;
  font-size: 0.94rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-meta:empty {
  display: none;
}

.topbar-context {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid rgba(77, 224, 212, 0.16);
  border-radius: var(--radius-pill);
  background: rgba(77, 224, 212, 0.08);
  color: var(--text-soft);
}

.topbar-context-label {
  color: var(--muted);
  white-space: nowrap;
}

.topbar-context-name {
  max-width: min(48vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}

.topbar-context-clear {
  width: 34px;
  height: 34px;
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.topbar-context-clear:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
}

.topbar-actions {
  grid-column: 3;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 10px;
}

.topbar-button {
  min-width: 0;
  padding: 0;
  color: var(--text-soft);
}

.message-feed {
  width: min(100%, 960px);
  min-height: 0;
  margin: 0 auto;
  padding: 4px 8px 8px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.empty-state {
  height: 100%;
  min-height: 340px;
  display: grid;
  place-items: center;
}

.empty-state-card {
  width: min(100%, 560px);
  padding: 28px 30px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(17, 26, 32, 0.9), rgba(14, 21, 27, 0.96));
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-state-kicker {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.empty-state-title {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.empty-state-text {
  margin: 16px 0 0;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1.6;
}

.message {
  display: flex;
}

.message-assistant {
  justify-content: flex-start;
}

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

.message-card {
  width: min(100%, 680px);
  padding: 10px 13px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(24, 34, 41, 0.95), rgba(19, 28, 34, 0.95));
}

.message-user .message-card {
  background: var(--surface-user);
  border-color: transparent;
}

.message-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.message-author {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-soft);
}

.message-time {
  font-size: 0.78rem;
  color: var(--muted);
}

.message-user .message-author,
.message-user .message-time {
  color: rgba(255, 255, 255, 0.86);
}

.message-text {
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.58;
  word-break: break-word;
}

.message-text p {
  margin: 0;
}

.message-text p + p {
  margin-top: 12px;
}

.message-text code {
  padding: 0.12rem 0.4rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
}

.message-user .message-text code {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.message-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.citation-chip,
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-pill);
}

.citation-chip {
  padding: 8px 12px;
  background: rgba(77, 224, 212, 0.1);
  color: var(--accent);
  font-size: 0.84rem;
}

.composer-panel {
  width: min(100%, 960px);
  margin: 0 auto;
  display: grid;
  gap: 10px;
  min-height: 0;
  padding: 12px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(18, 27, 34, 0.96), rgba(13, 20, 26, 0.98));
}

.composer-panel.dragover {
  border-color: rgba(77, 224, 212, 0.32);
  background: linear-gradient(180deg, rgba(17, 43, 45, 0.98), rgba(13, 20, 26, 0.98));
}

.attachment-tray {
  display: none;
  flex-wrap: wrap;
  gap: 10px;
}

.attachment-tray.has-items {
  display: flex;
}

.attachment-chip {
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.attachment-chip.error {
  border-color: rgba(255, 125, 125, 0.28);
  background: rgba(255, 125, 125, 0.1);
}

.attachment-name {
  font-weight: 600;
}

.attachment-status {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.composer-form {
  display: grid;
  gap: 12px;
}

.composer-input-wrap {
  min-height: 72px;
}

#composerInput {
  width: 100%;
  min-height: 72px;
  max-height: 144px;
  resize: none;
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: 0;
}

#composerInput::placeholder {
  color: var(--muted);
}

#composerInput:focus {
  border-color: rgba(77, 224, 212, 0.28);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.icon-button {
  min-width: 74px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 600;
}

.icon-only-button {
  width: 42px;
  height: 42px;
  min-width: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
}

.mobile-nav-button,
.sidebar-close {
  display: none;
}

.button-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.9;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.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;
}

.composer-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.send-button {
  min-width: 114px;
  padding: 11px 18px;
  border: 0;
  background: linear-gradient(135deg, var(--accent-strong), #0b8078);
  color: #041416;
  font-weight: 700;
  box-shadow: 0 18px 34px rgba(11, 128, 120, 0.28);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(142, 160, 170, 0.35);
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(142, 160, 170, 0.35) transparent;
}

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

  .sidebar {
    max-height: 240px;
  }

  .workspace {
    min-height: 0;
  }

  .topbar,
  .message-feed,
  .composer-panel {
    width: 100%;
  }
}

@media (max-width: 900px) {
  body {
    position: static;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    top: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 40;
    width: min(84vw, 320px);
    max-height: none;
    transform: translateX(calc(-100% - 24px));
    transition: transform 180ms ease;
  }

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

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

  .workspace {
    min-width: 0;
    height: calc(100dvh - 24px);
    padding: 14px;
    border-radius: 22px;
    min-height: 0;
  }

  .mobile-nav-button,
  .sidebar-close {
    display: inline-flex;
  }

  .sidebar-close {
    margin-left: auto;
  }

  .sidebar-brand-row {
    justify-content: space-between;
    gap: 12px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
  }

  .topbar-actions {
    grid-column: 3;
    width: auto;
    justify-self: end;
    justify-content: flex-end;
    flex-wrap: nowrap;
  }

  .topbar-main {
    grid-column: 2;
    text-align: left;
  }

  .topbar-meta {
    justify-content: flex-start;
  }

  .composer-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-left {
    flex-direction: column;
    align-items: flex-start;
  }

  .send-button,
  .new-chat-button {
    width: 100%;
  }

  .sidebar-bottom {
    justify-content: flex-start;
  }

  .message-card {
    width: min(100%, 100%);
  }

  .message-feed,
  .composer-panel {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
  }

  .workspace {
    height: 100dvh;
    padding: 12px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    gap: 12px;
  }

  .sidebar {
    top: 0;
    bottom: 0;
    left: 0;
    width: min(88vw, 320px);
    border-radius: 0 24px 24px 0;
  }

  .topbar {
    gap: 10px;
    padding-inline: 0;
  }

  .topbar h2 {
    font-size: 1.35rem;
  }

  .topbar-button,
  .mobile-nav-button,
  .sidebar-close,
  .sidebar-tool-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .message-feed {
    min-height: 0;
    padding-inline: 0;
    gap: 8px;
  }

  .message-card {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .message-text {
    font-size: 0.92rem;
    line-height: 1.5;
  }

  .composer-panel {
    padding: 10px;
    border-radius: 20px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #composerInput {
    min-height: 60px;
    padding: 12px 14px;
  }

  .composer-hint {
    font-size: 0.82rem;
  }

  .send-button {
    min-width: 100px;
  }

  .new-chat-button {
    padding: 10px 12px;
  }

  .conversation-item {
    padding: 10px 38px 10px 10px;
  }

  .topbar-context {
    max-width: 100%;
  }

  .topbar-context-name {
    max-width: 46vw;
  }
}
