:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
}

* { box-sizing: border-box; }

/* Без этого [hidden] не срабатывает на элементах, у которых класс
   (.modal-backdrop, .app, .view-login) сам задаёт display:flex —
   правило класса иначе перебивает скрытие. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Логин ---------- */
.view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 30px;
  width: 340px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { font-size: 18px; margin: 0 0 6px; }

.login-card label { font-size: 13px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }

input, textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: #fff;
}
input:focus, textarea:focus { border-color: var(--primary); }

button { font: inherit; cursor: pointer; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  color: var(--text);
}
.btn-secondary:hover { background: #f8fafc; }

.error-text { color: var(--danger); font-size: 13px; margin: 0; }

.mock-hint {
  background: #eff6ff; color: #1d4ed8; font-size: 12.5px;
  padding: 8px 10px; border-radius: 8px; margin: 0;
}

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #0f172a;
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
}

.sidebar-title { font-weight: 700; font-size: 15px; margin-bottom: 24px; padding: 0 6px; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 4px;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--primary); color: #fff; }

.logout-btn {
  margin-top: auto;
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: #cbd5e1;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.logout-btn:hover { background: rgba(255,255,255,.06); }

.content { flex: 1; padding: 28px 34px; overflow-y: auto; }

.tab { display: none; }
.tab.active { display: block; }

.tab-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.tab-header h2 { font-size: 19px; margin: 0; }

/* ---------- Таблица ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 10px; overflow: hidden; }
.data-table th, .data-table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.data-table th { color: var(--text-muted); font-weight: 600; background: #f8fafc; }
.data-table tbody tr:hover { background: #f8fafc; cursor: default; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.selected { background: #eff6ff; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-escalated { background: #fef3c7; color: #b45309; }
.badge-closed { background: #e2e8f0; color: #475569; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-human { background: #ecfdf5; color: #065f46; margin-left: 6px; }

.row-actions button {
  background: none; border: none; color: var(--primary); font-size: 13px; margin-right: 10px; padding: 0;
}
.row-actions button.danger { color: var(--danger); }

.empty-state { color: var(--text-muted); font-size: 14px; padding: 20px 0; }

/* ---------- Диалоги ---------- */
.conversations-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: start; }
.thread-panel { background: var(--surface); border-radius: 10px; padding: 16px; min-height: 200px; max-height: 70vh; overflow-y: auto; }
.thread-active { display: flex; flex-direction: column; height: 68vh; gap: 10px; }
.thread-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.thread-visitor { display: flex; flex-direction: column; font-size: 13.5px; font-weight: 600; }
.thread-visitor-contact { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.thread-messages { flex: 1; overflow-y: auto; }
.thread-msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 8px; line-height: 1.4; }
.thread-msg.user { background: var(--primary); color: #fff; margin-left: auto; border-bottom-right-radius: 3px; }
.thread-msg.assistant { background: #f1f5f9; border-bottom-left-radius: 3px; }
.thread-msg.operator { background: #ecfdf5; color: #065f46; border-bottom-left-radius: 3px; }
.thread-msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; opacity: .75; }
.thread-compose { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.thread-compose textarea {
  flex: 1; resize: none; min-height: 38px; max-height: 90px; font-size: 13.5px;
}

/* ---------- Модалка ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: var(--surface); border-radius: 14px; padding: 26px; width: 460px;
  display: flex; flex-direction: column; gap: 14px; max-height: 85vh; overflow-y: auto;
}
.modal-card h3 { margin: 0; font-size: 17px; }
.modal-card label { font-size: 13px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13.5px; z-index: 200;
}
.toast.error { background: var(--danger); }
