:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172033;
  background: #f6f8fb;
  font-synthesis: none;
  --blue: #2f80ed;
  --blue-dark: #1f6fd6;
  --blue-soft: #eaf3ff;
  --surface: #ffffff;
  --surface-muted: #f4f6f9;
  --border: #e3e8ef;
  --muted: #6e7b8e;
  --danger: #a43a3a;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #f6f8fb;
}

button, textarea { font: inherit; }

.shell {
  width: min(760px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar, .control-card, .section-heading, .composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #46a0ff, #2674df);
  box-shadow: 0 6px 16px rgb(47 128 237 / 22%);
  font-size: 19px;
  font-weight: 800;
}

.eyebrow, .label {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; color: #172033; }
h1 { font-size: 21px; line-height: 1.15; }
h2 { font-size: 16px; }

.connection, .shared-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: #edf1f6;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.connection.online { color: #13713c; background: #e0f5e8; }
.connection.offline { color: #9b3030; background: #ffe9e9; }

.control-card, .chat-card, .composer {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(28 45 70 / 6%);
}

.control-card {
  padding: 14px;
  border-radius: 16px;
}

.control-card strong { display: block; font-size: 16px; }
.muted { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.control-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 750;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: default; opacity: .45; }
.primary, .send { color: #fff; background: var(--blue); }
.primary:hover:not(:disabled), .send:hover:not(:disabled) { background: var(--blue-dark); }
.secondary { color: #314056; background: #edf1f6; }

.error-box {
  padding: 10px 12px;
  border: 1px solid #ffd0d0;
  border-radius: 12px;
  color: var(--danger);
  background: #fff2f2;
  font-size: 13px;
  line-height: 1.4;
}
.hidden { display: none; }

.chat-card {
  min-height: 210px;
  flex: 1 1 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
}

.section-heading {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.messages {
  min-height: 150px;
  overflow-y: auto;
  flex: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.empty {
  max-width: 300px;
  margin: auto;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.empty::before {
  content: "Пока нет сообщений";
  display: block;
  margin-bottom: 5px;
  color: #314056;
  font-size: 15px;
  font-weight: 750;
}

.message {
  width: min(88%, 620px);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 15px 15px 15px 5px;
  background: var(--surface);
  box-shadow: 0 2px 7px rgb(28 45 70 / 5%);
}

.message.user {
  align-self: flex-end;
  border-color: #cfe3ff;
  border-radius: 15px 15px 5px 15px;
  background: var(--blue-soft);
}

.message.system {
  width: min(94%, 620px);
  align-self: center;
  color: #863636;
  border-color: #f0d0d0;
  border-radius: 14px;
  background: #fff4f4;
}

.message-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: 11px; color: var(--muted); }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.message.system .message-content { font-size: 14px; }
.message-status { margin-top: 6px; color: var(--muted); font-size: 11px; }

.composer {
  flex: 0 0 auto;
  padding: 12px;
  border-radius: 16px;
}

.composer-label {
  display: block;
  margin: 0 0 7px 2px;
  color: #314056;
  font-size: 13px;
  font-weight: 750;
}

textarea {
  width: 100%;
  min-height: 78px;
  max-height: 170px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: 0;
  padding: 11px 12px;
  color: #172033;
  background: #f8fafc;
  line-height: 1.4;
}

textarea:focus { border-color: #94bff8; box-shadow: 0 0 0 3px rgb(47 128 237 / 10%); }
textarea:disabled { color: #8792a2; background: #f3f5f7; }
.composer-footer { margin-top: 9px; }
.composer-hint { color: var(--muted); font-size: 11px; }
.send { min-width: 150px; }

.events-panel { color: var(--muted); font-size: 12px; }
.events-panel summary { cursor: pointer; padding: 6px 4px; font-weight: 650; }
.events-panel ol { max-height: 160px; overflow: auto; margin: 4px 0 0; padding: 10px 10px 10px 30px; border-radius: 12px; background: #fff; }
.events-panel li { padding: 3px 0; }

@media (max-width: 520px) {
  .shell { gap: 10px; padding-left: 10px; padding-right: 10px; }
  .control-card { align-items: stretch; flex-direction: column; }
  .control-actions { width: 100%; justify-content: stretch; }
  .control-actions button { flex: 1; }
  .shared-badge { display: none; }
  .message { width: 94%; }
  .composer-footer { align-items: stretch; flex-direction: column; }
  .send { width: 100%; }
}

@media (max-height: 700px) {
  .brand-mark { width: 34px; height: 34px; }
  .eyebrow { display: none; }
  .chat-card { min-height: 170px; flex-basis: 220px; }
  textarea { min-height: 62px; }
}
