:root {
  --purple: #6c63ff;
  --purple-dark: #564fd1;
  --bg: #f5f6fa;
  --panel: #ffffff;
  --border: #e3e5ec;
  --text: #1c1e26;
  --text-dim: #6b7080;
  --green: #2fa365;
  --amber: #d98c1e;
  --red: #d9483a;
}

* { box-sizing: border-box; }

/* Класс .chat-empty/.chat-view задаёт display:flex с той же специфичностью, что и
   UA-правило [hidden] { display:none } — без этого явного !important они перебивают
   друг друга непредсказуемо в зависимости от порядка объявления. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ─── Login ─────────────────────────────────────────── */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
}

.login-subtitle {
  margin: -8px 0 8px;
  color: var(--text-dim);
  font-size: 13px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.login-card button {
  margin-top: 6px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--purple);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover { background: var(--purple-dark); }

.login-error {
  color: var(--red);
  font-size: 13px;
  margin: 0;
}

/* ─── App shell ─────────────────────────────────────── */

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 52px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-weight: 700; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.btn-link {
  background: none;
  border: none;
  color: var(--purple);
  cursor: pointer;
  font-size: 13px;
}

.app-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* ─── Sidebar / conversation list ───────────────────── */

.sidebar {
  width: 340px;
  flex: 0 0 auto;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-filters {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-filters input,
.sidebar-filters select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.filter-row {
  display: flex;
  gap: 8px;
}

.filter-row select { flex: 1; min-width: 0; }

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.conversation-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.conversation-item:hover { background: #f9f9fc; }
.conversation-item.active { background: #efedff; }

.conv-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.conv-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--text-dim);
  flex: 0 0 auto;
}

.conv-request {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-tags {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eee;
  color: var(--text-dim);
}

.tag.human { background: #fdecea; color: var(--red); }
.tag.bot { background: #eaf7f0; color: var(--green); }

/* ─── Chat pane ─────────────────────────────────────── */

.chat-pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
}

.chat-header-name { font-weight: 700; }
.chat-header-phone { font-size: 12px; color: var(--text-dim); }

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eee;
}

.btn-toggle {
  border: 1px solid var(--border);
  background: white;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}

.btn-toggle.mode-human {
  border-color: var(--red);
  color: var(--red);
}

.btn-toggle.mode-bot {
  border-color: var(--green);
  color: var(--green);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-start;
  background: #eee;
}

.msg.assistant {
  align-self: flex-end;
  background: var(--purple);
  color: white;
}

.msg.manager {
  align-self: flex-end;
  background: var(--amber);
  color: white;
}

.msg-meta {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
}

.chat-compose {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-compose textarea {
  flex: 1;
  resize: none;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}

.chat-compose button {
  padding: 0 18px;
  border: none;
  border-radius: 8px;
  background: var(--purple);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.chat-compose button:hover { background: var(--purple-dark); }
