:root {
  --bg: #0d1017;
  --panel: #131722;
  --panel-2: #1a1f2d;
  --line: #242a3a;
  --text: #e8ebf3;
  --muted: #8a93a8;
  --accent: #6d8cff;
  --accent-2: #a46dff;
  --ok: #3ccf91;
  --warn: #ffb547;
  --danger: #ff6b6b;
  --radius: 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- кнопки ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #3a4256; background: #20263a; }
.btn--primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; font-weight: 600; }
.btn--primary:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn--danger { background: transparent; border-color: rgba(255,107,107,.5); color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 5px 8px;
  cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); }

/* ---------- шапка ---------- */
.top {
  height: 56px; display: flex; align-items: center; gap: 14px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: -.01em; font-size: 16px; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand--big { font-size: 22px; justify-content: center; margin-bottom: 8px; }
.project-pick { display: flex; align-items: center; gap: 4px; }
.project-pick select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
  min-width: 170px; max-width: 240px;
}
.top__actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.usage {
  font-variant-numeric: tabular-nums; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px; font-size: 12px;
}
.usage.warn { color: var(--warn); border-color: var(--warn); }

/* ---------- раскладка ---------- */
.layout { display: grid; grid-template-columns: 230px 400px 1fr; height: calc(100% - 56px); }
.panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); min-height: 46px; color: var(--muted); font-weight: 600;
}
.panel__head > div { display: flex; align-items: center; gap: 2px; }

