:root {
  --bg: #f6f6f9; --panel: #ffffff; --line: #e4e4ec; --text: #17171c; --muted: #6b6b7a;
  --accent: #7c5cff; --accent-2: #9d84ff; --user: #efeaff; --err: #d23c3c; --ok: #1fa971; --warn: #e3a008;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111116; --panel: #1a1a21; --line: #2b2b36; --text: #ececf2; --muted: #9a9aab;
    --user: #2a2445; --accent-2: #b3a0ff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--err); min-height: 1.2em; font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; }
.btn.tiny { padding: 3px 9px; font-size: 12.5px; border-radius: 8px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #ff7ab6); }

/* login */
.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; display: grid; gap: 12px; text-align: center; }
.login-card input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }

/* header */
.top { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tab { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 9px; border: 1px solid transparent;
  cursor: pointer; white-space: nowrap; color: var(--muted); max-width: 200px; }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab.active { background: var(--user); color: var(--text); border-color: var(--line); }
.tab .x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 2px; font-size: 14px; }
.tab .spin { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.gpu { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.gpu .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.gpu.ready .dot { background: var(--ok); }
.gpu.starting .dot { background: var(--warn); animation: pulse 1s infinite; }
.mem-toggle { display: none; }
@keyframes pulse { 50% { opacity: .3; } }

/* layout */
.layout { height: calc(100% - 56px); display: grid; grid-template-columns: 1fr 320px; }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 24px max(16px, calc((100% - 820px) / 2)); display: flex; flex-direction: column; gap: 14px; }
.memory { border-left: 1px solid var(--line); background: var(--panel); padding: 18px; overflow-y: auto; }
.memory h3 { margin: 0 0 6px; font-size: 16px; }
.memory h4 { margin: 18px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.mem-scene { white-space: pre-wrap; font-size: 14px; }
.mem-log { margin: 0; padding-left: 20px; font-size: 13.5px; display: grid; gap: 3px; }
.privacy { margin-top: 24px; }

/* messages */
.empty { margin: auto; text-align: center; max-width: 460px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 22px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.examples button { font-size: 13px; }
.msg { max-width: 640px; display: grid; gap: 8px; }
.msg.user { align-self: flex-end; background: var(--user); padding: 10px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius); }
.msg.user .att { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; }
.msg.bot { align-self: flex-start; width: min(640px, 100%); }
.msg .text { white-space: pre-wrap; }
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.loader { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.result { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.result img { display: block; width: 100%; max-height: 70vh; object-fit: contain; cursor: zoom-in; background: #000; }
.result .badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.err-box { color: var(--err); font-size: 14px; }
details.prompt { font-size: 13px; color: var(--muted); }
details.prompt summary { cursor: pointer; }
details.prompt textarea { width: 100%; min-height: 110px; margin-top: 6px; padding: 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 13px/1.4 ui-monospace, Consolas, monospace; resize: vertical; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px max(16px, calc((100% - 820px) / 2)) 16px; border-top: 1px solid var(--line); background: var(--panel); }
.photo-pick { width: 56px; height: 56px; border-radius: 12px; border: 1.5px dashed var(--line); display: grid; place-items: center; cursor: pointer; overflow: hidden; flex: none; }
.photo-pick:hover { border-color: var(--accent); }
.photo-pick span { display: grid; text-align: center; font-size: 18px; line-height: 1.1; }
.photo-pick small { font-size: 10.5px; color: var(--muted); }
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick.need { border-color: var(--accent); animation: pulse 1.2s 3; }
.input-wrap { flex: 1; min-width: 0; display: grid; gap: 6px; }
.input-wrap textarea { width: 100%; resize: none; max-height: 180px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; }
.input-wrap textarea:focus { outline: none; border-color: var(--accent); }
.opts { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 12.5px; color: var(--muted); }
.opts select { margin-left: 4px; padding: 3px 6px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.send { width: 46px; height: 46px; padding: 0; font-size: 18px; border-radius: 12px; flex: none; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 40; display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox .close { position: absolute; top: 14px; right: 14px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .memory { position: fixed; top: 56px; right: 0; bottom: 0; width: min(340px, 90vw); z-index: 30; transform: translateX(100%); transition: transform .2s; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
  .memory.open { transform: none; }
  .mem-toggle { display: inline-block; }
  .gpu #gpuText { display: none; }
  .brand { font-size: 0; gap: 0; }
  .hint { display: none; }
  .top { gap: 8px; }
}
