:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1f232c; --line: #2a2f3a;
  --text: #e8eaef; --muted: #9098a8; --accent: #7c5cff; --accent-2: #a28bff;
  --ok: #3ecf8e; --err: #ff6b6b; --warn: #f5b041; --radius: 12px;
  font-family: "Segoe UI", "Heebo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, textarea, input { font: inherit; color: inherit; }
code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; font-size: 13px; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.6; }
[hidden] { display: none !important; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login input { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.err { color: var(--err); min-height: 1.2em; font-size: 14px; }

.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.side { background: var(--panel); border-inline-end: 1px solid var(--line); padding: 18px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.brand { font-weight: 700; font-size: 20px; }
.pc { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.led { width: 9px; height: 9px; border-radius: 50%; background: var(--err); flex: none; }
.pc.on .led { background: var(--ok); }
.side-title { color: var(--muted); font-size: 13px; margin-top: 8px; }
.projects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.projects li { padding: 10px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.projects li:hover { background: var(--panel-2); }
.projects li.active { background: var(--panel-2); outline: 1px solid var(--accent); }
.projects li small { display: block; color: var(--muted); font-size: 12px; }

.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 16px; cursor: pointer; text-align: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }

.stage { overflow: hidden; display: flex; }
.empty { margin: auto; max-width: 580px; text-align: center; padding: 24px; }
.empty h1 { font-size: 26px; }
.empty p { color: var(--muted); line-height: 1.7; }
.drop { margin-top: 24px; border: 2px dashed var(--line); border-radius: var(--radius); padding: 48px 16px; color: var(--muted); }
.stage.over .drop { border-color: var(--accent); color: var(--text); }

.editor { display: grid; grid-template-columns: 1fr 420px; width: 100%; height: 100%; }
.player-wrap { padding: 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow: auto; }
.head { display: flex; align-items: center; gap: 12px; }
.head h2 { margin: 0; font-size: 20px; flex: 1; cursor: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
video, #image { width: 100%; height: 55vh; flex: none; background: #000; border-radius: var(--radius); object-fit: contain; }
.versions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.versions button { font-size: 13px; padding: 6px 12px; }
.versions button.active { border-color: var(--accent); background: #2a2350; }
.versions a { color: var(--accent-2); font-size: 13px; margin-inline-start: auto; }
.files { border-top: 1px solid var(--line); padding-top: 10px; }
.files-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 6px 0; }
.files ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.files li { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.files li:hover { background: var(--panel-2); }
.files li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.files li small { color: var(--muted); }
.files li a, .files li button { color: var(--muted); font-size: 12px; background: none; border: 0; cursor: pointer; padding: 0 4px; }
.files li a:hover, .files li button:hover { color: var(--text); }

.chat { border-inline-start: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 14px; border-radius: 12px; line-height: 1.6; white-space: pre-wrap; max-width: 92%; overflow-wrap: anywhere; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-start; }
.msg.assistant { background: var(--panel-2); align-self: flex-end; }
.msg.tool, .msg.stage { color: var(--muted); font-size: 13px; padding: 2px 6px; align-self: flex-end; }
.msg.error { background: #3a1d22; color: var(--err); align-self: flex-end; }
.msg.warn { background: #3a2f1d; color: var(--warn); align-self: center; font-size: 14px; }
.status { display: flex; align-items: center; gap: 8px; padding: 8px 16px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.status .btn { margin-inline-start: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .2; } }
.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { resize: vertical; min-height: 70px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer-actions { display: flex; gap: 8px; justify-content: space-between; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; justify-content: flex-start; z-index: 5; }
.drawer-card { background: var(--panel); width: min(480px, 100%); height: 100%; overflow: auto; padding: 18px; border-inline-end: 1px solid var(--line); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; font-size: 18px; }
.p-section { color: var(--accent-2); font-size: 13px; margin: 18px 0 6px; font-weight: 600; }
.p-item { display: block; width: 100%; text-align: start; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer; }
.p-item:hover { border-color: var(--accent); }
.p-item b { display: block; margin-bottom: 4px; }
.p-item span { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 9; }
.overlay .card { background: var(--panel); padding: 24px 32px; border-radius: var(--radius); max-width: 90vw; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .side { border: 0; border-bottom: 1px solid var(--line); max-height: 240px; }
  .editor { grid-template-columns: 1fr; height: auto; }
  .player-wrap { padding: 12px; overflow: visible; }
  video, #image { height: auto; max-height: 50vh; }
  .chat { border: 0; min-height: 60vh; }
}