/* ---------- файлы ---------- */
.tree { overflow: auto; padding: 6px 0; flex: 1; }
.tree__row {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap;
  border-left: 2px solid transparent;
}
.tree__row:hover { background: var(--panel-2); }
.tree__row.active { background: #1d2333; border-left-color: var(--accent); }
.tree__name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree__row.dir .tree__name { color: var(--muted); font-weight: 600; }
.tree__acts { display: none; gap: 2px; }
.tree__row:hover .tree__acts { display: flex; }
.tree__acts button { background: none; border: 0; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.tree__acts button:hover { background: #2a3146; }

/* ---------- чат ---------- */
.messages { flex: 1; overflow: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; line-height: 1.5; word-wrap: break-word; }
.msg--user { align-self: flex-end; background: #26305a; border-bottom-right-radius: 4px; }
.msg--ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg--error { align-self: flex-start; background: rgba(255,107,107,.1); border: 1px solid rgba(255,107,107,.4); color: #ffc2c2; }
.msg__meta { margin-top: 6px; font-size: 11px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.tag { padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); }
.tag--local { color: var(--ok); border-color: rgba(60,207,145,.4); }
.msg--thinking { color: var(--muted); }
.msg--thinking::after { content: "…"; animation: dots 1.2s steps(4) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1.2em } }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 300px; line-height: 1.6; }
.empty b { color: var(--text); display: block; font-size: 16px; margin-bottom: 6px; }
.examples { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.examples button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: left; }
.examples button:hover { border-color: var(--accent); }

.attachments { display: flex; gap: 6px; padding: 0 12px; flex-wrap: wrap; }
.attachments:empty { display: none; }
.att { position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); margin-top: 8px; }
.att img { width: 100%; height: 100%; object-fit: cover; }
.att button { position: absolute; top: 1px; right: 1px; background: rgba(0,0,0,.7); border: 0; color: #fff; border-radius: 6px; cursor: pointer; font-size: 11px; }

.composer { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.composer textarea {
  width: 100%; resize: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; outline: none; line-height: 1.5; max-height: 220px;
}
.composer textarea:focus { border-color: var(--accent); }
.composer__bar { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.composer__bar .btn--primary { margin-left: auto; }
.hint { color: var(--muted); font-size: 11px; }
.mic.on { background: var(--danger); border-color: var(--danger); animation: pulse 1.3s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,.6) } 50% { box-shadow: 0 0 0 7px rgba(255,107,107,0) } }
.pro { display: flex; align-items: center; gap: 4px; color: var(--warn); font-size: 12px; cursor: pointer; }

/* ---------- просмотр / код ---------- */
.view { border-right: 0; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg__btn { background: none; border: 0; padding: 5px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg__btn.active { background: #2a3146; color: var(--text); }
.preview-wrap { flex: 1; display: flex; justify-content: center; background: #0a0c11; overflow: auto; padding: 0; }
.preview-wrap.phone { padding: 16px 0; }
#preview { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-wrap.phone #preview {
  width: 390px; height: min(844px, 100%); border-radius: 26px; border: 8px solid #222838; flex: none;
}
.code-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--line); color: var(--muted); }
#code {
  flex: 1; background: #0a0c11; border: 0; outline: none; padding: 14px; resize: none; tab-size: 2;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.55; color: #d7dcea;
}
.code-image { flex: 1; display: grid; place-items: center; background: #0a0c11; overflow: auto; padding: 20px; }
.code-image img { max-width: 100%; max-height: 100%; }

/* ---------- модальное окно ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,7,12,.7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal__box {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: min(640px, 100%); max-height: 86vh; overflow: auto; padding: 22px;
}
.modal__close { position: absolute; top: 12px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field input[type=text] { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
.field input[type=text]:focus { border-color: var(--accent); }
.field small { color: var(--muted); }
.types { display: grid; gap: 8px; }
.type-opt { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.type-opt:has(input:checked) { border-color: var(--accent); background: rgba(109,140,255,.08); }
.type-opt small { display: block; color: var(--muted); margin-top: 2px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.hist { display: flex; flex-direction: column; gap: 6px; }
.hist__item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; }
.hist__msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist__time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.diff { background: #0a0c11; border-radius: 10px; padding: 12px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre; overflow: auto; max-height: 60vh; }
.diff .add { color: #6fe3a8; } .diff .del { color: #ff8f8f; } .diff .hunk { color: #8fa8ff; }
.langs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.langs label { display: flex; gap: 6px; align-items: center; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.langs label:has(input:checked) { border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
.url-box { display: flex; gap: 8px; }
.url-box input { flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
pre.logs { background: #0a0c11; padding: 12px; border-radius: 10px; font-size: 12px; white-space: pre-wrap; max-height: 60vh; overflow: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #20263a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  transition: .25s; pointer-events: none; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- вход ---------- */
.login-page { display: grid; place-items: center; }
.login { display: flex; flex-direction: column; gap: 12px; width: min(340px, 90vw); }
.login input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; }
.login .btn { padding: 12px; }
.login__err { color: var(--danger); text-align: center; min-height: 20px; }

/* ---------- телефон ---------- */
.mobile-tabs { display: none; }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 340px 1fr; }
  .top .lbl { display: none; }
}
@media (max-width: 820px) {
  .top { gap: 8px; padding: 0 8px; }
  .brand__name, .hint, .python-only, .usage, #btn-del-project { display: none; }
  .toast { bottom: 72px; }
  .project-pick select { min-width: 0; width: 120px; }
  .top__actions { gap: 2px; }
  .top__actions .btn { padding: 6px 8px; }
  .layout { grid-template-columns: 1fr; height: calc(100% - 56px - 56px); }
  .layout > .panel { display: none; border-right: 0; }
  .layout[data-tab="files"] #panel-files,
  .layout[data-tab="chat"] #panel-chat,
  .layout[data-tab="view"] #panel-view { display: flex; }
  .tree__acts { display: flex; }
  .mobile-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 56px; background: var(--panel);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-tabs button { flex: 1; background: none; border: 0; color: var(--muted); cursor: pointer; }
  .mobile-tabs button.active { color: var(--text); font-weight: 600; }
  .preview-wrap.phone #preview { width: 100%; border: 0; border-radius: 0; height: 100%; }
}
