:root {
  --accent: #fff44f;
  --accent-ink: #23230a;
  --radius: 22px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

html[data-theme="light"] {
  --bg: #f4f5f9;
  --sd: rgba(166, 175, 198, 0.72);
  --sl: #ffffff;
  --ink: #31344b;
  --muted: #8d93a8;
  --hover: rgba(255, 244, 79, 0.28);
  --raise: 8px 8px 16px var(--sd), -8px -8px 16px var(--sl);
  --raise-sm: 4px 4px 9px var(--sd), -4px -4px 9px var(--sl);
  --sink: inset 5px 5px 10px var(--sd), inset -5px -5px 10px var(--sl);
  --sink-sm: inset 3px 3px 7px var(--sd), inset -3px -3px 7px var(--sl);
}

html[data-theme="dark"] {
  --bg: #0a0a0d;
  --sd: rgba(0, 0, 0, 0.92);
  --sl: rgba(255, 255, 255, 0.075);
  --ink: #eceef6;
  --muted: #666b80;
  --hover: rgba(255, 244, 79, 0.14);
  --raise: 8px 8px 18px var(--sd), -6px -6px 16px var(--sl);
  --raise-sm: 4px 4px 10px var(--sd), -3px -3px 8px var(--sl);
  --sink: inset 6px 6px 12px var(--sd), inset -4px -4px 10px var(--sl);
  --sink-sm: inset 4px 4px 8px var(--sd), inset -2px -2px 6px var(--sl);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  transition: background 0.35s ease, color 0.35s ease;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;
  padding: 18px;
  gap: 18px;
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 18px;
  border-radius: var(--radius);
  box-shadow: var(--raise);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: linear-gradient(145deg, #fff78a, var(--accent));
  box-shadow: var(--raise-sm);
}
.logo svg { width: 26px; height: 26px; }

.brand h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand h1 span { color: var(--muted); font-weight: 500; }

.btn-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 13px;
  border: none;
  border-radius: 16px;
  font: 600 0.95rem var(--font);
  color: var(--accent-ink);
  background: linear-gradient(145deg, #fff78a, var(--accent));
  box-shadow: var(--raise-sm);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-new svg { width: 17px; height: 17px; }
.btn-new:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn-new:active {
  transform: translateY(0);
  box-shadow: var(--sink-sm);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}

.session-item {
  position: relative;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--raise-sm);
  transition: box-shadow 0.15s ease, color 0.15s ease;
}
.session-item:hover { color: var(--accent-ink); }
.session-item.active { box-shadow: var(--sink-sm); color: var(--ink); }
.session-item .del {
  position: absolute;
  right: 8px;
  top: 50%;
  translate: 0 -50%;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  display: grid;
  place-items: center;
}
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: #ff5470; }
.session-item .del svg { width: 14px; height: 14px; }
.session-item.has-del .title { max-width: calc(100% - 30px); overflow: hidden; text-overflow: ellipsis; }

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

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  padding: 9px 13px;
  border-radius: 12px;
  box-shadow: var(--sink-sm);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.on { background: #37d67a; box-shadow: 0 0 8px rgba(55, 214, 122, 0.7); }
.dot.off { background: #ff5470; box-shadow: 0 0 8px rgba(255, 84, 112, 0.6); }

.icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--raise-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: box-shadow 0.15s ease;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { box-shadow: var(--sink-sm); }

/* ---------- Chat column ---------- */

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 22px;
  border-radius: var(--radius);
  box-shadow: var(--raise);
  margin-bottom: 18px;
}

.title-wrap { display: flex; align-items: center; gap: 11px; min-width: 0; }
.title-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 244, 79, 0.75);
  flex: none;
}
#chatTitle {
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-badge {
  font: 600 0.74rem var(--mono);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--sink-sm);
  white-space: nowrap;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}

/* ---------- Empty state ---------- */

.empty-state {
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: rise 0.5s ease both;
}
.empty-orb {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent);
  box-shadow: var(--raise);
}
.empty-orb svg { width: 46px; height: 46px; filter: drop-shadow(0 2px 6px rgba(255, 244, 79, 0.45)); }
.empty-state h2 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.01em; }
.empty-state p { color: var(--muted); font-weight: 500; }

/* ---------- Bubbles ---------- */

.bubble {
  max-width: min(76%, 720px);
  padding: 15px 19px;
  border-radius: 20px;
  font-size: 0.94rem;
  line-height: 1.62;
  word-break: break-word;
  animation: rise 0.3s ease both;
}

.bubble.user {
  align-self: flex-end;
  border-bottom-right-radius: 7px;
  box-shadow: var(--raise-sm);
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    linear-gradient(135deg, var(--accent), transparent 60%) border-box;
  border: 1.5px solid transparent;
}

.bubble.ai {
  align-self: flex-start;
  border-bottom-left-radius: 7px;
  box-shadow: var(--sink);
}

.bubble.ai > * + * { margin-top: 0.7em; }
.bubble.ai h1, .bubble.ai h2, .bubble.ai h3 { font-size: 1.02rem; font-weight: 700; }
.bubble.ai ul, .bubble.ai ol { padding-left: 1.3em; }
.bubble.ai li + li { margin-top: 0.25em; }
.bubble.ai a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.bubble.ai code {
  font-family: var(--mono);
  font-size: 0.82em;
  padding: 2px 7px;
  border-radius: 8px;
  box-shadow: var(--sink-sm);
}
.bubble.ai pre {
  padding: 13px 15px;
  border-radius: 13px;
  overflow-x: auto;
  box-shadow: var(--sink-sm);
  scrollbar-width: thin;
}
.bubble.ai pre code { padding: 0; box-shadow: none; background: none; }

.typing { display: inline-flex; gap: 7px; padding: 6px 2px; }
.typing i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }

.error-bubble {
  align-self: center;
  color: #ff5470;
  font-weight: 500;
  font-size: 0.85rem;
  box-shadow: var(--sink-sm);
  border-radius: 14px;
  padding: 10px 18px;
}

/* ---------- Composer ---------- */

.composer { padding-top: 18px; }

#composerForm {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 12px 12px 24px;
  border-radius: 999px;
  box-shadow: var(--raise);
}

#input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: 500 0.97rem var(--font);
}
#input::placeholder { color: var(--muted); }

#sendBtn {
  flex: none;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--accent-ink);
  background: linear-gradient(145deg, #fff78a, var(--accent));
  box-shadow: 5px 5px 12px var(--sd), -5px -5px 12px var(--sl), 0 0 0 0 rgba(255, 244, 79, 0.5);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.15s ease;
}
#sendBtn svg { width: 21px; height: 21px; }
#sendBtn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 5px 5px 14px var(--sd), -5px -5px 12px var(--sl), 0 0 18px rgba(255, 244, 79, 0.45);
}
#sendBtn:active:not(:disabled) { transform: translateY(0); box-shadow: var(--sink-sm); }
#sendBtn:disabled { filter: saturate(0.25) opacity(0.55); cursor: not-allowed; }

@keyframes blink {
  0%, 70%, 100% { opacity: 0.25; transform: scale(0.85); }
  35% { opacity: 1; transform: scale(1); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding: 12px; gap: 12px; }
  .sidebar { flex-direction: row; align-items: center; padding: 12px 14px; gap: 12px; }
  .brand h1 { display: none; }
  .session-list { flex-direction: row; overflow-x: auto; }
  .session-item { flex: none; }
  .side-foot { margin-left: auto; }
  .status { display: none; }
  .bubble { max-width: 90%; }
}
