:root {
  --bg: #0b0d12;
  --bg-2: #12151c;
  --panel: #181c26;
  --panel-2: #1f2430;
  --border: #2a3040;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #6c8cff;
  --accent-2: #8aa4ff;
  --green: #4ade80;
  --red: #f87171;
  --user-bg: #2a3350;
  --assistant-bg: #1a1f2b;
  --radius: 12px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.app { display: flex; height: 100vh; }
.sidebar {
  width: 280px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.sidebar .newchat {
  background: var(--accent); color: #fff; border: none; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; font-weight: 600; font-size: 14px;
}
.sidebar .newchat:hover { background: var(--accent-2); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  color: var(--muted); display: flex; justify-content: space-between; align-items: center;
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--panel); color: var(--text); }
.conv-item.active { background: var(--panel); color: var(--text); border-color: var(--border); }
.conv-item .del { opacity: 0; color: var(--muted); font-size: 16px; padding: 0 4px; }
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--red); }
.sidebar-footer { font-size: 12px; color: var(--muted); padding-top: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.sidebar-footer button { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.sidebar-footer button:hover { color: var(--text); border-color: var(--accent); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 52px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  padding: 0 16px; gap: 12px; background: var(--bg-2);
}
.topbar .title { font-weight: 600; font-size: 15px; flex: 1; }
.topbar select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px; font-size: 13px;
}
.chat-area { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; padding: 12px 14px; border-radius: var(--radius); line-height: 1.55; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user-bg); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--assistant-bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .codeblock { position: relative; margin: 8px 0; }
.msg pre {
  background: #0a0d14; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 13px; margin: 0;
}
.msg code { font-family: var(--mono); font-size: 13px; background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 4px; }
.msg pre code { background: none; padding: 0; }
.copy-btn {
  position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 3px 8px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer;
}
.copy-btn:hover { color: var(--text); }
.typing { color: var(--muted); font-style: italic; }
.empty-state { text-align: center; color: var(--muted); margin-top: 80px; }
.empty-state h2 { color: var(--text); }
.composer {
  border-top: 1px solid var(--border); padding: 12px 16px; background: var(--bg-2);
  display: flex; gap: 10px; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-family: var(--font); font-size: 14px; min-height: 42px; max-height: 160px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button {
  background: var(--accent); color: #fff; border: none; padding: 10px 16px;
  border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; height: 42px;
}
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }
/* auth */
.auth-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; width: 360px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.auth-card input {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 8px; font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button {
  background: var(--accent); color: #fff; border: none; padding: 11px; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.auth-card .toggle { color: var(--accent-2); cursor: pointer; font-size: 13px; text-align: center; }
.auth-card .err { color: var(--red); font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tabs button { flex: 1; background: var(--bg); color: var(--muted); border: 1px solid var(--border); padding: 8px; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
/* admin */
.admin-panel { padding: 20px; overflow-y: auto; }
.admin-panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-panel th, .admin-panel td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.admin-panel th { color: var(--muted); }
.admin-panel .danger { color: var(--red); cursor: pointer; }
.hidden { display: none !important; }
@media (max-width: 720px) {
  .sidebar { width: 220px; }
}

/* Playground */
.pg-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.pg-title { font-weight: 600; font-size: 14px; }
.pg-actions { display: flex; gap: 6px; }
.pg-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.pg-btn:hover { border-color: var(--accent); color: var(--accent-2); }
.pg-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.pg-btn.danger { color: var(--red); }
.pg-main { flex: 1; display: flex; min-height: 0; }
#pg-editor {
  flex: 1; background: #0a0d14; color: #d6e2ff; border: none; border-right: 1px solid var(--border);
  padding: 14px; font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: none;
  outline: none; white-space: pre; overflow: auto;
}
.pg-output { flex: 1; background: #fff; }
#pg-frame, #preview-frame { width: 100%; height: 100%; border: none; display: block; }
.pg-output { position: relative; }
.pg-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #666; font-size: 14px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-inner {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 1000px; height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
#preview-frame { flex: 1; background: #fff; }
