:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1b1b1f; --muted: #6b6b75; --line: #e4e2dc;
  --accent: #111; --claude: #c8622e; --claude-bg: #fbf1ea; --gpt: #1f8a64; --gpt-bg: #ecf7f2;
  --user-bg: #eef0f6; --danger: #c0392b; --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --panel: #1a1b1e; --ink: #ececef; --muted: #9a9aa5; --line: #2c2d31; --accent: #f2f2f2;
    --claude-bg: #2a1d16; --gpt-bg: #13241d; --user-bg: #1f2230; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
button.ghost, a.ghost { background: none; border: 0; color: var(--muted); padding: 6px 8px; text-decoration: none; font-size: 14px; }
button.icon { background: none; border: 0; padding: 6px 8px; font-size: 16px; color: var(--muted); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--danger); }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
textarea { resize: vertical; }
label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
label input, label select, label textarea, label .inrow { margin-top: 4px; color: var(--ink); font-size: 15px; }
.muted { color: var(--muted); }
.pad { padding: 12px; }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand b { font-weight: 400; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--bg); font-weight: 800; }

/* вход */
.gate { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.gate-card button { width: 100%; margin-top: 8px; padding: 11px; }
.err { color: var(--danger); min-height: 1.4em; }

/* разположение */
#app { display: flex; height: 100vh; height: 100dvh; }
#side { width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 6px; }
.new-row { display: flex; gap: 8px; padding: 8px 14px 12px; }
.new-row select { flex: 1; min-width: 0; }
#threadList { flex: 1; overflow: auto; padding: 0 8px; }
#threadList a { display: block; padding: 9px 10px; border-radius: 10px; color: inherit; text-decoration: none; margin-bottom: 2px; }
#threadList a:hover { background: var(--bg); }
#threadList a.active { background: var(--user-bg); }
#threadList .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
#threadList .m { display: block; font-size: 12px; color: var(--muted); }
.side-bottom { border-top: 1px solid var(--line); padding: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.title-wrap { flex: 1; min-width: 0; }
#topbar h1 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#roomName { font-size: 12px; }
#feed { flex: 1; overflow: auto; padding: 16px; }
.empty { max-width: 620px; margin: 8vh auto; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); }
.only-mobile { display: none; }

/* съобщения */
.row { display: grid; gap: 12px; margin: 0 auto 14px; max-width: 1200px; }
.row.n2 { grid-template-columns: 1fr 1fr; }
.row.n0 { display: none; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.msg.user { background: var(--user-bg); max-width: 820px; margin: 0 0 14px auto; }
@media (min-width: 1240px) { .msg.user { margin-right: calc((100% - 1200px) / 2); } }
.msg.claude { background: var(--claude-bg); border-top: 3px solid var(--claude); }
.msg.gpt { background: var(--gpt-bg); border-top: 3px solid var(--gpt); }
.msg.error { border-top-color: var(--danger); }
.msg .head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.msg.claude .head b { color: var(--claude); }
.msg.gpt .head b { color: var(--gpt); }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.tools { margin-left: auto; opacity: .55; }
.msg:hover .tools { opacity: 1; }
.msg .body { overflow-wrap: anywhere; }
.msg .body p { margin: .5em 0; }
.msg .body pre { white-space: pre-wrap; background: rgba(127,127,127,.1); padding: 8px; border-radius: 8px; }
.msg .body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.msg .body td, .msg .body th { border: 1px solid var(--line); padding: 4px 8px; }
.msg .foot { font-size: 11px; margin-top: 6px; }
.errtext { color: var(--danger); }
.dots i { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--muted); animation: b 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes b { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* долна част */
#actions { display: flex; gap: 8px; align-items: center; padding: 8px 16px 0; flex-wrap: wrap; }
#composer { padding: 8px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); border: 2px dashed transparent; border-radius: 12px; transition: border-color .15s, background-color .15s; }
#composer.dragover { border-color: var(--claude); background-color: var(--claude-bg); }
.target { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.target label { margin: 0; display: flex; align-items: center; gap: 4px; }
.target input { width: auto; margin: 0; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { flex: 1; resize: none; max-height: 240px; }
.compose-row button { padding: 10px 16px; }
.icon-btn { width: auto; padding: 9px 11px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1; margin: 0; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attach-list .chip { display: inline-flex; align-items: center; gap: 6px; background: var(--user-bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px 6px 3px 3px; font-size: 12px; max-width: 220px; }
.attach-list .chip img { width: 24px; height: 24px; object-fit: cover; border-radius: 6px; }
.attach-list .chip.uploading { opacity: .6; }
.attach-list .cn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.attach-list .rm { border: 0; background: none; padding: 0 2px; color: var(--muted); font-size: 13px; }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.msg-img { max-width: 220px; max-height: 220px; border-radius: 10px; border: 1px solid var(--line); display: block; }

/* модални */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border-radius: var(--radius); width: 100%; max-width: 720px; max-height: 92vh; display: flex; flex-direction: column; }
.modal-card.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { overflow: auto; padding: 8px 16px 16px; margin: 0; }
pre.modal-body { white-space: pre-wrap; font-size: 13px; }
.modal-body section { border-bottom: 1px solid var(--line); padding: 8px 0 14px; }
.modal-body h3 { margin: 10px 0 4px; font-size: 15px; }
.modal-body h4 { margin: 14px 0 4px; font-size: 14px; }
.inrow { display: flex; gap: 8px; }
.inrow input { flex: 1; }
.save-row { padding: 10px 0; }
.files { list-style: none; padding: 0; margin: 8px 0; }
.files li { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.files .fn { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.filebtn { display: inline-block; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; color: var(--ink); }
.filebtn input { display: none; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--accent); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; z-index: 99; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* мобилни */
@media (max-width: 800px) {
  .only-mobile { display: inline-block; }
  #side { position: fixed; inset: 0 auto 0 0; width: 86%; max-width: 320px; z-index: 40; transform: translateX(-102%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.side-open #side { transform: none; }
  .row.n2 { grid-template-columns: 1fr; }
  #feed { padding: 12px; }
  .msg.user { max-width: 100%; }
  #topbar { padding: 8px 10px; }
  #composer, #actions { padding-left: 10px; padding-right: 10px; }
  input, select, textarea { font-size: 16px; }
}
