/* ===== Базовые стили ===== */
* {
  box-sizing: border-box;
}

:root {
  --bg-page: #F7F8FA;
  --bg-header: #FFFFFF;
  --border: #E5E7EB;
  --active-bg: #EEF2FF;
  --accent: #4D6BFE;
  --text-main: #1E293B;
  --text-muted: #6B7280;
  --msg-user-bg: #4D6BFE;
  --msg-user-text: #FFFFFF;
  --msg-assistant-bg: #F1F5F9;
  --msg-assistant-text: #1E293B;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Каркас приложения ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

/* ===== Шапка ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header__title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

/* ===== Раскладка: сайдбар + контент ===== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ===== Боковое меню ===== */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-header);
  border-right: 1px solid var(--border);
  padding: 8px;
  overflow-y: auto;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--text-main);
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.nav-item:hover:not(:disabled) {
  background: #F1F5F9;
}

.nav-item.active {
  background: var(--active-bg);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-item--log {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

/* ===== Область контента ===== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ===== Лента сообщений ===== */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feed__empty {
  color: var(--text-muted);
  text-align: center;
  margin-top: 40px;
}

/* ===== Сообщение ===== */
.msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg--user {
  align-self: flex-end;
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  border-bottom-right-radius: 4px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--msg-assistant-bg);
  color: var(--msg-assistant-text);
  border-bottom-left-radius: 4px;
}

.msg--system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 8px;
}

/* Кликабельные сообщения (в журнале) */
.msg--clickable {
  cursor: pointer;
}

.msg--clickable:hover {
  background: #EEF2FF;
}

/* Подсветка последнего сообщения выбранной роли */
.msg--last {
  outline: 2px solid #4D6BFE;
  outline-offset: 2px;
}

.msg__meta {
  display: block;
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 4px;
}

.msg__role {
  font-weight: 600;
}

.msg__addressing {
  font-weight: 400;
}

/* ===== Панель получателей ===== */
.recipients-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-header);
  padding: 12px 20px;
  flex-shrink: 0;
}

.recipients-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.recipients-panel__title {
  font-weight: 600;
}

.recipients-panel__list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.recipients-panel__selected {
  color: var(--text-muted);
  font-size: 13px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* ===== Форма ввода ===== */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg-header);
  padding: 12px 20px;
  flex-shrink: 0;
}

.composer__input {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-main);
}

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
}

.composer__input:disabled {
  background: #F1F5F9;
  cursor: not-allowed;
}

.composer__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.status {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 20px;
}

/* ===== Кнопки ===== */
.btn {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #FFFFFF;
}

.btn--primary:hover:not(:disabled) {
  opacity: 0.9;
}

.btn--ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--active-bg);
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
    flex-shrink: 0;
  }

  .sidebar__nav {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    width: auto;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 8px 12px;
  }

  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .nav-item--log {
    margin-top: 0;
    border-top: none;
    padding-top: 8px;
  }

  .msg {
    max-width: 90%;
  }
}
