* { box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e0e2e7;
  --text: #1f2430;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bitrix: #f97316;
  --bitrix-hover: #ea580c;
  --success: #16a34a;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}
.brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.brand:hover { text-decoration: none; color: var(--accent); }

.user-info {
  float: right;
  font-size: 13px;
  color: var(--text-muted);
}

/* --- login page --- */

.login-box {
  max-width: 420px;
  margin: 60px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
}
.login-box h1 { font-size: 20px; margin: 0 0 8px; }
.login-box p { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }

.login-portals { display: flex; flex-direction: column; gap: 10px; }
.login-portal-btn {
  display: block;
  background: var(--bitrix);
  color: #fff;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
}
.login-portal-btn:hover { background: var(--bitrix-hover); text-decoration: none; }

/* --- nav / impersonation --- */

.main-nav {
  display: inline-flex;
  gap: 16px;
  margin-left: 24px;
  font-size: 13px;
}
.main-nav a { color: var(--text-muted); }
.main-nav a:hover { color: var(--accent); text-decoration: none; }

.impersonation-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 8px 24px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.inline-form { display: inline; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: #92400e;
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
}

/* --- pool: claim buttons --- */

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.claim-random-row { display: flex; gap: 8px; }
.btn-claim-random { width: auto; padding: 8px 14px; font-size: 13px; }

.card-body form { margin-top: 8px; }
.card-body .btn-bitrix { width: 100%; }

/* --- CRM kanban --- */

.kanban-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.kanban-header h1 { font-size: 20px; margin: 0; }
.view-toggle { font-size: 14px; }

.kanban-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.kanban-column {
  background: #eceef1;
  border-radius: 10px;
  padding: 10px;
  min-width: 220px;
}
.kanban-column-header {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kanban-count {
  background: var(--surface);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text-muted);
}

.kanban-column-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
  border-radius: 8px;
  transition: background 0.15s;
}
.kanban-column-body.drag-over { background: #dbeafe; }

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card-title { display: block; font-weight: 600; font-size: 13px; color: var(--text); }
.kanban-card-title:hover { color: var(--accent); }
.kanban-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.kanban-card-link { font-size: 11px; color: var(--success); margin-top: 4px; word-break: break-all; }

@media (max-width: 1100px) {
  .kanban-board { grid-template-columns: 1fr; }
}

/* --- CRM list view --- */

.crm-list-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.crm-list-table th, .crm-list-table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
.crm-list-table th { background: #f9fafb; color: var(--text-muted); font-weight: 600; }
.crm-list-table tr:last-child td { border-bottom: none; }
.crm-status-select { padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }

/* --- CRM lead detail panel --- */

.crm-panel { background: #f9fafb; border-radius: 8px; padding: 16px; }
.crm-status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.crm-webinar-info { font-size: 13px; color: var(--success); margin-bottom: 10px; word-break: break-all; }

.crm-comments { margin-top: 18px; }
.crm-comments h3 { font-size: 14px; margin: 0 0 8px; }
.comment-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.comment-form textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.comment-form button { width: fit-content; }
.comment-item { padding: 8px 0; border-top: 1px solid var(--border); }
.comment-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.comment-text { font-size: 13px; white-space: pre-line; }

.crm-history { margin-top: 18px; }
.crm-history h3 { font-size: 14px; margin: 0 0 8px; }
.history-item { font-size: 12px; color: var(--text-muted); padding: 4px 0; }
.history-date { float: right; }

/* --- modal --- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: 10px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
}
.modal-box h3 { margin: 0 0 14px; font-size: 16px; }
.modal-box label { display: block; font-size: 12px; font-weight: 600; margin: 10px 0 4px; }
.modal-box select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions button { width: auto; padding: 8px 16px; }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.filters {
  flex: 0 0 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.filter-group {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.filter-group:last-of-type { border-bottom: none; }

.filter-group > label:first-child {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
}

.filter-group input[type="text"],
.filter-group input[type="number"],
.filter-group input[type="date"],
.filter-group select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

.range-row {
  display: flex;
  gap: 8px;
}
.range-row input { width: 50%; }

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  margin-bottom: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.checkbox-line input { margin: 0; }

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-apply {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-apply:hover { background: var(--accent-hover); }

.btn-reset {
  display: block;
  text-align: center;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.results { flex: 1 1 auto; min-width: 0; }

.results-header {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

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

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-photo {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: #eceef1;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.card-title:hover { color: var(--accent); }

.card-position { font-size: 13px; color: var(--text-muted); }
.card-meta { font-size: 12px; color: var(--text-muted); }
.card-updated { font-size: 11px; color: #9ca3af; }

.phone-copy {
  font-weight: 700;
  font-size: 14px;
  color: var(--success);
  cursor: pointer;
  padding: 6px 8px;
  border: 1px dashed var(--success);
  border-radius: 6px;
  text-align: center;
  user-select: none;
}
.phone-copy:hover { background: #f0fdf4; }
.phone-copy.copied { background: var(--success); color: #fff; border-style: solid; }

.phone-copy-big { font-size: 20px; padding: 12px 16px; margin-bottom: 10px; }

.copyable { cursor: pointer; border-bottom: 1px dashed var(--text-muted); }
.copyable.copied { color: var(--success); border-color: var(--success); }

.btn-bitrix {
  background: var(--bitrix);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-bitrix:hover { background: var(--bitrix-hover); }
.btn-bitrix-big { padding: 10px 16px; font-size: 14px; margin-top: 6px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 28px;
  font-size: 14px;
}
.page-info { color: var(--text-muted); }

/* --- detail page --- */

.back-link { display: inline-block; margin-bottom: 16px; font-size: 14px; }

.detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  max-width: 820px;
}

.detail-header {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.detail-photo {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  background: #eceef1;
  flex-shrink: 0;
}

.detail h1 { margin: 0 0 4px; font-size: 22px; }
.detail-position { font-size: 15px; color: var(--text-muted); margin-bottom: 6px; }
.detail-meta { font-size: 13px; color: var(--text-muted); }
.detail-updated { font-size: 12px; color: #9ca3af; margin-top: 4px; }

.contacts-block {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.contact-line { font-size: 14px; margin-bottom: 4px; }
.contact-type { color: var(--text-muted); text-transform: capitalize; margin-right: 6px; }

.section { padding: 18px 0; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: none; }
.section h2 { font-size: 15px; margin: 0 0 10px; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv-table td { padding: 5px 0; vertical-align: top; }
.kv-table td:first-child { color: var(--text-muted); width: 220px; white-space: nowrap; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: #eef2ff;
  color: #3730a3;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
}

.exp-item, .edu-item { margin-bottom: 12px; font-size: 14px; }
.exp-dates { font-weight: 600; }
.exp-org { color: var(--text-muted); }
.exp-position { font-weight: 600; margin-top: 2px; }
.exp-resp { color: var(--text-muted); margin-top: 2px; white-space: pre-line; }

.edu-item { display: flex; gap: 8px; }
.edu-year { font-weight: 600; }
.edu-org { color: var(--text); }
.edu-spec { color: var(--text-muted); }

.about-text { white-space: pre-line; font-size: 14px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .filters { position: static; max-height: none; width: 100%; flex-basis: auto; }
  .detail-header { flex-direction: column; align-items: center; text-align: center; }
}
