:root {
  --bg: #0b0b14;
  --panel: rgba(20, 20, 34, 0.78);
  --panel-2: rgba(31, 31, 52, 0.7);
  --border: rgba(148, 163, 255, 0.16);
  --text: #e9e9f4;
  --muted: #a3a3bd;
  --accent: #818cf8;
  --accent-2: #c084fc;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --user: linear-gradient(135deg, #4f46e5, #7c3aed);
  --assistant: rgba(38, 38, 60, 0.92);
  --radius: 18px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(99, 102, 241, 0.28), transparent 60%),
    radial-gradient(900px 600px at 92% 0%, rgba(192, 132, 252, 0.18), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(700px 400px at 50% 110%, rgba(56, 189, 248, 0.08), transparent 70%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 30px) 18px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 26px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.24), rgba(192, 132, 252, 0.16));
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.brand h1 {
  margin: 0;
  font-size: clamp(20px, 2.4vw, 27px);
  letter-spacing: -0.02em;
}

.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.ghlink {
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  transition: border-color 0.2s, transform 0.2s;
  white-space: nowrap;
}

.ghlink:hover { border-color: rgba(148, 163, 255, 0.45); transform: translateY(-1px); }

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow-y: auto;
  max-height: calc(100vh - 190px);
}

.sidebar h2 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.sidebar h2:not(:first-child) { margin-top: 22px; }

.model-list { display: flex; flex-direction: column; gap: 10px; }

.model-card {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(24, 24, 40, 0.65);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
  font: inherit;
}

.model-card:hover { border-color: rgba(148, 163, 255, 0.4); transform: translateY(-1px); }

.model-card.active {
  border-color: rgba(129, 140, 248, 0.75);
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.24), rgba(124, 58, 237, 0.14));
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.25) inset;
}

.model-card .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.model-card .name { font-weight: 700; font-size: 14px; }
.model-card .meta { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.14);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.3);
  white-space: nowrap;
}

.model-card.alt .pill {
  background: rgba(251, 191, 36, 0.12);
  color: #fcd34d;
  border-color: rgba(251, 191, 36, 0.28);
}

.hint {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.repo-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12.5px;
}

.repo-links a { color: #c7d2fe; text-decoration: none; }
.repo-links a:hover { text-decoration: underline; }

.runtime {
  margin-top: 20px;
  padding: 12px 13px;
  border-radius: 12px;
  background: rgba(10, 10, 20, 0.55);
  border: 1px dashed rgba(148, 163, 255, 0.22);
  font-size: 12px;
  color: var(--muted);
}

.runtime-title {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  margin-bottom: 5px;
  color: #8b8ba7;
}

.chat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(12, 12, 24, 0.5);
}

.statusbar .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.7);
  flex: none;
}

.statusbar[data-state="loading"] .dot { background: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, 0.7); animation: pulse 1s infinite; }
.statusbar[data-state="gen"] .dot { background: var(--accent); box-shadow: 0 0 10px rgba(129, 140, 248, 0.8); animation: pulse 0.8s infinite; }
.statusbar[data-state="error"] .dot { background: var(--err); box-shadow: 0 0 10px rgba(248, 113, 113, 0.8); }

@keyframes pulse { 50% { opacity: 0.35; } }

.progress {
  flex: 1;
  height: 5px;
  max-width: 320px;
  margin-left: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px clamp(14px, 2.2vw, 26px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; max-width: min(86%, 820px); }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.msg.user .avatar { background: linear-gradient(135deg, #4f46e5, #7c3aed); border-color: transparent; }

.bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
}

.msg.user .bubble {
  background: var(--user);
  border-color: transparent;
  border-top-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--assistant);
  border-top-left-radius: 4px;
}

.bubble .typing { color: var(--muted); }

.bubble.error { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 16px 8px;
  border-top: 1px solid var(--border);
  background: rgba(10, 10, 20, 0.42);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(15, 15, 28, 0.8);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.18s;
}

.composer textarea:focus { border-color: rgba(129, 140, 248, 0.6); }
.composer textarea::placeholder { color: #7b7b95; }

.composer-side { display: flex; gap: 8px; }

.send, .stop, .clear {
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.send {
  color: white;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}

.send:hover:not(:disabled) { transform: translateY(-1px); }
.send:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.stop {
  color: #fecaca;
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.4);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 18px 14px;
  background: rgba(10, 10, 20, 0.42);
  font-size: 12px;
  color: var(--muted);
}

.range-label { display: flex; align-items: center; gap: 9px; }

input[type="range"] {
  accent-color: #818cf8;
  width: 130px;
}

output { min-width: 30px; color: #c7d2fe; font-variant-numeric: tabular-nums; }

.clear {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border-color: var(--border);
}

.clear:hover { color: var(--text); border-color: rgba(148, 163, 255, 0.4); }

footer {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  color: #7b7b95;
  font-size: 12px;
}

footer a { color: #a5b4fc; text-decoration: none; }
footer a:hover { text-decoration: underline; }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: none; order: 2; }
  .chat { order: 1; min-height: 70vh; }
  .sidebar h2:not(:first-child) { margin-top: 16px; }
  .msg { max-width: 94%; }
  .ghlink { display: none; }
}

@media (max-width: 520px) {
  .composer { flex-wrap: wrap; }
  .composer-side { width: 100%; justify-content: flex-end; }
  .controls { flex-wrap: wrap; }
  .logo { width: 44px; height: 44px; font-size: 22px; }
}
