/* Беседа: сообщения, markdown, агрегаты, composer, лайтбокс, опросы, разрешения */
/* ---------- Беседа ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f7f9fc; }

.chat-empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: #9aa3af;
  font-size: 15px;
}

.chat-view { display: flex; flex-direction: column; height: 100%; }

.head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}

.back-btn { display: none; }

.head-titles { flex: 1; min-width: 0; }
.head-title {
  font-weight: 650; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 8px;
}
.head-status { font-size: 12.5px; color: #8a94a3; }

.head .avatar { width: 40px; height: 40px; font-size: 15px; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.thread > :first-child { margin-top: auto; }

.load-bar {
  align-self: center;
  margin: 2px 0 10px;
}
.load-more {
  border: 0;
  background: #eef1f5;
  color: #4f81ff;
  font-size: 13px;
  font-family: inherit;
  border-radius: 15px;
  padding: 7px 15px;
  cursor: pointer;
  transition: background .12s;
}
.load-more:hover { background: #e0e7f3; }

.day {
  align-self: center;
  font-size: 12px;
  color: #8a94a3;
  background: #eef1f5;
  border-radius: 14px;
  padding: 3px 12px;
  margin: 8px 0;
}

.msg { max-width: 66%; display: flex; align-items: flex-end; gap: 8px; animation: pop .12s ease-out; }
.msg.mine { align-self: flex-start; }
.msg.theirs { align-self: flex-start; }

@keyframes pop { from { transform: translateY(4px); opacity: .55; } to { transform: none; opacity: 1; } }

.bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 8px 12px 6px;
  max-width: 100%;
  box-shadow: 0 1px 1px rgba(16,24,40,.04);
}
.msg.mine .bubble { background: #d3ecff; border-color: #c0e1ff; }

.msg-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }

.msg-text { font-size: 14.5px; line-height: 1.35; word-wrap: break-word; }
.msg-text a { color: #1a73e8; text-decoration: underline; word-break: break-all; }
.msg-text a:hover { text-decoration: none; }

.msg-ts {
  font-size: 11px;
  color: #8a94a3;
  text-align: right;
  margin-top: 2px;
}
.msg.mine .msg-ts { color: #5f8fc7; }

.photo { border-radius: 12px; overflow: hidden; max-width: 260px; cursor: pointer; }
.photo img { display: block; width: 100%; height: auto; }
.msg-file { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; word-break: break-all; }
.file-ico { flex-shrink: 0; }
.file-link { color: #1c7ed6; text-decoration: underline; word-break: break-all; }

/* ----------  Markdown в ответах ИИ ---------- */
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text .md-h { margin: 8px 0 4px; line-height: 1.3; }
.msg-text h2.md-h { font-size: 16px; }
.msg-text h3.md-h { font-size: 15px; }
.msg-text h4.md-h { font-size: 14px; }
.msg-text .md-p { margin: 4px 0 6px; }
.msg-text code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: #eef1f5; border-radius: 6px; padding: 1px 5px; }
.msg.mine .msg-text code { background: #c9e6ff; }
.md-table { border-collapse: collapse; margin: 6px 0; font-size: 13px; max-width: 100%; }
.md-table th, .md-table td { border: 1px solid #dce3ec; padding: 3px 8px; vertical-align: top; text-align: left; }
.md-table th { background: rgba(79, 129, 255, .08); font-weight: 600; }
.md-list { margin: 4px 0 6px; padding-left: 20px; }
.md-list li { margin: 2px 0; }
.md-q { margin: 6px 0; padding: 4px 10px; border-left: 3px solid #c8d0da; color: #5b6472; }
.md-code { background: #f6f8fa; border: 1px solid #e5e7eb; border-radius: 10px; margin: 6px 0 8px; overflow: hidden; }
.md-code-head { font-size: 11px; color: #8a94a3; padding: 2px 10px; border-bottom: 1px solid #eef1f5; text-transform: lowercase; letter-spacing: .3px; }
.md-code pre { margin: 0; padding: 8px 10px; font-size: 12px; line-height: 1.45; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: pre; }

/* ----------  служебные сообщения (агрегаты) ---------- */
.agg {
  align-self: flex-start;
  width: 100%;
  max-width: 92%;
  display: flex;
  flex-direction: column;
  margin: 2px 0;
}
.agg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: 100%;
  border: 1px dashed #d7dce3;
  background: #f4f6f9;
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-family: inherit;
  color: #6b7280;
  cursor: pointer;
  text-align: left;
}
.agg-toggle:hover { background: #eef1f5; border-color: #c3cad4; }
.agg-chev { flex: none; display: inline-block; font-size: 13px; color: #9aa3af; line-height: 1; transition: transform .15s ease; }
.agg.open .agg-chev { transform: rotate(90deg); }
.agg-sum { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agg-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 2px 4px;
  padding-left: 10px;
  border-left: 2px solid #e7ebf1;
}
.svc {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 6px 10px 8px;
  font-size: 13px;
}
.svc-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #6b7280; margin-bottom: 4px; }
.svc-head b { font-weight: 650; }
.svc-ts { margin-left: auto; flex: none; font-size: 11px; color: #aab2bd; font-weight: 400; }
.svc-status { flex: none; font-size: 11px; border-radius: 10px; padding: 1px 8px; background: #eef4ff; color: #4f81ff; }
.svc-status.err { background: #fdecec; color: #e03131; }
.svc-status.run { background: #fff4e5; color: #b26a00; }
.svc-text { white-space: pre-wrap; word-wrap: break-word; font-size: 13px; color: #374151; line-height: 1.45; }
.svc.tool .svc-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f6f8fa;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11.5px;
  line-height: 1.4;
  color: #3b4654;
}
.svc.reasoning .svc-text { color: #6a4f9c; font-style: italic; }
.svc.compaction .svc-text, .svc.summary .svc-text { color: #7a6a3a; font-size: 12px; }
.svc-files { display: flex; flex-wrap: wrap; gap: 4px; }
.svc-file { font-size: 11.5px; background: #eef7ee; color: #2b6b34; border: 1px solid #d5ead6; border-radius: 8px; padding: 2px 8px; }

/* ---------- Комposer ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}

.composer textarea {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 14.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.35;
}
.composer textarea:focus { border-color: #4f81ff; }

.send-btn {
  border: 0;
  background: #4f81ff;
  color: #fff;
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 17px;
  cursor: pointer;
  flex: none;
}
.send-btn:hover { background: #3f6fff; }

/* ---------- Лайтбокс ---------- */
.lightbox[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
}
.lightbox img { max-width: 92%; max-height: 92%; border-radius: 8px; }
/* ----------  вопрос-опрос (question-тул opencode) ---------- */
.msg.qmsg { max-width: 82%; }
.bubble.poll { border-color: #d9d2f5; background: #fbfaff; }
.poll-body { display: flex; flex-direction: column; gap: 12px; }
.poll-q { display: flex; flex-direction: column; gap: 6px; }
.poll-header { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: #6741d9; }
.poll-question { font-size: 14.5px; line-height: 1.35; }
.poll-question > :first-child { margin-top: 0; }
.poll-question > :last-child { margin-bottom: 0; }
.poll-opts { display: flex; flex-direction: column; gap: 6px; }
.poll-opt {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  background: #fff;
  border: 1px solid #e0ddf0;
  border-radius: 11px;
  padding: 8px 11px;
  color: #1f2430;
  transition: border-color .12s, background .12s;
}
.poll-opt:hover { border-color: #b9aef0; background: #f6f3ff; }
.poll-opt.on { border-color: #6741d9; background: #efeaff; }
.poll-mark {
  flex: none;
  width: 17px;
  height: 17px;
  margin-top: 1px;
  border: 2px solid #c3cbda;
  border-radius: 50%;
  position: relative;
  box-sizing: border-box;
}
.poll-opts[data-multiple="1"] .poll-mark { border-radius: 5px; }
.poll-opt.on .poll-mark { border-color: #6741d9; background: #6741d9; }
.poll-opt.on .poll-mark::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.poll-label { font-size: 14px; font-weight: 600; }
.poll-desc { display: block; font-size: 12.5px; color: #6b7280; margin-top: 2px; line-height: 1.35; }
.poll-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding-top: 8px; border-top: 1px solid #eee9fb; }
.poll-status { font-size: 12px; color: #8a94a3; }
.bubble.poll.answered .poll-status { color: #2f9e44; font-weight: 600; }
.poll-send {
  border: 0;
  background: #6741d9;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.poll-send:hover { background: #5a35c4; }
.poll-send:disabled { opacity: .6; cursor: default; }
.bubble.poll.answered .poll-opt { cursor: default; }
.bubble.poll.answered .poll-opt:not(.on) { opacity: .5; }
.bubble.poll.answered .poll-opt.on { border-color: #2f9e44; background: #eefaf0; }
.bubble.poll.answered .poll-opt.on .poll-mark { background: #2f9e44; border-color: #2f9e44; }

/* ----------  запросы разрешений opencode (permission) ---------- */

.perm-title { font-size: 13px; font-weight: 700; color: #e8590c; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 6px; }
.perm-text { font-size: 14px; line-height: 1.4; word-break: break-word; }
.perm-code {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: #f5f3fa;
  border: 1px solid #e6e0f5;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.perm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.perm-btn {
  border: 1px solid;
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 10px;
  cursor: pointer;
}
.perm-btn:disabled { opacity: .6; cursor: default; }
.perm-btn.once { border-color: #b9aef0; color: #6741d9; background: #f6f3ff; }
.perm-btn.once:hover { background: #efeaff; }
.perm-btn.always { border-color: #6741d9; color: #fff; background: #6741d9; }
.perm-btn.always:hover { background: #5a35c4; }
.perm-btn.reject { border-color: #f2c3c3; color: #d6391d; background: #fef3f2; }
.perm-btn.reject:hover { background: #fee9e7; }
.perm-why {
  flex: 1 1 180px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  background: #fff;
}
.bubble.poll.perm.answered .perm-actions { display: none; }
.bubble.poll.perm.answered .poll-status { color: #2f9e44; font-weight: 600; }
.bubble.poll.perm.answered .perm-title { color: #2f9e44; }