@import url("https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

:root {
  --red: #ff1e32;
  --red-hot: #ff4a58;
  --red-deep: #c41022;
  --bg: #050508;
  --bg-2: #0a0a10;
  --text: #f4f4f8;
  --muted: #9a9aa8;
  --line: rgba(255, 255, 255, .1);
  --glass: rgba(14, 14, 20, .72);
  --glass-strong: rgba(10, 10, 16, .88);
  --side: rgba(8, 8, 12, .92);
  --green: #34d399;
  --yellow: #fbbf24;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
}
body {
  background:
    radial-gradient(ellipse 70% 42% at 14% -8%, rgba(255, 30, 50, .22), transparent 55%),
    radial-gradient(ellipse 50% 36% at 88% 8%, rgba(255, 30, 50, .08), transparent 50%),
    linear-gradient(180deg, #0a0608 0%, #050508 45%, #030306 100%);
}

/* —— Cinematic boot —— */
.ai-boot {
  position: fixed; inset: 0; z-index: 400;
  display: grid; place-items: center;
  background: #000;
  transition: opacity .7s var(--ease-out), visibility .7s;
}
.ai-boot.is-done {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.ai-boot-ambient {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 55% 40% at 50% 18%, rgba(255, 30, 50, .28), transparent 58%),
    radial-gradient(ellipse 40% 30% at 50% 72%, rgba(255, 30, 50, .07), transparent 60%);
  animation: ai-boot-glow 5.5s ease-in-out infinite;
}
.ai-boot-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: .12;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 55% 50% at 50% 42%, #000 20%, transparent 75%);
}
.ai-boot-scan {
  position: absolute; left: 0; right: 0; height: 28%;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(255, 30, 50, .07), transparent);
  animation: ai-boot-scan 3.2s ease-in-out infinite;
  opacity: .5;
}
.ai-boot-inner {
  position: relative; z-index: 1;
  width: min(340px, calc(100vw - 2.5rem));
  text-align: center;
  animation: ai-boot-in .75s var(--ease-out) both;
}
.ai-boot-mark {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 18px; display: grid; place-items: center;
  font-family: Syne, sans-serif; font-weight: 800; font-size: 22px; letter-spacing: .04em;
  background: linear-gradient(145deg, var(--red-hot), var(--red-deep));
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, .12) inset,
    0 12px 36px rgba(255, 30, 50, .45),
    0 0 48px rgba(255, 30, 50, .25);
}
.ai-boot-title {
  margin: 0;
  font-family: Syne, sans-serif;
  font-weight: 800; letter-spacing: .28em; font-size: .95rem;
  color: #fff;
}
.ai-boot-sub {
  margin: .45rem 0 1.25rem;
  font-size: .82rem; color: var(--muted); letter-spacing: .04em;
}
.ai-boot-status {
  margin: 0 0 1.05rem;
  min-height: 1.35em;
  color: #c8c8d0;
  font-size: .9rem; font-weight: 500;
  transition: opacity .28s ease, transform .28s ease;
}
.ai-boot-status.is-swap { opacity: 0; transform: translateY(5px); }
.ai-boot-bar {
  width: 100%; height: 2px; margin: 0 auto;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
  box-shadow: 0 0 18px rgba(255, 30, 50, .12);
}
.ai-boot-fill {
  height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff3a4a, var(--red), #ff6b74);
  box-shadow: 0 0 14px rgba(255, 30, 50, .65);
  transition: width .55s var(--ease-out);
}
.ai-boot-log {
  list-style: none; margin: 1.3rem 0 0; padding: 0;
  text-align: left;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .68rem; line-height: 1.55;
  color: rgba(160, 160, 172, .85);
  max-height: 5.2em; overflow: hidden;
}
.ai-boot-log li {
  opacity: .45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: ai-boot-log .4s ease both;
}
.ai-boot-log li.is-current { opacity: 1; color: #e8e8ee; }
.ai-boot-log li.is-done::before { content: "✓ "; color: var(--red); }
.ai-boot-log li.is-current:not(.is-done)::before { content: "› "; color: var(--red); }
.ai-boot.is-ready .ai-boot-status { color: #fff; }
.ai-boot.is-ready .ai-boot-fill { box-shadow: 0 0 22px rgba(255, 30, 50, .85); }
.ai-boot-skip {
  margin: 1.1rem 0 0;
  font-size: .72rem;
  color: rgba(160, 160, 172, .75);
  letter-spacing: .04em;
}
.ai-boot.is-done,
.ai-boot[hidden] {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

@keyframes ai-boot-glow {
  0%, 100% { opacity: .85; }
  50% { opacity: 1; }
}
@keyframes ai-boot-scan {
  0% { top: -10%; }
  100% { top: 90%; }
}
@keyframes ai-boot-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: none; }
}
@keyframes ai-boot-log {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: .45; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-boot-ambient, .ai-boot-scan { animation: none; }
  .ai-boot-inner { animation: none; }
  .bubble { animation: none !important; }
}

/* —— App shell —— */
.shell {
  display: flex; min-height: 100vh;
  opacity: 0;
  transition: opacity .55s var(--ease-out);
}
.shell.is-ready { opacity: 1; }
.shell.is-booting { pointer-events: none; }
.shell.is-ready { pointer-events: auto; }

.sidebar {
  width: 288px;
  flex-shrink: 0;
  background: var(--side);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  z-index: 20;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 14px; padding: 0 2px;
}
.side-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-mark {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center;
  font-family: Syne, sans-serif; font-weight: 800; font-size: 11px;
  background: linear-gradient(145deg, var(--red-hot), var(--red-deep));
  box-shadow: 0 6px 16px rgba(255, 30, 50, .35);
}
.side-brand strong { display: block; font-family: Syne, sans-serif; font-size: 14px; }
.side-brand em { display: block; font-style: normal; font-size: 11px; color: var(--muted); }
.thread-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.thread-item {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  font: inherit;
  width: 100%;
  transition: background .18s ease, border-color .18s ease;
}
.thread-item:hover { background: rgba(255,255,255,.045); border-color: rgba(255,255,255,.06); }
.thread-item.active {
  background: rgba(255, 30, 50, .12);
  border-color: rgba(255, 30, 50, .38);
  box-shadow: 0 0 0 1px rgba(255, 30, 50, .08) inset;
}
.thread-item .t-title {
  display: block; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item .t-meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.thread-actions { display: flex; gap: 4px; margin-top: 7px; }
.thread-actions button {
  font-size: 11px; padding: 3px 8px; border-radius: 7px;
  border: 1px solid var(--line); background: rgba(0,0,0,.3); color: var(--muted); cursor: pointer;
}
.side-foot { font-size: 11px; color: var(--muted); margin: 12px 4px 0; }

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  width: min(840px, 100%);
  margin: 0 auto;
}

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-family: Syne, sans-serif; font-weight: 800; font-size: 13px;
  background: linear-gradient(145deg, var(--red-hot), var(--red-deep));
  box-shadow: 0 8px 22px rgba(255, 30, 50, .4); flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand strong {
  display: block; font-family: Syne, sans-serif; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw;
}
.brand em { display: block; font-style: normal; color: var(--muted); font-size: 11px; margin-top: 1px; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tier-badge {
  font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  background: rgba(255, 30, 50, .16); border: 1px solid rgba(255, 30, 50, .42); color: #ffc4ca;
  letter-spacing: .02em;
}
.quota-pill {
  font-size: 11px; color: var(--muted); padding: 5px 9px; border-radius: 9px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
}

.btn {
  border: 0; cursor: pointer; font: inherit; border-radius: 11px;
  padding: 10px 14px; color: var(--text); background: rgba(255,255,255,.06);
  transition: transform .15s ease, filter .15s ease, border-color .15s ease;
}
.btn.primary {
  background: linear-gradient(145deg, var(--red-hot), var(--red-deep));
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(255, 30, 50, .28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.ghost:hover { border-color: rgba(255, 30, 50, .4); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: wait; }

.panel.login {
  margin: 28px auto 0; padding: 26px 24px; border-radius: 20px;
  background: var(--glass-strong); border: 1px solid var(--line);
  max-width: 420px; width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  animation: rise .45s var(--ease-out) both;
}
.panel.login[hidden] { display: none !important; }
.login-mark {
  width: 48px; height: 48px; border-radius: 14px; margin-bottom: 14px;
  display: grid; place-items: center;
  font-family: Syne, sans-serif; font-weight: 800; font-size: 15px;
  background: linear-gradient(145deg, var(--red-hot), var(--red-deep));
  box-shadow: 0 10px 28px rgba(255, 30, 50, .35);
}
.panel.login h1 { font-family: Syne, sans-serif; margin: 0 0 6px; font-size: 24px; letter-spacing: -.01em; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.45; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
input[type="text"], input[type="password"], #msgInput {
  width: 100%; padding: 12px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: rgba(0,0,0,.4); color: var(--text); font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus, input[type="password"]:focus, #msgInput:focus {
  outline: none;
  border-color: rgba(255, 30, 50, .45);
  box-shadow: 0 0 0 3px rgba(255, 30, 50, .12);
}
.login-go { width: 100%; margin-top: 16px; padding: 12px; }
.err { color: #f87171; font-size: 13px; margin-top: 10px; }

#mainView {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  animation: rise .5s var(--ease-out) both;
}
#mainView[hidden] { display: none !important; }

.glass-strip, .status-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.empty-hint {
  display: inline-flex; align-self: flex-start; align-items: center;
  margin: 0 0 10px; padding: 7px 13px; border-radius: 999px;
  font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  animation: rise .3s ease both;
}
.empty-hint[hidden] { display: none !important; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, .15);
}
.dot.up { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 211, 153, .15); }
.dot.down { background: #f87171; box-shadow: 0 0 0 3px rgba(248, 113, 113, .15); }

.chat {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  padding: 6px 2px 14px; min-height: 240px; max-height: calc(100vh - 280px);
  scroll-behavior: smooth;
}
.bubble {
  max-width: 88%; padding: 13px 15px; border-radius: 16px; line-height: 1.48;
  font-size: 14.5px; white-space: pre-wrap; word-break: break-word;
  animation: msg-in .38s var(--ease-out) both;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(145deg, rgba(255, 30, 50, .92), rgba(140, 12, 28, .95));
  border-bottom-right-radius: 5px;
}
.bubble.bot {
  align-self: flex-start;
  background: var(--glass);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  backdrop-filter: blur(10px);
}
.bubble.bot.err { border-color: rgba(248,113,113,.4); color: #fecaca; }
.bubble.bot.loading {
  color: var(--muted);
  font-style: italic;
  border-style: dashed;
  box-shadow: none;
}
.bubble img { display: block; max-width: 100%; border-radius: 12px; margin-top: 10px; }
.meta { display: block; margin-top: 7px; font-size: 11px; color: var(--muted); letter-spacing: .01em; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 2px 0 12px; }
.chips button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.035);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.chips button:hover {
  border-color: rgba(255, 30, 50, .5);
  background: rgba(255, 30, 50, .08);
  transform: translateY(-1px);
}

.composer {
  display: flex; gap: 7px; align-items: center;
  padding: 9px 10px; border-radius: 18px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0,0,0,.25);
  backdrop-filter: blur(14px);
}
.composer:focus-within {
  border-color: rgba(255, 30, 50, .4);
  box-shadow: 0 12px 32px rgba(0,0,0,.25), 0 0 0 3px rgba(255, 30, 50, .1);
}
.composer input { flex: 1; border: 0; background: transparent; padding: 9px 6px; box-shadow: none; }
.composer input:focus { outline: none; box-shadow: none; border: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); cursor: pointer; font-size: 16px;
  transition: border-color .15s ease, background .15s ease;
}
.icon-btn:hover { border-color: rgba(255, 30, 50, .35); }
.icon-btn.active { border-color: rgba(255, 30, 50, .7); background: rgba(255, 30, 50, .18); }
.menu-btn { display: none; }
.send { padding: 10px 16px; border-radius: 12px; }
.foot-hint { margin: 10px 2px 0; font-size: 11px; color: var(--muted); text-align: center; }
.backdrop { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-105%); transition: transform .28s var(--ease-out);
    box-shadow: 12px 0 40px rgba(0,0,0,.4);
  }
  .shell.side-open .sidebar { transform: none; }
  .menu-btn { display: grid; place-items: center; }
  .backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.58);
    z-index: 15; backdrop-filter: blur(2px);
  }
  .backdrop[hidden] { display: none !important; }
  .quota-pill { display: none; }
  .chat { max-height: calc(100vh - 310px); }
  .top { padding: 8px 10px; }
}
