:root {
  --ink: #070f1c;
  --panel: #0f1c33;
  --panel-2: #152745;
  --line: rgba(210, 230, 255, 0.12);
  --text: #e8f1ff;
  --muted: #8fa6c4;
  --accent: #2bb8f0;
  --accent-ink: #041018;
  --navy: #0a1f4d;
  --user-bubble: #173054;
  --danger: #e07070;
  --radius: 18px;
  --font: "Figtree", system-ui, sans-serif;
  --display: "Syne", "Figtree", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
}
.logo {
  display: block;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
}
.logo-hero {
  width: min(100%, 22rem);
  border-radius: 1.25rem;
  box-shadow:
    0 0 0 1px rgba(43, 184, 240, 0.2),
    0 28px 70px rgba(0, 0, 0, 0.4);
  animation: rise 0.75s ease both;
}
.logo-sidebar {
  width: 7.5rem;
  border-radius: 0.85rem;
  box-shadow: 0 0 0 1px rgba(43, 184, 240, 0.18);
}
.logo-welcome {
  width: min(100%, 16rem);
  margin: 0 auto 1.25rem;
  border-radius: 1.1rem;
  box-shadow:
    0 0 0 1px rgba(43, 184, 240, 0.2),
    0 22px 55px rgba(0, 0, 0, 0.35);
}

/* ——— Landing / login ——— */
.landing {
  min-height: 100%;
  position: relative;
  overflow: hidden;
}
.landing-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 55% at 12% 18%, rgba(43, 184, 240, 0.22), transparent 55%),
    radial-gradient(ellipse 70% 50% at 88% 8%, rgba(10, 31, 77, 0.55), transparent 50%),
    linear-gradient(160deg, #050b16 0%, #0a1830 45%, #070f1c 100%);
  z-index: -1;
}
.landing-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.45;
  pointer-events: none;
}
.landing-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 6vh 1.5rem 3rem;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 3rem;
  align-items: center;
  min-height: calc(100vh - 4rem);
}
.brand-hero {
  display: block;
  margin-bottom: 1.5rem;
}
.landing-copy h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.85rem, 3.6vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  max-width: 16ch;
  animation: rise 0.8s 0.08s ease both;
}
.landing-copy .lede {
  margin: 1rem 0 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
  animation: rise 0.8s 0.14s ease both;
}
.landing-main--single {
  grid-template-columns: 1fr;
  justify-items: center;
  max-width: 28rem;
}
.logo-panel {
  width: 9rem;
  margin: 0 auto 1.25rem;
  border-radius: 1rem;
  box-shadow: 0 0 0 1px rgba(43, 184, 240, 0.18);
}
.login-panel {
  background: rgba(21, 32, 27, 0.82);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.75rem 1.6rem 1.5rem;
  backdrop-filter: blur(12px);
  animation: rise 0.85s 0.15s ease both;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.login-panel h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}
.panel-hint {
  margin: 0.35rem 0 1.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.login-panel label {
  display: block;
  margin-bottom: 0.9rem;
}
.login-panel label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.login-panel input {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  outline: none;
}
.login-panel input:focus {
  border-color: rgba(43, 184, 240, 0.55);
  box-shadow: 0 0 0 3px rgba(43, 184, 240, 0.14);
}
.login-panel button[type="submit"] {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.9rem 1rem;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.login-panel button[type="submit"]:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.login-panel button[type="submit"]:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}
.form-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}
.form-success {
  margin: 0.85rem 0 0;
  color: #7ec8a3;
  font-size: 0.9rem;
}
.forgot-link {
  margin: 0.35rem 0 0.85rem;
  font-size: 0.9rem;
}
.forgot-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.forgot-link a:hover {
  text-decoration: underline;
}
.landing-foot {
  padding: 0 2rem 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

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

/* ——— App shell ——— */
.app-body { height: 100%; overflow: hidden; }
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(43, 184, 240, 0.1), transparent 50%),
    var(--ink);
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem 0.85rem;
  background: rgba(15, 22, 19, 0.95);
  border-right: 1px solid var(--line);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.35rem;
}
.brand-compact {
  flex: 1;
  min-width: 0;
}
.new-chat-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.new-chat-btn:hover {
  background: var(--panel-2);
  border-color: rgba(43, 184, 240, 0.4);
}
.conv-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 0.15rem;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 10px;
  padding: 0.55rem 0.45rem 0.55rem 0.7rem;
  cursor: pointer;
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
  color: var(--muted);
}
.conv-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.conv-item.active {
  background: var(--user-bubble);
  color: var(--text);
}
.conv-item span {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.92rem;
}
.conv-item .del {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--danger); background: rgba(224,112,112,0.12); }
.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}
.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.main-col {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  height: 100%;
}
.chat-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.model-wrap select {
  appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238fa398' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") right 0.8rem center no-repeat;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 2.2rem 0.55rem 1rem;
  min-width: 12rem;
  cursor: pointer;
}
.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  width: 2.35rem;
  height: 2.35rem;
  cursor: pointer;
}
.mobile-only { display: none; }

.chat-stage {
  overflow: auto;
  padding: 1.5rem 1.25rem 1rem;
}
.welcome {
  max-width: 40rem;
  margin: 12vh auto 0;
  text-align: center;
  animation: rise 0.6s ease both;
}
.welcome p {
  margin: 0 auto;
  color: var(--muted);
  max-width: 28rem;
  line-height: 1.5;
}
.messages {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding-bottom: 1rem;
}
.msg {
  display: grid;
  gap: 0.45rem;
  animation: rise 0.35s ease both;
}
.msg-role {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.msg.user .msg-body {
  background: var(--user-bubble);
  border: 1px solid var(--line);
  border-radius: 16px 16px 4px 16px;
  padding: 0.9rem 1rem;
  white-space: pre-wrap;
  line-height: 1.55;
}
.msg.assistant .msg-body {
  line-height: 1.65;
  padding: 0.15rem 0.15rem;
}
.msg.assistant .msg-body :is(p, ul, ol) { margin: 0.55rem 0; }
.msg.assistant .msg-body :is(ul, ol) { padding-left: 1.25rem; }
.msg.assistant .msg-body pre {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.86rem;
}
.msg.assistant .msg-body code {
  font-family: var(--mono);
  font-size: 0.9em;
}
.msg.assistant .msg-body :not(pre) > code {
  background: rgba(255,255,255,0.06);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.msg.streaming .msg-body::after {
  content: "▋";
  margin-left: 2px;
  animation: blink 1s steps(1) infinite;
  color: var(--accent);
}
@keyframes blink {
  50% { opacity: 0; }
}

.composer-wrap {
  padding: 0.5rem 1.25rem 1.1rem;
}
.composer {
  max-width: 48rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.65rem 0.65rem 0.65rem 1rem;
  box-shadow: 0 18px 50px rgba(0,0,0,0.25);
  transition: border-color 0.15s ease;
}
.composer:focus-within {
  border-color: rgba(43, 184, 240, 0.45);
}
.composer textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  max-height: 180px;
  line-height: 1.45;
  padding: 0.45rem 0;
}
.composer button {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border-radius: 12px;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
}
.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.composer-note {
  max-width: 48rem;
  margin: 0.55rem auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 860px) {
  .landing-main {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding-top: 2vh;
  }
  .landing-copy h1 { max-width: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  #close-sidebar { display: inline-flex; align-items: center; justify-content: center; }
}
@media (min-width: 861px) {
  #close-sidebar { display: none; }
}
