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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #212121;
  color: #ececec;
  height: 100vh;
  overflow: hidden;
}

.layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: #171717;
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  border-right: 1px solid #2a2a2a;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo svg path { fill: #93c5fd; }

.logo-text {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.3px;
}

.icon-btn {
  background: none;
  border: none;
  color: #8e8ea0;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: #2a2a2a; color: #ececec; }

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b6b7b;
  padding: 0 10px 6px;
}

.history-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-empty {
  font-size: 13px;
  color: #555;
  padding: 8px 10px;
}

.history-item {
  font-size: 13px;
  color: #b0b0c0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}
.history-item:hover { background: #2a2a2a; color: #ececec; }
.history-item.active { background: #2a2a2a; color: #fff; }

.sidebar-footer {
  border-top: 1px solid #2a2a2a;
  padding-top: 12px;
  margin-top: 8px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 14px;
  color: #b0b0c0;
}
.user-pill:hover { background: #2a2a2a; color: #ececec; }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #212121;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 3px; }

/* ── Welcome ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 24px;
  gap: 20px;
  min-height: 100%;
}

.welcome-cloud svg { filter: drop-shadow(0 4px 24px rgba(147,197,253,0.25)); }

.welcome-title {
  font-size: 28px;
  font-weight: 600;
  color: #ececec;
  letter-spacing: -0.5px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 560px;
}

.chip {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  color: #b0b0c0;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { background: #333; border-color: #555; color: #ececec; }

/* ── Message bubbles ── */
.msg-row {
  display: flex;
  padding: 8px 20%;
  gap: 12px;
  animation: fadeUp 0.2s ease;
}

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

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-row.user .bubble {
  background: #2f2f2f;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  max-width: 72%;
  font-size: 15px;
  line-height: 1.6;
  color: #ececec;
}

.msg-row.assistant {
  flex-direction: column;
}

.assistant-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding-left: 2px;
}

.assistant-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.assistant-name {
  font-size: 13px;
  font-weight: 600;
  color: #93c5fd;
}

.msg-row.assistant .bubble {
  background: none;
  padding: 0 2px;
  max-width: 100%;
  font-size: 15px;
  line-height: 1.75;
  color: #d1d1d1;
}

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #555;
  animation: dot 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input ── */
.input-wrap {
  padding: 12px 20% 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-box {
  background: #2f2f2f;
  border: 1px solid #3a3a3a;
  border-radius: 16px;
  display: flex;
  align-items: flex-end;
  padding: 12px 12px 12px 16px;
  gap: 8px;
  transition: border-color 0.15s;
}
.input-box:focus-within { border-color: #555; }

.input-box textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: #ececec;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
}
.input-box textarea::placeholder { color: #555; }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: #fff;
  color: #212121;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover { background: #e0e0e0; }
.send-btn:disabled { background: #333; color: #555; cursor: default; }

.input-hint {
  font-size: 11px;
  color: #444;
  text-align: center;
}

/* ── Message animations ── */
@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row {
  animation: msgSlideIn 0.22s ease forwards;
}

/* ── Glitch effect for meltdown messages ── */
@keyframes glitch1 {
  0%   { clip-path: inset(20% 0 60% 0); transform: translate(-3px, 0); }
  20%  { clip-path: inset(70% 0 5% 0);  transform: translate(3px, 0); }
  40%  { clip-path: inset(40% 0 40% 0); transform: translate(-1px, 0); }
  60%  { clip-path: inset(5% 0 75% 0);  transform: translate(2px, 0); }
  80%  { clip-path: inset(55% 0 20% 0); transform: translate(-2px, 0); }
  100% { clip-path: inset(20% 0 60% 0); transform: translate(0, 0); }
}
@keyframes glitch2 {
  0%   { clip-path: inset(60% 0 10% 0); transform: translate(3px, 0); filter: hue-rotate(90deg); }
  25%  { clip-path: inset(10% 0 70% 0); transform: translate(-3px, 0); filter: hue-rotate(180deg); }
  50%  { clip-path: inset(80% 0 5% 0);  transform: translate(1px, 0);  filter: hue-rotate(270deg); }
  75%  { clip-path: inset(30% 0 50% 0); transform: translate(-1px, 0); filter: hue-rotate(0deg); }
  100% { clip-path: inset(60% 0 10% 0); transform: translate(0, 0);   filter: hue-rotate(90deg); }
}
@keyframes iconSpin {
  0%   { transform: rotate(0deg) scale(1); filter: hue-rotate(0deg); }
  25%  { transform: rotate(15deg) scale(1.15); filter: hue-rotate(120deg); }
  50%  { transform: rotate(-10deg) scale(0.9); filter: hue-rotate(240deg); }
  75%  { transform: rotate(20deg) scale(1.1); filter: hue-rotate(180deg); }
  100% { transform: rotate(0deg) scale(1); filter: hue-rotate(360deg); }
}
@keyframes textShake {
  0%, 100% { transform: translate(0, 0); }
  10%  { transform: translate(-2px, 1px); }
  20%  { transform: translate(2px, -1px); }
  30%  { transform: translate(-1px, 2px); }
  40%  { transform: translate(1px, -2px); }
  50%  { transform: translate(-2px, -1px); }
  60%  { transform: translate(2px, 1px); }
  70%  { transform: translate(-1px, -1px); }
  80%  { transform: translate(1px, 2px); }
  90%  { transform: translate(-2px, 0); }
}
@keyframes colorFlicker {
  0%, 100% { color: #d1d1d1; }
  15%  { color: #f87171; }
  30%  { color: #fbbf24; }
  45%  { color: #34d399; }
  60%  { color: #93c5fd; }
  75%  { color: #c084fc; }
}

.bubble-glitch {
  position: relative;
  animation: textShake 0.4s ease 0s 3, colorFlicker 1.8s ease 0.1s 2;
}
.bubble-glitch::before {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  color: #f87171;
  animation: glitch1 0.6s steps(1) 0.2s 4;
  pointer-events: none;
  opacity: 0.5;
}
.bubble-glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  color: #93c5fd;
  animation: glitch2 0.5s steps(1) 0.1s 4;
  pointer-events: none;
  opacity: 0.4;
}

.icon-glitch {
  animation: iconSpin 0.8s ease 0s 2;
}

/* ── Chip hover pop ── */
@keyframes chipPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}
.chip:active { animation: chipPop 0.15s ease; }

/* ── Welcome screen float ── */
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-8px); }
}
.welcome-cloud svg { animation: float 4s ease-in-out infinite; }

/* ── Typing dots pulse (enhanced) ── */
@keyframes dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40%           { transform: scale(1.1); opacity: 1; }
}
.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #60a5fa;
  animation: dot 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; background: #818cf8; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; background: #a78bfa; }

/* ── Send button pulse on hover ── */
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(255,255,255,0); }
}
.send-btn:not(:disabled):hover { animation: btnPulse 0.6s ease; }

/* ── History item slide in ── */
@keyframes historySlide {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
.history-item { animation: historySlide 0.18s ease forwards; }

/* ── Assistant icon pulse on load ── */
@keyframes iconPop {
  0%   { transform: scale(0.7); opacity: 0; }
  70%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.assistant-icon { animation: iconPop 0.3s ease forwards; }

/* ── Input box focus glow ── */
@keyframes focusGlow {
  0%, 100% { border-color: #555; }
  50%       { border-color: #818cf8; }
}
.input-box:focus-within {
  animation: focusGlow 2s ease infinite;
  border-color: #555;
}

/* ── Bubble pop-in ── */
@keyframes bubblePop {
  0%   { transform: scale(0.94); opacity: 0; }
  70%  { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}
.msg-row .bubble { animation: bubblePop 0.2s ease forwards; }

/* ── Settings modal ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
  padding: 0 0 80px 12px;
}
.settings-overlay.settings-visible { opacity: 1; }
.settings-panel {
  background: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 16px;
  width: 300px;
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.2s ease;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.settings-overlay.settings-visible .settings-panel { transform: translateY(0); }
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid #2a2a2a;
}
.settings-title { font-size: 14px; font-weight: 600; color: #ececec; letter-spacing: 0.02em; }
.settings-close {
  background: none; border: none; color: #666; cursor: pointer;
  padding: 4px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.settings-close:hover { color: #ececec; background: #2a2a2a; }
.settings-section { padding: 16px 18px; border-bottom: 1px solid #222; }
.settings-section:last-child { border-bottom: none; }
.settings-label { font-size: 12px; font-weight: 600; color: #b0b0c0; text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 4px; }
.settings-sub { font-size: 12px; color: #555; margin-bottom: 10px; line-height: 1.5; }
.settings-name-row { display: flex; gap: 8px; }
.settings-input {
  flex: 1; background: #252525; border: 1px solid #3a3a3a; border-radius: 8px;
  color: #ececec; font-size: 13px; font-family: inherit; padding: 8px 10px; outline: none;
  transition: border-color 0.15s;
}
.settings-input:focus { border-color: #555; }
.settings-input-disabled { opacity: 0.4; cursor: not-allowed; }
.settings-save-btn {
  background: #93c5fd; border: none; border-radius: 8px; color: #111;
  font-size: 13px; font-weight: 600; padding: 8px 14px; cursor: pointer;
  transition: background 0.15s; white-space: nowrap;
}
.settings-save-btn:hover { background: #bfd9fe; }
.settings-btn-disabled { opacity: 0.35; cursor: not-allowed !important; background: #444 !important; color: #888 !important; }
.settings-cooldown { font-size: 11px; color: #666; margin-top: 8px; }
.settings-error { font-size: 12px; color: #f87171; margin-top: 8px; line-height: 1.4; }
.settings-filter-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: #1e2d1e; border: 1px solid #2d4a2d; color: #6ee76e;
  font-size: 12px; padding: 5px 10px; border-radius: 20px;
}
.settings-section-danger .settings-label { color: #888; }
.settings-clear-btn {
  background: none; border: 1px solid #3a2222; border-radius: 8px;
  color: #f87171; font-size: 12px; padding: 7px 12px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.settings-clear-btn:hover { background: #2a1212; border-color: #f87171; }

/* ── Stream cursor ── */
.stream-cursor {
  display: inline-block;
  color: #818cf8;
  animation: cursorBlink 0.7s ease-in-out infinite;
  font-size: 0.9em;
  margin-left: 1px;
  vertical-align: middle;
}
@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Streaming bubble smooth fade-in ── */
.stream-bubble {
  animation: bubblePop 0.15s ease forwards;
}
