:root {
  --bg: #08080c;
  --bg-2: #0f0f16;
  --panel: #14141d;
  --panel-2: #1b1b27;
  --line: #262635;
  --text: #e9e7ef;
  --muted: #8d8a9c;
  --accent: #e0233f;
  --accent-2: #ff4d64;
  --accent-soft: rgba(224, 35, 63, 0.14);
  --ok: #2fd17d;
  --warn: #f5b942;
  --danger: #ff4d64;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  text-align: left;
}
.btn:hover { border-color: #3a3a4f; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: #3a121a; border-color: #5c1b28; color: #ffb3bf; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- brand ---------- */
.brand { font-weight: 700; letter-spacing: .2px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand b { color: var(--accent); }
.brand.big { font-size: 26px; justify-content: center; }
.sigil { color: var(--accent); filter: drop-shadow(0 0 8px rgba(224,35,63,.55)); }
.sigil.huge { font-size: 46px; line-height: 1; }

/* ---------- auth ---------- */
.auth {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(224,35,63,.18), transparent 60%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 26px; box-shadow: 0 30px 80px rgba(0,0,0,.5); text-align: center;
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-2); border-radius: 10px; padding: 4px; margin: 20px 0; }
.tab { border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--danger); min-height: 1.2em; font-size: 14px; margin: 4px 0 12px; }
#auth-submit { text-align: center; padding: 11px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; padding: 14px; min-height: 0;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 8px 4px 0; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.conv {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px;
  cursor: pointer; color: #cfccd9; font-size: 14px;
}
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; width: 26px; height: 26px; font-size: 13px; }
.conv:hover .del, .conv.active .del { opacity: 1; }
.side-bottom { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.bad .dot { background: var(--danger); }
.user-row { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-2);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: rgba(8,8,12,.85); backdrop-filter: blur(8px);
}
.chat-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-controls { display: flex; align-items: center; gap: 12px; }
.select-wrap select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; max-width: 220px;
}
.temp { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.temp input { width: 80px; accent-color: var(--accent); }
.temp output { width: 24px; color: var(--text); }

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; scroll-behavior: smooth; }
.welcome { max-width: 720px; margin: 6vh auto 0; text-align: center; }
.welcome h2 { font-size: 28px; margin: 10px 0 6px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 26px; text-align: left; }
.suggestion {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 14px; cursor: pointer;
  color: #cfccd9; font-size: 14px; text-align: left;
}
.suggestion:hover { border-color: var(--accent); color: #fff; }

.msg { max-width: 860px; margin: 0 auto 22px; display: flex; gap: 14px; }
.msg .who {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; margin-top: 2px;
}
.msg.user .who { background: var(--panel-2); color: var(--muted); }
.msg.assistant .who { background: var(--accent-soft); color: var(--accent-2); }
.msg .body { flex: 1; min-width: 0; }
.msg.user .body { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; }
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16.5px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }
.md table { border-collapse: collapse; margin: 0 0 12px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; }
.md blockquote { border-left: 3px solid var(--accent); margin: 0 0 12px; padding: 2px 14px; color: var(--muted); }
.codeblock { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 0 0 14px; background: #0d1117; }
.cb-head {
  display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 6px 14px;
  background: #161b22; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); font-family: var(--mono);
}
.cb-head .copy { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 3px 8px; border-radius: 6px; }
.cb-head .copy:hover { background: var(--panel-2); color: var(--text); }
.codeblock pre { margin: 0; padding: 14px; overflow-x: auto; }
.codeblock pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }

