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

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e4ea;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #059669;
  --error-bg: #fef2f2;
  --error-text: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ─── Header ─── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.logout-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}
.logout-link:hover { color: var(--text); }

/* ─── Main ─── */
main {
  max-width: 760px;
  margin: 32px auto;
  padding: 0 16px 60px;
}

/* ─── Auth page ─── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

/* ─── Card ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ─── Fields ─── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.field-full { grid-column: 1 / -1; }

input[type="text"],
input[type="password"],
textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  width: 100%;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
textarea { resize: vertical; }
input[type="file"] {
  font-size: 13px;
  color: var(--text-muted);
}

/* ─── Radio & Checkbox ─── */
.radio-group, .checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.radio-option, .checkbox-option {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color .15s, background .15s;
  user-select: none;
}

.radio-option input, .checkbox-option input { display: none; }

.radio-option:hover, .checkbox-option:hover { border-color: var(--primary); }

.radio-option.checked,
.checkbox-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(79,70,229,.06);
  color: var(--primary);
  font-weight: 500;
}

/* ─── Divider ─── */
.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 16px 0;
  position: relative;
}
.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.client-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.client-select-row select {
  flex: 1;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--surface); color: #e53e3e; border: 1px solid #e53e3e; }
.btn-danger:hover { background: #fff5f5; }
.btn-download {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
  width: 100%;
  margin-bottom: 10px;
}
.btn-download:hover { background: rgba(79,70,229,.06); }
.btn-full { width: 100%; }

.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }

/* ─── Alert ─── */
.alert { border-radius: 7px; padding: 10px 14px; font-size: 13px; margin-bottom: 18px; }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* ─── Badge ─── */
.badge {
  font-size: 11px;
  font-weight: 400;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 20px;
}

/* ─── Result card ─── */
.result-card { text-align: center; padding: 48px 36px; }
.success-icon {
  width: 56px; height: 56px;
  background: #d1fae5;
  color: var(--success);
  border-radius: 50%;
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.result-card h2 { font-size: 22px; margin-bottom: 28px; }
.download-list { margin-bottom: 12px; }

/* ─── Utils ─── */
.mt-sm { margin-top: 10px; }
.mt-lg { margin-top: 24px; }
.field-full-row { display: contents; }

/* ─── Summary card ─── */
.summary-card { background: #f8f9ff; }
.summary-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 14px;
  margin-bottom: 12px;
}
.summary-label { color: var(--text-muted); font-weight: 500; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

@media (max-width: 540px) {
  .fields-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: 1; }
}

/* ─── assist-panel ─── */
main.wide { max-width: 1100px; }
table.leads { width:100%; border-collapse:collapse; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; }
table.leads th, table.leads td { text-align:left; padding:10px 14px; border-bottom:1px solid var(--border); font-size:14px; }
table.leads th { background:#f8f9ff; color:var(--text-muted); font-weight:600; }
table.leads tr:hover td { background:#f8f9ff; }
.filters { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:16px; align-items:end; }
.filters .field { min-width:160px; }
.filters select { border:1px solid var(--border); border-radius:7px; padding:9px 12px; font-size:14px; background:#fff; width:100%; }
.lpr-card { border:1px solid var(--border); border-radius:var(--radius); padding:16px; margin-bottom:14px; background:var(--surface); }
.lpr-card.active { border-color:var(--primary); box-shadow:0 0 0 3px rgba(79,70,229,.10); }
.lpr-card.closed { opacity:.55; }
.lpr-card h3 { font-size:15px; margin-bottom:4px; display:flex; align-items:center; gap:10px; }
.step { background:#f8f9ff; border:1px solid var(--border); border-radius:8px; padding:10px 12px; margin:8px 0; }
.step pre { white-space:pre-wrap; font-family:inherit; font-size:13px; margin-bottom:8px; }
.status-pill { font-size:12px; padding:2px 10px; border-radius:20px; background:#eef2ff; color:var(--primary); }
.funnel { display:flex; gap:16px; flex-wrap:wrap; }
.funnel .metric { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:16px 22px; min-width:130px; }
.funnel .metric b { font-size:24px; display:block; color:var(--primary); }
.toast { position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
  background:var(--text); color:#fff; padding:10px 18px; border-radius:8px; opacity:0;
  transition:opacity .2s; pointer-events:none; z-index:50; }
.toast.show { opacity:1; }
header nav { font-size:13px; }
header nav a { margin:0 2px; }

/* ─── contacts flat table (всё в один экран) ─── */
main.full { max-width: 1500px; margin: 20px auto; padding: 0 16px 50px; }
table.contacts { width: 100%; table-layout: auto; font-size: 13px; }
table.contacts th, table.contacts td { padding: 7px 9px; vertical-align: middle; }
.c-phone { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: nowrap; }
.c-msgs { white-space: nowrap; }
.c-msgs .btn { margin-right: 4px; min-width: 30px; padding: 4px 0; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.c-name { font-weight: 600; white-space: nowrap; }
select.mini { border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; font-size: 12px; background: #fff; max-width: 130px; }
.status-pill.ok { background: #d1fae5; color: var(--success); }
.reply-form { display: flex; gap: 5px; align-items: center; }
.reply-form input { padding: 5px 8px; font-size: 12px; width: 130px; }
tr.row-won td { background: #f0fdf4 !important; }
tr.row-dim td { opacity: .5; }
tr.row-dim:hover td { opacity: 1; }

/* ─── reply popover (рядом с кнопкой) + when column ─── */
.c-when { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
table.contacts { overflow: visible; }            /* чтобы поповер не обрезался */
td.reply-cell { position: relative; }
.popover { display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 40;
  width: 300px; text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 14px; }
.popover.open { display: block; }
.popover strong { display: block; font-size: 13px; margin-bottom: 8px; }
.popover textarea { width: 100%; font-size: 13px; }
.pop-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

/* ─── company grouping ─── */
tr.grp-0 td:first-child { box-shadow: inset 4px 0 0 #6366f1; }
tr.grp-1 td:first-child { box-shadow: inset 4px 0 0 #14b8a6; }
.grp-badge { font-size: 11px; color: var(--text-muted); background: #eef2ff;
  border-radius: 10px; padding: 1px 7px; margin-left: 4px; font-weight: 500; }
tr.row-next td { background: #fffbeb !important; }
.next-badge { font-size: 11px; color: #b45309; font-weight: 600; margin-left: 4px; }

/* ─── daily quota bar ─── */
.quota { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px; }
.quota-head { font-size: 14px; margin-bottom: 8px; }
.quota-head b { font-size: 16px; color: var(--primary); }
.quota-bar { height: 8px; background: #eef2ff; border-radius: 6px; overflow: hidden; }
.quota-fill { height: 100%; background: var(--primary); border-radius: 6px; transition: width .3s; }
.quota-done { border-color: var(--success); background: #f0fdf4; }
.quota-done .quota-head, .quota-done .quota-head b { color: var(--success); }
.quota-done .quota-fill { background: var(--success); }

/* ─── locked / gating ─── */
tr.row-locked td { color: var(--text-muted); background: #fafafa; }
.lock-note { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
