:root {
  --ink: #1a2748;
  --muted: #5a6a8f;
  --paper: #f6f4f0;
  --brand: #273f82;
  --brand-2: #1e3270;
  --accent: #f49f43;
  --accent-2: #e0892e;
  --line: rgba(39, 63, 130, 0.12);
  --shadow: 0 20px 60px rgba(39, 63, 130, 0.12);
  --sidebar: #1a2748;
  --user-bubble: #273f82;
  --assist-bubble: #ffffff;
  --display: "Montserrat", system-ui, sans-serif;
  --body: "Source Serif 4", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar-w: 280px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--display);
}

.chat-atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1000px 520px at 0% 0%, rgba(244, 159, 67, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 10%, rgba(39, 63, 130, 0.14), transparent 50%),
    linear-gradient(165deg, #faf8f4 0%, #f1eee8 40%, #e6eaf4 100%);
}

.chat-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* —— Sidebar —— */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem 1rem 1rem;
  background:
    linear-gradient(180deg, #22356e 0%, var(--sidebar) 45%, #15203c 100%);
  color: #eef2fb;
  border-right: 1px solid rgba(244, 159, 67, 0.25);
  min-height: 100vh;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow: hidden;
}

.sidebar-brand {
  padding: 0.35rem 0.4rem 0.75rem;
  animation: rise 0.55s ease both;
}

.sidebar-logo {
  width: 7.5rem;
  height: auto;
  display: block;
  margin-bottom: 0.35rem;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
}

.sidebar-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.sidebar-sub {
  margin: 0.15rem 0 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  opacity: 0.72;
  letter-spacing: 0.02em;
}

.btn-new {
  appearance: none;
  border: 1px solid rgba(244, 159, 67, 0.55);
  background: rgba(244, 159, 67, 0.14);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.75rem 0.9rem;
  border-radius: 0.65rem;
  cursor: pointer;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-new:hover {
  background: rgba(244, 159, 67, 0.28);
}

.btn-new:active {
  transform: translateY(1px);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.15rem 0 0.35rem;
}

.nav-section-label {
  margin: 0.7rem 0.55rem 0.25rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.84);
  text-align: left;
  font-family: var(--display);
  font-size: 0.86rem;
  font-weight: 650;
  padding: 0.62rem 0.7rem;
  border-radius: 0.55rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-ico {
  width: 1.25rem;
  flex: 0 0 auto;
  text-align: center;
  opacity: 0.85;
  font-size: 0.82rem;
  font-family: var(--mono);
}

.recents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.55rem 0.1rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.chat-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 0.15rem;
}

.chat-list-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-align: left;
  font-family: var(--display);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.65rem 0.7rem;
  border-radius: 0.55rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-item:hover,
.chat-list-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.chat-list-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: center;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.sidebar-foot a {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
}

.sidebar-foot a:hover {
  color: var(--accent);
}

.runtime {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  opacity: 0.75;
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #8a97b8;
  box-shadow: 0 0 0 3px rgba(138, 151, 184, 0.25);
}

.dot.ok {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(244, 159, 67, 0.25);
}

.dot.warn {
  background: #e35d2a;
  box-shadow: 0 0 0 3px rgba(227, 93, 42, 0.2);
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 30;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.55rem;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* —— Main —— */
.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-width: 0;
}

.chat-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px);
}

.chat-top-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brand);
  min-width: 0;
}

.top-logo {
  width: 2.6rem;
  height: auto;
}

#chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-top-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.thread {
  overflow: auto;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 1rem;
  scroll-behavior: smooth;
}

.empty {
  max-width: 40rem;
  margin: 12vh auto 0;
  text-align: center;
  animation: rise 0.7s ease both;
}

.empty-logo {
  width: clamp(8rem, 22vw, 12rem);
  height: auto;
  margin: 0 auto 1rem;
  display: block;
}

.empty h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.04em;
  color: var(--brand);
}

.empty p {
  margin: 0 auto 1.5rem;
  max-width: 32rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.55;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.suggestions button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font-family: var(--display);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
  padding: 0.85rem 0.95rem;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.suggestions button:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(39, 63, 130, 0.08);
}

.message-row {
  display: flex;
  margin: 0 auto 1.1rem;
  max-width: 48rem;
  animation: rise 0.35s ease both;
}

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

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

.bubble {
  max-width: min(100%, 40rem);
  padding: 0.95rem 1.1rem;
  border-radius: 1.1rem;
  line-height: 1.55;
  font-family: var(--body);
  font-size: 1.02rem;
  box-shadow: 0 8px 28px rgba(39, 63, 130, 0.06);
}

.message-row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 0.35rem;
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 500;
}

.message-row.assistant .bubble {
  background: var(--assist-bubble);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 0.35rem;
}

.message-row.error .bubble {
  border-color: rgba(227, 93, 42, 0.45);
  background: #fff6f2;
  color: #8a2e10;
}

.bubble .md p {
  margin: 0 0 0.75rem;
}

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

.bubble .md pre {
  margin: 0.65rem 0;
  padding: 0.75rem 0.85rem;
  overflow: auto;
  background: #1a2748;
  color: #e8eefc;
  border-radius: 0.55rem;
  font-family: var(--mono);
  font-size: 0.8rem;
}

.bubble .md code {
  font-family: var(--mono);
  font-size: 0.86em;
}

.bubble .md :not(pre) > code {
  background: rgba(39, 63, 130, 0.08);
  padding: 0.08em 0.28em;
  border-radius: 0.25rem;
}

.msg-meta {
  margin-top: 0.55rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.msg-meta summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
}

.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 0.15ch;
  animation: blink 1s steps(1) infinite;
  color: var(--accent);
}

/* —— Composer —— */
.composer-wrap {
  padding: 0.5rem clamp(1rem, 4vw, 2.5rem) 1rem;
  background: linear-gradient(180deg, transparent, rgba(246, 244, 240, 0.95) 30%);
}

.composer {
  max-width: 48rem;
  margin: 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 1.15rem;
  box-shadow: var(--shadow);
  padding: 0.65rem 0.75rem 0.75rem;
}

.composer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.15rem 0.35rem 0.55rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.field-inline select {
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 0.25rem 0.4rem;
  font-family: var(--mono);
  background: #fff;
  color: var(--ink);
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: end;
}

#prompt {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  font-family: var(--display);
  font-size: 0.98rem;
  line-height: 1.45;
  max-height: 10rem;
  min-height: 1.4rem;
  padding: 0.55rem 0.45rem;
  background: transparent;
  color: var(--ink);
}

.btn-send,
.btn-stop {
  appearance: none;
  border: 0;
  border-radius: 0.75rem;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
}

.btn-send {
  background: var(--brand);
  color: #fff;
}

.btn-send:hover {
  background: var(--brand-2);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: wait;
}

.btn-stop {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--line);
}

.legal {
  max-width: 48rem;
  margin: 0.55rem auto 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
}

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

@keyframes blink {
  50% {
    opacity: 0;
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .chat-app.sidebar-open .sidebar {
    transform: none;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

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

  .chat-top {
    padding-left: 3.5rem;
  }

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

  .btn-send,
  .btn-stop {
    width: 100%;
  }
}
