:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1d2125; --muted: #5f6870; --line: #e1e3e1;
  --accent: #1f6f5c; --accent-text: #ffffff; --user: #e7f1ee; --card: #fff8e6; --card-line: #e9d9a8;
  --danger: #a33a2b; --code: #f0f1ef;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141719; --panel: #1c2023; --text: #e6e8e9; --muted: #9aa3a9; --line: #2e3438;
          --accent: #4fb39a; --accent-text: #0d1513; --user: #1f2e2a; --card: #2b2618; --card-line: #574a24;
          --danger: #e07a69; --code: #262b2e; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
       background: var(--panel); }
.top h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.who { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.who a { color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
       border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text);
       font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.full { width: 100%; } .small-btn { padding: 6px 12px; font-size: 14px; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }

.welcome { max-width: 560px; margin: 12vh auto 0; padding: 0 16px; text-align: center; }
.welcome h2 { font-size: 26px; margin-bottom: 8px; }
.welcome-actions { display: flex; gap: 12px; justify-content: center; margin: 24px 0 12px; flex-wrap: wrap; }

.layout { flex: 1; display: flex; min-height: 0; }
.side { width: 260px; flex-shrink: 0; border-right: 1px solid var(--line); padding: 12px; overflow-y: auto;
        background: var(--panel); }
.chats { list-style: none; margin: 12px 0 0; padding: 0; }
.chats li button { width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none;
                   color: var(--text); font: inherit; font-size: 14px; cursor: pointer; overflow: hidden;
                   text-overflow: ellipsis; white-space: nowrap; }
.chats li button:hover { background: var(--bg); }
.chats li button.active { background: var(--user); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 8px; background: var(--card);
          border: 1px solid var(--card-line); font-size: 14px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; max-width: 480px; }
.msg { max-width: 820px; width: fit-content; padding: 10px 14px; border-radius: 10px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); width: min(820px, 100%); }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h3, .msg.assistant h4 { margin: 12px 0 6px; font-size: 15px; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 8px; padding-left: 22px; }
.msg code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg pre { background: var(--code); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 13px; }
.msg pre code { background: none; padding: 0; }
.msg table { border-collapse: collapse; margin: 6px 0 8px; font-size: 14px; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.msg img.figure { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: 6px;
                  border: 1px solid var(--line); background: #fff; }
.msg .files { font-size: 13px; color: var(--muted); margin-top: 4px; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px; }
.msg.error { align-self: center; color: var(--danger); font-size: 14px; }

.question { align-self: flex-start; width: min(820px, 100%); background: var(--card); border: 1px solid var(--card-line);
            border-radius: 10px; padding: 12px 14px; }
.question .q-text { white-space: pre-wrap; margin-bottom: 10px; }
.question .q-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.question .q-options .btn { justify-content: flex-start; text-align: left; white-space: normal; }
.question .q-own { display: flex; gap: 8px; }
.question .q-own input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
                         background: var(--panel); color: var(--text); font: inherit; }
.question.done { opacity: .6; }

.activity { padding: 4px 16px; font-size: 13px; color: var(--muted); }
.activity::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px;
                    background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .activity::before { animation: none; } }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 12px; }
.composer textarea { width: 100%; resize: vertical; min-height: 44px; max-height: 40vh; padding: 9px 11px;
                     border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.composer-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.file-list { display: flex; flex-wrap: wrap; gap: 6px; }
.file-list:not(:empty) { margin-bottom: 8px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; border-radius: 999px; background: var(--user);
        font-size: 13px; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0; }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
         padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); }

@media (max-width: 760px) {
  .side { position: fixed; top: 49px; bottom: 0; left: 0; z-index: 5; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  .side:not(.open) { display: none; }
  .msg, .question { max-width: 100%; }
}
