:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #161514; --muted: #6f6b66; --line: #e4e1dc;
  --accent: #d40f30; --accent-ink: #fff; --user: #161514; --user-ink: #fff; --code: #f0eeea; --ok: #1f7a4d;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121212; --panel: #1b1b1b; --ink: #ecebe8; --muted: #9a958f; --line: #2b2a28;
    --accent: #ff4d67; --accent-ink: #120; --user: #ecebe8; --user-ink: #121212; --code: #262523; --ok: #4cc28a; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
button { background: var(--ink); color: var(--bg); border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: var(--accent); color: #fff; }
button.small { padding: 4px 10px; font-size: 13px; }
input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; }
input:focus, textarea:focus { border-color: var(--ink); }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--accent); min-height: 1.2em; }
[hidden] { display: none !important; }

.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); }

.app { display: grid; grid-template-columns: 250px 1fr 300px; height: 100%; }
.side, .files { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.files { border-right: 0; border-left: 1px solid var(--line); }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.new { display: flex; gap: 6px; padding: 10px; }
.new input { flex: 1; min-width: 0; }
#projects { overflow-y: auto; padding: 4px 8px 12px; }
.proj { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); padding: 8px 10px; border-radius: 8px; }
.proj:hover { background: var(--code); }
.proj.on { background: var(--ink); color: var(--bg); }
.proj small { display: block; opacity: .65; font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: 6px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.title { flex: 1; min-width: 0; font-weight: 600; display: flex; gap: 8px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--code); color: var(--muted); }
.pill.run { background: var(--ok); color: #fff; }
.gates { display: flex; gap: 4px; padding: 8px 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.gate { font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.gate.done { background: var(--code); color: var(--ink); }
.gate.cur { background: var(--accent); border-color: var(--accent); color: #fff; }

.chat { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; max-width: 440px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 18px; }
.msg { max-width: 820px; width: fit-content; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-ink); padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px 14px 14px 4px; }
.msg.assistant p { margin: .4em 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 16px; margin: .8em 0 .3em; }
.msg.assistant code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg.assistant pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg.assistant pre code { padding: 0; }
.msg.assistant table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.msg.assistant th { background: var(--code); }
.msg.assistant a { color: var(--accent); }
.msg.assistant a.media { cursor: pointer; }
.tool { font-size: 12.5px; color: var(--muted); padding: 1px 4px; font-family: ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 820px; }
.tool b { color: var(--ink); font-weight: 600; }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); }
.sys.bad { color: var(--accent); }
.inline-media { display: block; margin: 8px 0; max-width: min(360px, 100%); max-height: 480px; border-radius: 8px; background: #000; }
.thinking { color: var(--muted); font-size: 13px; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 200px; }
.clip { font-size: 20px; cursor: pointer; padding: 6px; user-select: none; }
.upload { display: flex; gap: 10px; align-items: center; padding: 0 16px 10px; background: var(--panel); font-size: 13px; color: var(--muted); }
.bar { flex: 1; height: 6px; background: var(--code); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.file-list { overflow-y: auto; padding: 10px; display: grid; gap: 10px; align-content: start; }
.file { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--bg); }
.file .thumb { aspect-ratio: 16/10; background: #000; display: grid; place-items: center; color: #fff; font-size: 26px; overflow: hidden; }
.file .thumb img, .file .thumb video { width: 100%; height: 100%; object-fit: contain; }
.file .meta { padding: 6px 8px; font-size: 12px; word-break: break-all; }
.file .meta small { color: var(--muted); display: block; }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: grid; place-items: center; z-index: 10; padding: 16px; }
.viewer-in { background: var(--panel); border-radius: 12px; padding: 12px; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: 8px; }
.viewer-in .close { align-self: flex-end; }
.viewer-body video, .viewer-body img { max-width: min(90vw, 1200px); max-height: 78vh; display: block; border-radius: 8px; background: #000; }
.viewer-body audio { width: min(90vw, 500px); }
.viewer-body .row { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: 13px; margin-top: 8px; }

.only-mobile { display: none; }
@media (max-width: 1000px) {
  .app { grid-template-columns: 220px 1fr; }
  .files { position: fixed; right: 0; top: 0; bottom: 0; width: min(320px, 90vw); z-index: 5; box-shadow: -8px 0 30px rgba(0,0,0,.2); transform: translateX(100%); transition: transform .2s; }
  .files.open { transform: none; }
  #filesBtn { display: inline-block; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 85vw); z-index: 5; box-shadow: 8px 0 30px rgba(0,0,0,.2); transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  #menu { display: inline-block; }
  .chat { padding: 14px 12px; }
  .composer { padding: 10px 12px; }
}
