:root {
  --brand: #2f6fd0;
  --brand-dark: #245bb0;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2733;
  --muted: #66717f;
  --line: #e3e8ef;
  --ok: #2e7d32;
  --warn: #b26a00;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
#app { display: flex; flex-direction: column; height: 100vh; }

/* Шапка */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; }
.brand-name { font-weight: 600; font-size: 17px; line-height: 1.1; }
.brand-sub { font-size: 12px; opacity: .9; }
.badge {
  background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.5);
  border-radius: 12px; padding: 2px 10px; font-size: 12px;
}

/* Панель ролей */
.rolebar {
  display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.role-btn {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 18px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  font-size: 13px; white-space: nowrap;
}
.role-btn:hover { border-color: var(--brand); color: var(--brand); }
.role-btn.active {
  background: var(--brand); border-color: var(--brand); color: #fff;
}

/* Стартовый экран */
.start {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow: auto;
}
.start-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 24px; max-width: 560px; width: 100%;
  box-shadow: 0 4px 18px rgba(31,39,51,.06);
}
.start-hello { font-size: 16px; line-height: 1.5; }
.start-hint { margin: 16px 0 10px; color: var(--muted); font-size: 13px; }
.start-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.start-buttons .role-btn { border-radius: 10px; padding: 10px 16px; font-size: 14px; }

/* Чат */
.chat { flex: 1; overflow-y: auto; padding: 16px; }
.messages { display: flex; flex-direction: column; gap: 12px; max-width: 860px; margin: 0 auto; }
.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px; border-radius: 12px; line-height: 1.45;
  font-size: 14px; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble {
  background: var(--card); border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.system .bubble {
  background: #fff8e8; border: 1px solid #f0dfb5; color: var(--warn);
}
.sources {
  margin-top: 6px; font-size: 12px; color: var(--muted);
  background: #eef3fb; border: 1px solid #d7e2f2; border-radius: 8px; padding: 6px 10px;
}
.msg-actions { display: flex; gap: 8px; margin-top: 6px; }
.mini-btn {
  font-size: 12px; padding: 4px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
}
.mini-btn:hover { border-color: var(--brand); color: var(--brand); }
.mini-btn[disabled] { opacity: .45; cursor: default; }

/* Поле ввода */
.composer {
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 14px 8px;
}
.limit-note {
  max-width: 860px; margin: 0 auto 8px; font-size: 12px;
  color: var(--warn); background: #fff8e8;
  border: 1px solid #f0dfb5; border-radius: 8px; padding: 6px 10px;
}
.composer-row { display: flex; gap: 10px; max-width: 860px; margin: 0 auto; }
textarea#input {
  flex: 1; resize: none; min-height: 40px; max-height: 140px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 14px; outline: none;
}
textarea#input:focus { border-color: var(--brand); }
.send-btn {
  width: 44px; height: 40px; border: none; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 16px;
}
.send-btn:hover { background: var(--brand-dark); }
.send-btn[disabled] { opacity: .5; cursor: default; }
.composer-hint {
  max-width: 860px; margin: 6px auto 0; font-size: 11px; color: var(--muted);
}

@media (max-width: 640px) {
  .msg { max-width: 96%; }
  .brand-sub { display: none; }
}
