/* ═══ Дизайн в стиле официального портала люберцы.рф ═══ */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --text: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #a11d42;        /* фирменный бордовый портала Люберец */
  --brand-dark: #8a1538;
  --brand-tint: #fdf3f6;
  --ok: #15803d;
  --ok-tint: #f0fdf4;
  --warn: #b45309;
  --warn-tint: #fffbeb;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 4px 14px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Manrope', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15.5px;
  line-height: 1.55;
}

.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* Тонкая фирменная полоса сверху, как на портале */
.topline { height: 4px; background: var(--brand); }

/* ─── Шапка ─── */
.header {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}
.header-in {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 18px;
  padding-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 52px; height: 52px;
  background: var(--brand);
  color: #fff;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(161, 29, 66, 0.35);
}
.brand-over {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--brand);
}
.header h1 { font-size: 21px; font-weight: 800; color: var(--ink); margin-top: 2px; }

/* ─── Навигация-разделы ─── */
.nav {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.nav-in { display: flex; gap: 6px; padding-top: 10px; padding-bottom: 10px; overflow-x: auto; }
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--brand); background: var(--brand-tint); }
.tab.active { background: var(--brand); color: #fff; }

/* ─── Основная область ─── */
.main { flex: 1; padding-top: 20px; padding-bottom: 28px; }
.view[hidden] { display: none; }
.view-title { font-size: 21px; font-weight: 800; color: var(--ink); margin-bottom: 14px; }
.view-subtitle { font-size: 16.5px; font-weight: 700; color: var(--ink); margin: 22px 0 10px; }
.muted { color: var(--muted); font-size: 14px; }

/* ─── Чат ─── */
.chat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 340px;
  max-height: calc(100vh - 330px);
}
.msg {
  max-width: 82%;
  padding: 12px 15px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.msg.bot.escalated { background: var(--brand-tint); border: 1px solid #f3cfd9; }
.msg.bot.crisis { background: var(--warn-tint); border: 1px solid #fde6b8; }
.msg.bot.general { background: #f8fafc; border: 1px dashed var(--line); }

.sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; padding: 6px 4px; }

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 16px 6px;
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
}
.composer input:focus { outline: 2px solid var(--brand); outline-offset: -1px; background: #fff; }

.chat-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 16px 14px;
}
.link-btn {
  border: none; background: none;
  color: var(--brand);
  font-size: 14px; font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.pulse { animation: pulse 1.6s ease-in-out infinite; border-radius: 8px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(161, 29, 66, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(161, 29, 66, 0); }
}
.privacy-note {
  font-size: 12.5px;
  color: var(--muted);
  max-width: 480px;
  line-height: 1.45;
}
.privacy-note a { color: var(--brand); }

/* ─── Кнопки ─── */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline { background: transparent; }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-small { padding: 6px 12px; font-size: 13.5px; border-radius: 9px; }
.btn-danger { color: var(--brand); border-color: #f3cfd9; }
.btn-danger:hover { background: var(--brand-tint); }

/* Шапка: меню пользователя */
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-menu[hidden] { display: none; }
.user-name { font-weight: 700; font-size: 14.5px; color: var(--ink); }
.role-badge {
  background: var(--brand);
  color: #fff;
  font-size: 12px; font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

/* ─── Панели и карточки ─── */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.panel h3 { font-size: 16.5px; font-weight: 800; color: var(--ink); margin-bottom: 10px; }
.panel-hint { color: var(--muted); font-size: 13.5px; margin-bottom: 12px; }

.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.dots { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.dots li::marker { color: var(--brand); }
.panel p + .dots { margin-top: 6px; }
.panel .muted { margin-top: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  color: var(--ink);
}
.card-answer { white-space: pre-wrap; font-size: 14.5px; line-height: 1.55; }
.status {
  background: var(--warn-tint);
  color: var(--warn);
  font-size: 12.5px; font-weight: 700;
  padding: 3px 11px;
  border-radius: 999px;
  align-self: center;
}
.status-done { background: var(--ok-tint); color: var(--ok); }

/* Карточка заявки */
.esc-card { border-left: 4px solid #eab308; }
.esc-card.esc-answered { border-left-color: var(--ok); }

.summary-block {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 14px;
  white-space: pre-wrap;
}
.dialog-details { margin-top: 8px; font-size: 14px; }
.dialog-details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.dialog-log {
  margin-top: 8px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--bg);
}
.dialog-line { margin-bottom: 6px; font-size: 13.5px; line-height: 1.45; }
.dialog-line.user b { color: var(--brand); }
.dialog-line.bot b { color: var(--muted); }

.reply-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-start; }
.reply-form textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.reply-block {
  background: var(--ok-tint);
  border: 1px solid #d3ecda;
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 14px;
  white-space: pre-wrap;
}

/* ─── Статистика (компактные чипы) ─── */
.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.stat-num { font-size: 20px; font-weight: 800; color: var(--brand); }
.stat-label { color: var(--muted); font-size: 13px; }

/* ─── Таблицы ─── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.table th, .table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }

.upload-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.upload-status { font-size: 13.5px; color: var(--muted); margin: 10px 0; min-height: 18px; }

.users-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
  font-size: 15px;
}

/* Форма создания учётной записи (администратор) */
.create-user-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 8px;
}
.create-user-form input, .create-user-form select {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
}
.create-user-form input:focus, .create-user-form select:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  background: #fff;
}
.create-user-form input { flex: 1 1 150px; }
.create-user-form select { flex: 0 0 auto; }

/* ─── Подвал ─── */
.footer-site {
  background: var(--brand-dark);
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  padding: 18px 0;
  margin-top: auto;
}

/* ─── Модальные окна ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
  padding: 26px;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal h2 { font-size: 19px; font-weight: 800; color: var(--ink); margin-bottom: 8px; }
.modal-hint { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; line-height: 1.5; }
.modal label { display: block; font-size: 14px; margin-bottom: 12px; font-weight: 700; color: var(--ink); }
.modal input[type="text"], .modal input[type="email"], .modal input[type="password"], .modal textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14.5px;
  font-family: inherit;
  font-weight: 400;
  background: var(--bg);
  resize: vertical;
}
.modal input:focus, .modal textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; background: #fff; }
.req { color: var(--brand); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.consent {
  display: flex !important;
  gap: 10px;
  align-items: flex-start;
  font-weight: 400 !important;
  font-size: 13px !important;
  color: var(--text) !important;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.consent input { margin-top: 3px; accent-color: var(--brand); }

.modal-close {
  position: absolute;
  top: 10px; right: 14px;
  border: none; background: none;
  font-size: 26px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

/* Вкладки входа/регистрации */
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.auth-tab {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 10px;
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--muted);
}
.auth-tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ─── Тост ─── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14.5px;
  z-index: 20;
  animation: fadein 0.25s ease;
  max-width: 90vw;
  text-align: center;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ─── Мобильные ─── */
@media (max-width: 640px) {
  .header h1 { font-size: 17.5px; }
  .brand-logo { width: 44px; height: 44px; font-size: 22px; }
  .msg { max-width: 94%; }
  .chat { max-height: calc(100vh - 360px); }
  .chat-foot { flex-direction: column; align-items: flex-start; gap: 8px; }
  .composer { flex-direction: column; }
  .composer .btn { width: 100%; }
}
