:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e6e9f0;
  --brand: #1e3a8a;
  --brand-2: #2563eb;
  --accent: #f97316;
  --accent-soft: #fff3e9;
  --user-bubble: #2563eb;
  --shadow: 0 6px 24px rgba(30, 41, 59, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 20px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.manager-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; text-decoration: none;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid #ffe0c7;
  transition: 0.15s;
}
.manager-btn:hover { background: #ffe9d8; }

/* ---------- Layout 3 cols ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}
.col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.col-head {
  padding: 16px 18px 10px;
  font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.col-sub { padding: 0 18px 12px; font-size: 12px; color: var(--muted); }

/* ---------- Left: categories ---------- */
.search-wrap { padding: 0 14px 10px; }
.search-wrap input {
  width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--line); font-size: 13px; background: #fbfcfe;
}
.search-wrap input:focus { outline: none; border-color: var(--brand-2); }
.cat-list { overflow-y: auto; padding: 4px 10px 14px; }
.cat-group-label {
  padding: 12px 8px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: #94a3b8; font-weight: 700;
}
.cat-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--ink); transition: 0.12s;
  border: 1px solid transparent;
}
.cat-item:hover { background: #f5f7fb; }
.cat-item.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}
.cat-item.active .cat-icon { background: rgba(255,255,255,0.18); }
.cat-icon {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 15px;
  background: #eef2fb;
}
.cat-item .chev { margin-left: auto; opacity: 0.5; font-size: 12px; }

/* ---------- Center: chat ---------- */
.chat-head {
  display: flex; align-items: center; gap: 11px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.ai-ava {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.chat-head-text { display: flex; flex-direction: column; line-height: 1.3; }
.chat-head-text strong { font-size: 14px; }
.status { font-size: 12px; color: #16a34a; }
.status.manager { color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #f1f4f9; border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.msg.manager { align-self: flex-start; background: var(--accent-soft); border: 1px solid #ffe0c7; border-bottom-left-radius: 4px; }
.msg.typing { color: var(--muted); font-style: italic; }

.quick-replies { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 6px; }
.quick-replies button {
  padding: 7px 13px; border-radius: 20px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--brand);
  transition: 0.12s;
}
.quick-replies button:hover { background: #eef2fb; border-color: var(--brand-2); }

.composer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.composer input {
  flex: 1; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--line);
  font-size: 14px; background: #fbfcfe;
}
.composer input:focus { outline: none; border-color: var(--brand-2); }
.send-btn {
  width: 46px; border: none; border-radius: 11px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 16px; transition: 0.12s;
}
.send-btn:hover { background: #ea6a09; }

/* ---------- Right: materials ---------- */
.materials { overflow-y: auto; padding: 4px 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.mat-video video { width: 100%; border-radius: 11px; display: block; background: #000; }
.mat-video .mat-title { margin-top: 6px; font-size: 13px; font-weight: 600; }
.mat-card {
  border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px;
  background: #fbfcfe;
}
.mat-card .mat-title { font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.mat-card .mat-body { margin-top: 6px; font-size: 12.5px; color: var(--muted); white-space: pre-wrap; line-height: 1.5; }
.mat-icon { font-size: 14px; }
.mat-empty { padding: 14px 16px; color: var(--muted); font-size: 13px; }
.mat-image img { width: 100%; border-radius: 11px; cursor: zoom-in; display: block; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: grid; place-items: center; z-index: 50; }
.modal.hidden, .lightbox.hidden { display: none; }
.modal-card { background: #fff; border-radius: 16px; padding: 24px; width: 380px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal-card h3 { margin: 0 0 6px; }
.modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.modal-card input[type=text], .modal-card input[type=tel] {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; margin-bottom: 10px;
}
.consent { display: flex; gap: 9px; font-size: 12px; color: var(--muted); align-items: flex-start; margin: 4px 0 6px; line-height: 1.4; }
.consent input { margin-top: 2px; }
.consent a { color: var(--brand-2); }
.contact-error { color: #dc2626; font-size: 12.5px; min-height: 16px; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.btn-primary:hover { background: #ea6a09; }
.btn-ghost { background: #fff; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; cursor: pointer; color: var(--muted); }

/* ---------- Lightbox ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  html, body { height: auto; }

  .topbar { padding: 10px 14px; gap: 8px; }
  .brand-logo { width: 32px; height: 32px; font-size: 16px; }
  .brand-name { font-size: 15px; }
  .brand-tagline { font-size: 11px; }
  .manager-btn { font-size: 12px; padding: 8px 12px; white-space: nowrap; }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    padding: 10px 10px 20px;
    gap: 10px;
    height: auto;
    min-height: 0;
  }

  /* Порядок: чат первым, потом категории, потом материалы */
  .col-center { order: 1; min-height: 480px; height: auto; }
  .col-left   { order: 2; max-height: none; height: auto; }
  .col-right  { order: 3; max-height: none; height: auto; }

  .col { overflow: visible; height: auto !important; max-height: none !important; }

  /* Категории — компактный список без ограничения высоты */
  .col-left { height: auto; }
  .cat-list { max-height: none; overflow-y: visible; height: auto; }
  .search-wrap { padding: 0 12px 8px; }

  /* Чат */
  .messages { min-height: 300px; max-height: 420px; overflow-y: auto; }
  .composer input { font-size: 16px; /* предотвращает zoom на iOS */ }

  /* Материалы */
  .materials { max-height: none; }
  .mat-card iframe, .mat-card video { max-height: 200px; }
}
