:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1b1d21;
  --muted: #6b6f76;
  --line: #e2e0db;
  --accent: #1f5eff;
  --user: #eef2ff;
  --err: #b42318;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1d2024; --ink: #e9eaec; --muted: #9a9ea6; --line: #30343a;
    --accent: #6f95ff; --user: #23293a; --err: #ff8a80; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:disabled { opacity: .5; cursor: wait; }

.top { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-size: 15px; letter-spacing: .01em; }
.brand span { color: var(--accent); }
.status { margin-right: auto; color: var(--muted); font-size: 13px; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 360px 1fr; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.log { flex: 1; overflow-y: auto; margin: 0; padding: 16px; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.msg { white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 12px; border-radius: 10px; max-width: 95%; }
.msg.assistant { align-self: flex-start; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.error { color: var(--err); border: 1px solid currentColor; }
.msg img { display: block; max-width: 100%; border-radius: 6px; margin-bottom: 6px; }

.composer { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.row { display: flex; justify-content: space-between; align-items: center; }
.file { color: var(--accent); cursor: pointer; }
.attach { position: relative; width: 72px; }
.attach img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.attach button { position: absolute; top: -6px; right: -6px; padding: 0 6px; border-radius: 50%; }
#send { background: var(--accent); border-color: var(--accent); color: #fff; }

.cad { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#cad { flex: 1; width: 100%; border: 0; background: #212830; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
dialog input { display: block; width: 100%; margin: 8px 0 12px; padding: 8px; font: inherit; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto; }
  .chat { order: 2; border-right: 0; border-top: 1px solid var(--line); min-height: 50vh; }
  .top { flex-wrap: wrap; }
}
