:root {
  --bg: #f1f4f7;
  --bg-2: #eaf0f7;
  --sidebar: rgba(252, 254, 255, 0.76);
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(94, 120, 162, 0.2);
  --line-soft: rgba(94, 120, 162, 0.12);
  --ink: #0f172a;
  --ink-soft: #5f6f89;
  --accent: #174a86;
  --accent-2: #2e6fb4;
  --accent-soft: #e8f1ff;
  --user-a: #0f315c;
  --user-b: #1d4f8a;
  --ok: #1f5f3f;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-lg: 0 28px 80px rgba(20, 38, 65, 0.14);
  --shadow-md: 0 12px 30px rgba(20, 38, 65, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 8%, #ffffff 0%, var(--bg) 35%, var(--bg-2) 100%),
    linear-gradient(130deg, #f7fbff, #eaf0f7);
  overflow: hidden;
}

h1,
.brand,
.history-title {
  font-family: "Fraunces", Georgia, serif;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: radial-gradient(rgba(14, 24, 40, 0.18) 0.55px, transparent 0.55px);
  background-size: 4px 4px;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(46px);
  pointer-events: none;
  z-index: 0;
}

.ambient--a {
  width: 320px;
  height: 320px;
  top: -130px;
  right: 16%;
  background: rgba(149, 182, 242, 0.54);
}

.ambient--b {
  width: 280px;
  height: 280px;
  bottom: -100px;
  left: 22%;
  background: rgba(243, 213, 165, 0.36);
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  height: 100dvh;
  padding: 16px;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  backdrop-filter: blur(16px);
  background: linear-gradient(160deg, var(--sidebar), rgba(245, 250, 255, 0.6));
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px;
}

.sidebar-head {
  display: grid;
  gap: 8px;
}

.new-chat,
.search-chat,
.history-item,
.send-btn,
.model-btn,
.suggest {
  font-family: inherit;
}

.new-chat {
  border: 1px solid #b6c9e9;
  color: #0e315b;
  background: linear-gradient(150deg, #f8fcff, #e9f2ff);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.search-chat {
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink-soft);
  padding: 9px 11px;
  outline: none;
}

.new-chat:hover,
.history-item:hover,
.model-btn:hover,
.send-btn:hover,
.suggest:hover {
  transform: translateY(-1px);
}

.search-chat:focus {
  border-color: #9fc0ea;
}

.sidebar-section {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-right: 2px;
}

.sidebar-label {
  margin: 0;
  padding-left: 4px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6f7d95;
}

.history {
  display: grid;
  gap: 8px;
}

.history-item {
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  text-align: left;
  padding: 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.history-item--active {
  border-color: #b6caea;
  background: linear-gradient(145deg, #f8fbff, #eef4ff);
}

.history-title {
  font-size: 16px;
  color: #1a3356;
}

.history-sub {
  font-size: 12px;
  color: #6a7891;
}

.empty-history {
  font-size: 13px;
  color: #6f7d95;
  padding: 6px;
}

.sidebar-foot {
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}

.brand {
  margin: 0;
  font-size: 23px;
  color: #15335c;
}

.brand-sub {
  margin: 4px 0 0;
  color: #6b7991;
  font-size: 13px;
}

.chat-layout {
  min-width: 0;
  min-height: 0;
  backdrop-filter: blur(14px);
  background: linear-gradient(160deg, var(--panel), rgba(255, 255, 255, 0.58));
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  border-bottom: 1px solid var(--line-soft);
  padding: 16px 22px;
  background: rgba(251, 253, 255, 0.96);
  transition: padding 0.2s ease, border-color 0.2s ease;
}

.topbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

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

.menu-btn {
  border: 1px solid #c9d8ef;
  border-radius: 10px;
  background: linear-gradient(145deg, #f8fcff, #edf4ff);
  color: #1c426f;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 11px;
  cursor: pointer;
}

.quick-new-chat-btn {
  border: 1px solid #c9d8ef;
  border-radius: 10px;
  background: linear-gradient(145deg, #f8fcff, #edf4ff);
  color: #1c426f;
  font-family: inherit;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  width: 38px;
  height: 34px;
  cursor: pointer;
}

.topbar-title h1 {
  margin: 0;
  font-size: 24px;
  color: #12315c;
  line-height: 1.16;
  transition: font-size 0.2s ease;
}

.topbar-title p {
  margin: 5px 0 0;
  color: #697892;
  font-size: 13px;
  transition: font-size 0.2s ease, margin-top 0.2s ease;
}

.chat-layout.chat-layout--active .topbar {
  padding: 12px 18px;
}

.chat-layout.chat-layout--active .topbar-title h1 {
  font-size: 20px;
}

.chat-layout.chat-layout--active .topbar-title p {
  font-size: 12px;
  margin-top: 3px;
}

.chat-feed {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 20px 0 8px;
}

.chat-stream {
  width: min(940px, calc(100% - 36px));
  margin: 0 auto;
}

.chat-intro.hidden {
  display: none;
}

.message {
  margin-bottom: 14px;
  max-width: min(880px, 100%);
  border-radius: 16px;
  border: 1px solid var(--line-soft);
  background: linear-gradient(160deg, #ffffff, #f8fbff);
  padding: 13px 15px;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  animation: rise 0.24s ease;
}

.message h3,
.message h4 {
  margin: 0 0 8px;
  font-family: "Fraunces", Georgia, serif;
  color: inherit;
}

.message p {
  margin: 0 0 8px;
}

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

.message ul {
  margin: 0 0 8px 18px;
  padding: 0;
}

.message li {
  margin: 0 0 4px;
}

.message strong {
  font-weight: 800;
}

.message a {
  color: #1a5fb4;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(26, 95, 180, 0.35);
}

.message a:hover {
  border-bottom-color: rgba(26, 95, 180, 0.8);
}

.message code {
  font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: rgba(20, 30, 48, 0.08);
  border-radius: 6px;
  padding: 1px 5px;
}

.message--user {
  margin-left: auto;
  border-color: rgba(44, 95, 164, 0.48);
  background: linear-gradient(145deg, var(--user-a), var(--user-b));
  color: #fff;
  box-shadow: var(--shadow-md);
}

.message--typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
}

.message--typing span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #5d7092;
  animation: blink 1s infinite ease-in-out;
}

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

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

.followup-row {
  margin: -4px 0 14px;
  max-width: min(880px, 100%);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.followup-chip {
  border: 1px solid #d4e1f6;
  background: linear-gradient(145deg, #f7fbff, #edf3ff);
  color: #1f4471;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.followup-chip:hover {
  transform: translateY(-1px);
  border-color: #b8cdef;
  box-shadow: 0 8px 16px rgba(45, 89, 151, 0.12);
}

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

.suggest {
  border: 1px solid #d7e4fa;
  border-radius: 13px;
  background: linear-gradient(145deg, #f8fcff, #edf4ff);
  color: #21416b;
  text-align: left;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.suggest:hover {
  border-color: #adc7f1;
  box-shadow: 0 10px 20px rgba(76, 116, 176, 0.15);
}

.composer-wrap {
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(248, 252, 255, 0.95));
  padding: 12px 16px 16px;
}

.composer {
  width: min(940px, 100%);
  margin: 0 auto;
  border: 1px solid #cfddef;
  border-radius: 18px;
  background: linear-gradient(150deg, #ffffff, #f7fbff);
  box-shadow: 0 12px 30px rgba(44, 82, 135, 0.12);
  padding: 11px 12px;
  display: grid;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  min-height: 30px;
  max-height: 220px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.45;
  color: #1a2941;
}

.composer textarea::placeholder {
  color: #8090ad;
}

.tools-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.model-switch {
  border: 1px solid #d2ddf0;
  border-radius: 11px;
  padding: 2px;
  display: inline-flex;
  gap: 3px;
  background: #f3f8ff;
}

.model-btn {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #3d4f6c;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: 0.18s ease;
}

.model-btn--active {
  background: #fff;
  color: #153964;
  box-shadow: 0 1px 2px rgba(17, 33, 56, 0.1);
}

.topic-select {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid #d4dfef;
  border-radius: 11px;
  background: #f9fbff;
  padding: 7px 10px;
  color: #4b5c79;
}

.topic-select span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.topic-select select {
  border: 0;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #203e67;
}

.send-btn {
  border: 0;
  border-radius: 11px;
  padding: 9px 14px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 10px 20px rgba(31, 79, 139, 0.26);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

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

.status {
  color: var(--ok);
  font-size: 12px;
  font-weight: 800;
}

.tip {
  color: #6f7e98;
  font-size: 12px;
}

.sources {
  display: none !important;
}

.source-pill {
  border: 1px solid #c9daee;
  background: #eef5ff;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  color: #365b8f;
}

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

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    border: 0;
    padding: 0;
    margin: 0;
    background: rgba(12, 24, 42, 0.38);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

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

  .sidebar {
    display: grid;
    position: fixed;
    z-index: 20;
    top: 10px;
    left: 10px;
    bottom: 10px;
    width: min(340px, calc(100vw - 20px));
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.22s ease;
    overflow: hidden;
  }

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

  .chat-layout {
    border-radius: 16px;
  }

  .topbar {
    padding: 14px;
  }

  .topbar-row {
    align-items: center;
  }

  .topbar-actions {
    gap: 8px;
  }

  .topbar-title h1 {
    font-size: 21px;
  }

  .menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chat-stream,
  .composer,
  .sources {
    width: calc(100% - 20px);
  }
}

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

  .app {
    height: auto;
    min-height: 100dvh;
  }

  .chat-layout {
    min-height: calc(100dvh - 20px);
  }

  .chat-layout.chat-layout--active .topbar {
    padding: 11px 12px;
  }

  .chat-layout.chat-layout--active .topbar-title h1 {
    font-size: 18px;
  }

  .chat-feed {
    padding-top: 14px;
  }

  .message {
    font-size: 14px;
    border-radius: 14px;
    padding: 11px 12px;
  }

  .composer-wrap {
    padding: 10px;
  }

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

  .composer textarea {
    font-size: 15px;
  }

  .suggest-grid {
    grid-template-columns: 1fr;
  }

  .tools-row {
    grid-template-columns: 1fr;
  }

  .model-switch {
    width: fit-content;
  }

  .topic-select {
    width: 100%;
  }

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

  .send-btn {
    width: 100%;
  }

  .tip {
    display: none;
  }
}

@media (min-width: 1081px) {
  .menu-btn {
    display: none;
  }
}
