:root {
  --bg: #ebe6de;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: #ffffff;
  --panel-muted: rgba(247, 244, 238, 0.94);
  --ink: #191919;
  --muted: #6e685f;
  --line: rgba(25, 25, 25, 0.1);
  --line-strong: rgba(25, 25, 25, 0.16);
  --accent: #171717;
  --accent-soft: rgba(23, 23, 23, 0.07);
  --shadow: 0 18px 50px rgba(39, 30, 18, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.75), transparent 34rem),
    linear-gradient(180deg, #efeae2 0%, var(--bg) 100%);
  font-family: "Avenir Next", "Manrope", "SF Pro Text", sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

.app-shell {
  position: relative;
  width: min(1100px, 100%);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  min-width: 0;
}

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

.brand-block {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-button:hover,
.chip:hover,
.suggestion:hover {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.icon-button svg,
.send-button svg {
  width: 18px;
  height: 18px;
}

.filters-panel {
  position: absolute;
  top: 62px;
  right: 16px;
  z-index: 30;
  width: min(720px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(249, 246, 241, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.filters-panel[hidden] {
  display: none;
}

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

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.messages.empty {
  justify-content: flex-end;
}

.message {
  display: flex;
  min-width: 0;
}

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

.bubble {
  width: fit-content;
  max-width: min(760px, 100%);
  min-width: 0;
  padding: 14px 16px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  box-shadow: 0 10px 28px rgba(35, 28, 18, 0.05);
}

.message.user .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.message-text,
.source-name,
.source-snippet {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-text {
  line-height: 1.6;
}

.message-text > :first-child {
  margin-top: 0;
}

.message-text > :last-child {
  margin-bottom: 0;
}

.message-text p {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4 {
  margin: 0 0 12px;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.message-text h1 {
  font-size: 22px;
}

.message-text h2 {
  font-size: 19px;
}

.message-text h3,
.message-text h4 {
  font-size: 16px;
}

.message-text ul,
.message-text ol {
  margin: 0 0 12px;
  padding-left: 20px;
}

.message-text li + li {
  margin-top: 6px;
}

.message-text strong {
  font-weight: 700;
}

.message-text code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(25, 25, 25, 0.06);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 0.92em;
}

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

.sources {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sources-disclosure {
  margin-top: 14px;
  border-top: 1px solid rgba(25, 25, 25, 0.08);
  padding-top: 12px;
}

.sources-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
}

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

.sources-chevron {
  color: var(--muted);
  transition: transform 0.18s ease;
}

.sources-disclosure[open] .sources-chevron {
  transform: rotate(180deg);
}

.sources-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-card {
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid rgba(25, 25, 25, 0.08);
}

.source-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
  margin-bottom: 6px;
}

.source-name {
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
}

.source-meta {
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--accent-soft);
}

.source-snippet {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.dock {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid rgba(25, 25, 25, 0.08);
  background: rgba(251, 249, 245, 0.88);
  backdrop-filter: blur(18px);
}

.filters-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 10px;
  min-width: 0;
}

.control-inline,
.filter-block {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(25, 25, 25, 0.08);
  border-radius: 20px;
  background: var(--panel-muted);
}

.control-inline label,
.filter-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-strong);
  color: var(--ink);
}

select:focus,
textarea:focus {
  outline: none;
}

.chip-row,
.suggestions {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.chip-row::-webkit-scrollbar,
.suggestions::-webkit-scrollbar {
  display: none;
}

.chip,
.suggestion {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.suggestions-wrap[hidden] {
  display: none;
}

.composer {
  margin: 0;
}

.composer-frame {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px 10px;
  border: 1px solid rgba(25, 25, 25, 0.1);
  border-radius: 24px;
  background: var(--panel-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

textarea {
  width: 100%;
  min-width: 0;
  min-height: 24px;
  max-height: 180px;
  resize: none;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 4px;
  font-size: 16px;
  line-height: 1.5;
}

textarea::placeholder {
  color: #8a8379;
}

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

.status {
  min-width: 0;
  padding-left: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status:empty {
  display: none;
}

.send-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.send-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

@media (max-width: 720px) {
  body {
    background:
      radial-gradient(circle at top, rgba(255, 255, 255, 0.82), transparent 22rem),
      linear-gradient(180deg, #efe9e0 0%, #e8e2d8 100%);
  }

  .app-shell {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .topbar {
    justify-content: flex-end;
    min-height: 32px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .brand-block {
    display: none;
  }

  .filters-panel {
    top: 52px;
    right: 10px;
    width: calc(100vw - 20px);
    padding: 8px;
    border-radius: 20px;
  }

  .chat-shell {
    border-radius: 24px;
  }

  .messages {
    padding: 14px 14px 6px;
    gap: 10px;
  }

  .bubble {
    max-width: 100%;
    border-radius: 20px;
    padding: 12px 14px;
  }

  .dock {
    gap: 10px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .control-inline,
  .filter-block {
    padding: 10px 12px;
    border-radius: 18px;
  }

  .chip,
  .suggestion {
    max-width: calc(100vw - 56px);
  }

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

  .status {
    font-size: 12px;
  }
}
