:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #dde1e6;
  --primary: #334383;
  --primary-dark: #283150;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #802626;
  --internal-bg: #fef3c7;
}

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

body {
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- Шапка сайта ---------- */
.topbar {
  height: 48px;
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  max-width: 1200px;
  margin: 0 auto;
  border-radius: 0 0 10px 10px;
}
.topbar-logo { width: 30px; height: 30px; }
.topbar-title { font-size: 18px; font-weight: 700; letter-spacing: .3px; }

/* Бренд над формой входа/регистрации (не шире формы, по центру) */
.brand-login {
  width: 360px;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--primary-dark);
}
.brand-login img { width: 42px; height: 42px; }
.brand-login span { font-size: 24px; font-weight: 700; letter-spacing: .3px; }

/* ---------- Экран входа ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin-bottom: 20px; }

/* ---------- Общая раскладка ---------- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr;
  gap: 20px;
  min-height: calc(100vh - 48px);
}

/* Профиль (верхний левый угол, ТЗ 7.2) */
.profile-card {
  grid-row: 1 / 3;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  align-self: start;
  text-align: center;
}
.avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  position: relative;
}
.unread-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 24px; height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--danger, #dc2626);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
/* Колонка действий в таблице пользователей — фиксированная ширина, кнопки в один ряд */
.col-actions {
  width: 390px;
  min-width: 290px;
  white-space: nowrap;
}
.col-actions .btn { margin-right: 6px; }
.profile-card .name { font-weight: 600; font-size: 15px; }
.profile-card .role { color: var(--primary); font-size: 13px; margin: 2px 0; }
.profile-card .org { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.profile-stats { border-top: 1px solid var(--border); padding-top: 12px; text-align: left; }
.profile-stats div { display: flex; justify-content: space-between; padding: 3px 0; }
.profile-actions { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }

/* Вкладки-иконки: иконка сверху, подпись снизу; активная — тонкая полоса снизу */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: stretch;
}
.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 14px 6px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 12px;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.tabs a svg { width: 22px; height: 22px; }
.tabs a:hover { color: var(--primary); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.content { min-width: 0; }

/* ---------- Карточки, таблицы ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 880px;
  max-width: 100%;
}
.card h2 { font-size: 18px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8fafc; }

/* Статусы (ТЗ 7.4) */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.badge-new { background: #9ca3af; }
.badge-in_progress { background: #3b82f6; }
.badge-resolved { background: #22c55e; }
.badge-escalated { background: #ef4444; }
.badge-closed { background: #4b5563; }

/* ---------- Формы ---------- */
label { display: block; font-weight: 500; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=email], input[type=tel],
input[type=datetime-local], input[type=date], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; min-height: 110px; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.form-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 400; }

/* Фильтры */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; flex: 1; min-width: 140px; }

/* Пагинация */
.pagination { margin-top: 16px; display: flex; gap: 8px; align-items: center; }

/* ---------- Чат заявки (ТЗ 7.5) ---------- */
.ticket-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.ticket-head h2 { margin: 0; flex: 1; }

.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  position: relative;
}
.msg-client { align-self: flex-end; background: #f1f5f9; border: 1px solid var(--border); }
.msg-staff { align-self: flex-start; background: #dbeafe; border: 1px solid #bfdbfe; }
.msg-internal { align-self: flex-start; background: var(--internal-bg); border: 1px solid #fcd34d; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .meta .internal-tag { color: #b45309; font-weight: 700; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.msg .edited { font-size: 11px; color: var(--muted); font-style: italic; }
.msg .msg-actions { margin-top: 6px; display: flex; gap: 8px; }
.msg .msg-actions a { font-size: 12px; color: var(--primary); cursor: pointer; text-decoration: none; }
.msg .msg-actions a.danger { color: var(--danger); }
.msg .atts { margin-top: 6px; font-size: 12px; }
.msg .atts a { color: var(--primary); }

.attachments-list { margin-top: 8px; }
.attachments-list a { color: var(--primary); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  margin-top: 8px;
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--primary); background: #eff6ff; }

/* ---------- Диаграммы (аналитика) ---------- */
.chart-wrap { margin-bottom: 20px; overflow-x: auto; }
.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Футер и согласие на обработку ПДн (152-ФЗ) */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 16px 0 24px;
}
.footer a { color: var(--primary); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.consent-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 10px;
  line-height: 1.5;
}
.consent-note a { color: var(--primary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: #111827;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 100;
  max-width: 360px;
}
.toast.error { background: var(--danger); }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .profile-card { grid-row: auto; }
  .msg { max-width: 95%; }
}
