:root {
  --bg-0: #090b10;
  --bg-1: #0f141c;
  --panel: rgba(18, 24, 33, 0.72);
  --panel-strong: rgba(20, 28, 39, 0.92);
  --line: rgba(145, 167, 196, 0.2);
  --line-strong: rgba(120, 166, 232, 0.45);
  --text: #dfe8f3;
  --muted: #8f9eb1;
  --accent: #59f0ff;
  --accent-2: #89ff6c;
  --warn: #ff7b5d;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --blur: blur(16px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Space Grotesk", "Rajdhani", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 10% 10%, #0d1b2e 0%, transparent 55%),
              radial-gradient(900px 700px at 85% 85%, #11222c 0%, transparent 50%),
              linear-gradient(145deg, var(--bg-0), var(--bg-1));
  overflow: hidden;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background: radial-gradient(280px circle at var(--mx, 50%) var(--my, 50%), rgba(96, 234, 255, 0.2), transparent 72%);
  transition: background .18s linear;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; transition: transform .16s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease; }
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0) scale(.98); }
button:disabled { opacity: .65; cursor: wait; }
.hidden { display: none !important; }

.fx-grid,
.fx-noise,
.fx-blobs { position: fixed; inset: 0; pointer-events: none; z-index: -1; }
.fx-grid {
  background-image: linear-gradient(rgba(120, 180, 255, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(120, 180, 255, 0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at 50% 50%, black, transparent 75%);
  animation: driftGrid 16s linear infinite;
}
.fx-noise {
  opacity: .12;
  background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.11) 1px, transparent 1px);
  background-size: 3px 3px;
  mix-blend-mode: screen;
}
.fx-blobs span {
  position: absolute;
  border-radius: 999px;
  filter: blur(34px);
  opacity: .35;
}
.fx-blobs span:nth-child(1) { width: 300px; height: 300px; top: 8%; left: 8%; background: #14b7ff; animation: floatA 14s ease-in-out infinite; }
.fx-blobs span:nth-child(2) { width: 420px; height: 420px; right: 12%; top: 38%; background: #00ffa6; animation: floatB 18s ease-in-out infinite; }
.fx-blobs span:nth-child(3) { width: 260px; height: 260px; left: 45%; bottom: 7%; background: #9cff4f; animation: floatC 12s ease-in-out infinite; }

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -12px);
  background: rgba(10, 20, 30, 0.88);
  border: 1px solid var(--line-strong);
  color: #d5f8ff;
  border-radius: 999px;
  padding: 11px 18px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 123, 93, 0.9); color: #ffd9d0; }

.auth-view { min-height: 100vh; }
.auth-topbar, .chat-header, .side-top {
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.auth-topbar { height: 96px; display: flex; align-items: center; justify-content: space-between; padding: 0 38px; }
.brand, .side-brand { font-size: 31px; letter-spacing: -.08em; font-weight: 800; text-transform: uppercase; }
.auth-actions { display: flex; gap: 10px; }
.pill, .wide-btn, .danger-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 700;
  background: rgba(14, 20, 28, .75);
}
.pill, .wide-btn, .danger-btn, .list-item, .model-card, .nav-item, .user-chip, .create-btn { position: relative; overflow: hidden; }
.tap-ring {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: rgba(164, 249, 255, 0.55);
  transform: translate(-50%, -50%) scale(0);
  animation: tapRing .42s ease-out forwards;
  pointer-events: none;
}
.pill.light, .wide-btn { background: linear-gradient(135deg, #62f0ff, #91ff73); color: #0b1116; border-color: transparent; }
.pill.ghost, .wide-btn.secondary { background: rgba(16, 23, 33, 0.4); }
.danger-btn { width: 100%; margin-top: 12px; border-color: rgba(255,123,93,.5); color: #ffc5b7; background: rgba(83, 23, 13, 0.34); }

.hero-panel { min-height: calc(100vh - 96px); display: grid; grid-template-columns: minmax(340px, 500px) minmax(0, 1fr); align-items: center; gap: 32px; padding: 24px 40px 50px; }
.auth-card, .settings-modal, .create-modal, .composer, .model-card, .user-menu, .user-chip, .search-box, .create-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.auth-card { width: min(500px, 100%); border-radius: 24px; padding: 30px 22px; box-shadow: var(--shadow); animation: fadeUp .6s ease; }
.auth-card h1 { margin: 0; text-align: center; font-size: 42px; line-height: .95; }
.auth-card p { color: var(--muted); text-align: center; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 5px; background: rgba(3, 8, 14, 0.45); border-radius: 15px; margin: 20px 0; }
.tab { border: 0; border-radius: 12px; padding: 11px; background: transparent; color: var(--muted); font-weight: 700; }
.tab.active { background: rgba(95, 249, 255, 0.2); color: #cefbff; }
.auth-form, .stack-form { display: grid; gap: 10px; }
label { color: var(--muted); font-weight: 650; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(11, 17, 25, 0.58);
  padding: 12px 14px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(89,240,255,.14); }
textarea { resize: vertical; }
.tiny-note { color: var(--muted); font-size: 13px; }
.hero-copy h2 { font-size: clamp(48px, 7vw, 100px); line-height: .88; letter-spacing: -.06em; margin: 0; }
.hero-copy p { color: #b6c2d2; font-size: 18px; max-width: 620px; }

.app-view { height: 100vh; display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: rgba(5, 11, 18, 0.64); }
.side-top { height: 82px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--line); }
.icon-btn, .round-menu, .close-modal { border: 1px solid transparent; background: transparent; color: var(--muted); display: grid; place-items: center; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; }
.icon-btn:hover, .round-menu:hover { border-color: var(--line); color: var(--text); background: rgba(24, 34, 46, .5); }
.create-btn { margin: 12px; border-radius: 14px; min-height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 16px; font-weight: 700; }
.create-btn span { font-size: 26px; }
.side-nav { display: grid; gap: 4px; padding: 0 12px 10px; }
.nav-item { border: 1px solid transparent; background: transparent; color: var(--text); border-radius: 11px; text-align: left; padding: 12px 14px; font-weight: 700; }
.nav-item.active, .nav-item:hover { background: rgba(20, 31, 44, 0.7); border-color: var(--line); }
.search-box { margin: 0 12px 12px; border-radius: 11px; display: flex; align-items: center; gap: 8px; padding: 0 11px; }
.search-box input { border: 0; background: transparent; box-shadow: none; padding: 12px 0; }
.section-label { color: var(--muted); font-size: 13px; padding: 8px 20px; text-transform: uppercase; letter-spacing: .08em; }
.list { padding: 0 7px; display: grid; gap: 7px; overflow: auto; min-height: 52px; }
.chat-list { max-height: 34vh; }
.list-item {
  width: 100%; border: 1px solid transparent; background: rgba(14, 19, 27, 0.36); color: #fff; border-radius: 11px;
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px;
}
.list-item:hover, .list-item.active { border-color: var(--line); background: rgba(26, 36, 50, 0.72); box-shadow: inset 0 0 0 1px rgba(89,240,255,.08); }
.list-item span:last-child { min-width: 0; display: grid; }
.list-item strong, .list-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item small, .list-empty { color: var(--muted); }
.user-footer { margin-top: auto; padding: 12px; position: relative; }
.user-chip { width: 100%; border-radius: 12px; display: flex; align-items: center; gap: 10px; padding: 10px; text-align: left; border-color: var(--line); }
.user-chip > span:nth-child(2) { min-width: 0; display: grid; }
.chev { margin-left: auto; color: var(--muted); }
.user-menu { position: absolute; bottom: 76px; left: 12px; right: 12px; border-radius: 12px; padding: 7px; box-shadow: var(--shadow); z-index: 4; }
.user-menu button { width: 100%; border: 0; background: transparent; color: #fff; text-align: left; border-radius: 8px; padding: 11px; }
.user-menu button:hover { background: rgba(29, 41, 56, 0.7); }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden; flex: 0 0 auto; display: grid; place-items: center;
  background: linear-gradient(135deg, #00d2ff, #73ff95); color: #04121b; font-weight: 800; border: 1px solid rgba(255,255,255,.2);
}
.avatar.small { width: 40px; height: 40px; font-size: 14px; }
.avatar.big { width: 92px; height: 92px; font-size: 32px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-empty { background: linear-gradient(135deg, #49ccff, #95ff67); }

.chat-shell { min-width: 0; position: relative; display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  min-height: 80px; display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(8, 14, 22, 0.66); z-index: 2;
}
.chat-header h2 { margin: 0; }
.chat-header p { margin: 2px 0 0; color: var(--muted); }
.backend-badge {
  margin-left: auto;
  margin-right: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  color: #b8c7d9;
  background: rgba(9, 16, 24, 0.72);
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backend-badge.online { border-color: rgba(110, 255, 149, 0.52); color: #b9ffc8; }
.backend-badge.offline { border-color: rgba(255, 127, 108, 0.62); color: #ffc9bc; }
.backend-badge.checking { border-color: rgba(125, 188, 255, 0.52); color: #c0e6ff; }
.round-menu { border: 1px solid var(--line); border-radius: 50%; width: 50px; height: 50px; }
.empty-state { margin: auto; text-align: center; max-width: 660px; padding: 24px; animation: fadeUp .6s ease; }
.orb {
  width: 92px; height: 92px; margin: 0 auto 14px; border-radius: 24px; display: grid; place-items: center; font-size: 52px; font-weight: 800;
  background: linear-gradient(135deg, #4bd9ff, #b2ff66);
  box-shadow: 0 0 0 1px rgba(255,255,255,.2), 0 18px 52px rgba(74, 214, 255, .35);
  animation: pulseOrb 3s ease-in-out infinite;
}
.empty-state h1 { font-size: clamp(42px, 6vw, 72px); letter-spacing: -.05em; margin: 0; }
.empty-state p { color: var(--muted); }
.quick-actions button { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; background: linear-gradient(135deg, #63efff, #95ff71); color: #071017; }

.messages { flex: 1; overflow: auto; padding: 28px 20px 130px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.message { width: min(900px, 100%); display: flex; gap: 10px; align-items: flex-start; opacity: 0; transform: translateY(8px) scale(.995); animation: msgIn .28s ease forwards; }
.message.user { justify-content: flex-end; }
.bubble {
  background: rgba(14, 22, 31, 0.88); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  line-height: 1.52; white-space: pre-wrap; max-width: min(740px, 86%); box-shadow: 0 10px 24px rgba(0,0,0,.25);
}
.message.user .bubble { background: linear-gradient(135deg, #62f0ff, #93ff76); border-color: transparent; color: #071017; }
.message.pending .bubble { opacity: .84; }
.bubble img { max-width: min(420px, 100%); border-radius: 11px; display: block; margin-bottom: 8px; }
.typing { color: var(--muted); font-style: italic; }
.composer {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: min(900px, calc(100% - 36px)); border-radius: 16px;
  display: flex; align-items: end; gap: 8px; padding: 9px; box-shadow: var(--shadow);
}
.file-btn, #sendBtn { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); background: rgba(11,19,27,.7); }
#sendBtn { background: linear-gradient(135deg, #57edff, #a3ff68); color: #09121b; border-color: transparent; }
#messageInput { min-height: 42px; max-height: 160px; border: 0; background: transparent; padding: 10px 2px; box-shadow: none; resize: none; }
.image-preview { width: 52px; height: 42px; border-radius: 10px; overflow: hidden; flex: 0 0 auto; border: 1px solid var(--line); background-size: cover; background-position: center; }

.info-panel { width: 360px; border-left: 1px solid var(--line); padding: 32px 24px; position: relative; overflow: auto; background: rgba(8, 14, 21, 0.72); }
.close-info { position: absolute; right: 14px; top: 14px; }
.info-panel p { color: var(--muted); white-space: pre-wrap; }
.info-block { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.model-list { display: grid; gap: 9px; margin: 12px 0 16px; }
.model-card { border-radius: 12px; padding: 12px; display: grid; gap: 4px; text-align: left; }
.model-card small, .model-card span { color: var(--muted); }
.model-card.active { border-color: var(--line-strong); box-shadow: inset 0 0 0 1px rgba(89,240,255,.25); }
.info-stat { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 0; margin: 16px 0; }
.info-stat span { color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 8, 14, 0.6); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(8px); }
.settings-modal { width: min(920px, 94vw); height: min(780px, 92vh); border-radius: 20px; display: grid; grid-template-columns: 245px 1fr; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.close-modal { position: absolute; top: 10px; right: 12px; color: #fff; font-size: 22px; z-index: 2; }
.settings-tabs { border-right: 1px solid var(--line); padding: 20px 16px; display: grid; align-content: start; gap: 8px; }
.settings-tabs button { border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 11px; padding: 13px; text-align: left; font-weight: 700; }
.settings-tabs button.active { color: #d5f9ff; background: rgba(24, 36, 50, 0.72); border-color: var(--line); }
.settings-content { padding: 34px 26px; overflow: auto; }
.settings-pane { display: none; }
.settings-pane.active { display: block; }
.settings-pane h1, .create-modal h1 { margin: 0 0 20px; }
.stack-form.compact { margin-top: 16px; max-width: 420px; }
.account-card, .status-card, .chip, .inline-form { border: 1px solid var(--line); background: rgba(12, 18, 27, 0.7); border-radius: 12px; }
.account-card, .status-card { padding: 14px; display: grid; gap: 6px; color: var(--muted); }
.account-card strong, .status-card strong { color: var(--text); }
.status-card input { margin-top: 4px; }
.prefs-form { display: grid; gap: 18px; }
.prefs-form label { display: grid; gap: 8px; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.button-row button { border: 1px solid var(--line); background: rgba(11, 18, 26, 0.8); min-width: 124px; padding: 10px 12px; border-radius: 10px; font-weight: 700; }
.button-row button.active { border-color: var(--line-strong); box-shadow: inset 0 0 0 1px rgba(89,240,255,.25); }
.inline-form { display: flex; gap: 8px; padding: 7px; margin: 16px 0; }
.inline-form input { border: 0; background: transparent; box-shadow: none; }
.inline-form button { border: 0; border-radius: 9px; padding: 0 14px; background: linear-gradient(135deg, #5cefff, #9dff69); color: #08121a; font-weight: 700; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; }
.chip button { background: transparent; color: var(--muted); border: 0; font-size: 16px; }
.status-card pre { white-space: pre-wrap; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #afbecf; margin: 0; }
.create-modal { width: min(700px, 94vw); max-height: 92vh; overflow: auto; border-radius: 18px; padding: 28px; position: relative; box-shadow: var(--shadow); }
.avatar-upload-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

body.dense-mode .messages { gap: 7px; }
body.dense-mode .bubble { padding: 9px 11px; border-radius: 10px; }
body.classic-mode .bubble { border-radius: 4px; }
.mobile-only { display: none; }

@keyframes driftGrid { 0% { transform: translate(0,0); } 100% { transform: translate(40px, 40px); } }
@keyframes pulseOrb { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.03); } }
@keyframes floatA { 0%,100% { transform: translate(0,0);} 50% { transform: translate(26px, -14px);} }
@keyframes floatB { 0%,100% { transform: translate(0,0);} 50% { transform: translate(-18px, 20px);} }
@keyframes floatC { 0%,100% { transform: translate(0,0);} 50% { transform: translate(10px, -20px);} }
@keyframes msgIn { to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tapRing {
  to {
    transform: translate(-50%, -50%) scale(12);
    opacity: 0;
  }
}

@media (max-width: 1080px) {
  .app-view { grid-template-columns: 300px minmax(0, 1fr); }
  .info-panel { position: fixed; inset: 0 0 0 auto; z-index: 25; max-width: 90vw; box-shadow: var(--shadow); }
  .info-panel.hidden { display: none !important; }
}

@media (max-width: 920px) {
  body { overflow: auto; }
  .auth-topbar { padding: 16px; height: auto; }
  .auth-actions, .hero-copy { display: none; }
  .hero-panel { padding: 22px 14px; display: block; }
  .app-view { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 304px; transform: translateX(-104%); transition: .2s ease; z-index: 20; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: grid; }
  .chat-header { padding: 10px 12px; }
  .settings-modal { grid-template-columns: 1fr; height: 94vh; }
  .settings-tabs { grid-auto-flow: column; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px; }
  .settings-content { padding: 22px 14px; }
  .composer { width: calc(100% - 20px); }
  .messages { padding-left: 10px; padding-right: 10px; }
}