.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.thinking .spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.msg-error { color: #ffb3bf; background: #2a0f15; border: 1px solid #5c1b28; padding: 10px 12px; border-radius: 10px; margin-top: 10px; font-size: 14px; }

.project-card {
  margin-top: 12px; border: 1px solid #4a1622; background: linear-gradient(180deg, rgba(224,35,63,.10), rgba(224,35,63,.03));
  border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.project-card .pc-info { flex: 1; min-width: 160px; }
.project-card .pc-name { font-weight: 600; }
.project-card .pc-meta { font-size: 13px; color: var(--muted); }
.project-card .pc-actions { display: flex; gap: 8px; }

/* ---------- composer ---------- */
.composer-wrap { padding: 10px 16px 14px; }
.composer {
  max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px;
}
.composer:focus-within { border-color: #4a4a62; }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; padding: 6px 8px;
  max-height: 240px; line-height: 1.5;
}
.send { width: 44px; height: 44px; padding: 0; text-align: center; border-radius: 12px; font-size: 17px; flex: none; }
.hint { text-align: center; font-size: 12px; margin: 8px 0 0; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card {
  width: min(1200px, 100%); height: min(88vh, 900px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { flex: 1; overflow: auto; min-height: 0; }
.proj-list { padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.proj-item { border: 1px solid var(--line); background: var(--bg-2); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.proj-item .pn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-item .pm { font-size: 13px; color: var(--muted); }
.proj-item .pa { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.viewer { display: grid; grid-template-columns: 230px 1fr; height: 100%; }
.file-tree { border-right: 1px solid var(--line); overflow-y: auto; padding: 8px; background: var(--bg-2); }
.file-tree button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 10px;
  border-radius: 7px; font-family: var(--mono); font-size: 12.5px; color: #cfccd9; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-tree button:hover { background: var(--panel); }
.file-tree button.active { background: var(--panel-2); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.viewer-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.viewer-main iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.viewer-main pre { margin: 0; padding: 16px; overflow: auto; flex: 1; background: #0d1117; }
.viewer-main pre code { font-family: var(--mono); font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

.only-mobile { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 84%; max-width: 320px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 20px 0 60px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-block; }
  .temp { display: none; }
  .select-wrap select { max-width: 150px; }
  .suggestions { grid-template-columns: 1fr; }
  .msg { gap: 10px; }
  .msg .who { display: none; }
  .viewer { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .file-tree { max-height: 130px; border-right: 0; border-bottom: 1px solid var(--line); }
  .modal { padding: 0; }
  .modal-card { height: 100%; border-radius: 0; }
  .modal-head { flex-wrap: wrap; }
}

/* ---------- setup wizard ---------- */
.setup-body {
  min-height: 100%;
  background: radial-gradient(900px 500px at 50% -10%, rgba(224,35,63,.16), transparent 60%), var(--bg);
}
.setup { max-width: 760px; margin: 0 auto; padding: 36px 16px 60px; }
.center { text-align: center; }
.small { font-size: 13px; }
.steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0; margin: 26px 0 18px; counter-reset: s; }
.steps li {
  counter-increment: s; text-align: center; font-size: 13px; color: var(--muted); padding: 8px 4px;
  border-bottom: 2px solid var(--line);
}
.steps li::before { content: counter(s) " · "; }
.steps li.current { color: var(--text); border-color: var(--accent); }
.steps li.done { color: var(--ok); border-color: var(--ok); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.card h2 { margin: 0 0 8px; font-size: 19px; }
.card p { color: #cfccd9; }
.card code { font-family: var(--mono); background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; margin: 4px 0 10px; color: #cfccd9; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.ok-text { color: var(--ok) !important; }
.sysinfo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.si { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; font-size: 13px; }
.si b { font-size: 17px; }
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.model-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.model-card p { margin: 4px 0 8px; flex: 1; }
.model-card.rec { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.model-card.dim { opacity: .55; }
.model-card .btn { align-self: flex-start; }
.mc-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.badge { font-size: 11px; background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.dl { margin-top: 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.dl-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }
.adv { margin-top: 16px; color: var(--muted); font-size: 14px; }
.adv summary { cursor: pointer; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); }
.row-end { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- admin panel ---------- */
.admin { padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.admin h3 { margin: 0 0 10px; font-size: 15px; }
.admin-section { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.inst-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.inst-row:last-child { border-bottom: 0; }
.inst-row .nm { flex: 1; min-width: 160px; }
.default-tag { font-size: 11px; color: var(--ok); border: 1px solid var(--ok); border-radius: 99px; padding: 1px 8px; margin-left: 6px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.engine-note { font-size: 13px; color: var(--muted); }

@media (max-width: 600px) {
  .grid2, .sysinfo, .stats { grid-template-columns: 1fr 1fr; }
  .steps li { font-size: 11.5px; }
}
.check select, .admin select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
}

.err-stack { white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 11.5px; margin: 8px 0; max-height: 220px; overflow: auto; color: #ffd0d8; }
