:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #7a8494;
  --line: #e3e6eb;
  --brand: #14324d;
  --accent: #1f7a8c;
  --accent-d: #17606e;
  --ok: #1a9d5a;
  --shadow: 0 1px 3px rgba(20,40,60,.08), 0 1px 2px rgba(20,40,60,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent-d); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--brand); color: #fff; padding: 12px 22px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand span { color: #8fc7d4; font-weight: 600; }
.topbar-right { color: #8fc7d4; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 22px; }
.logout-link { color: #8fc7d4; font-size: 13px; }
.logout-link:hover { color: #fff; }

/* login page */
.login-body { min-height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #14324d 0%, #1f7a8c 100%); }
.login-card { background: var(--card); border-radius: 14px; padding: 34px 30px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 340px; max-width: 92vw; }
.login-brand { font-size: 22px; font-weight: 700; color: var(--brand); text-align: center; }
.login-sub { color: var(--muted); font-size: 13.5px; text-align: center; margin-top: 4px; margin-bottom: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.login-card input { font-size: 15px; padding: 10px 12px; }
.login-card button { padding: 11px; font-size: 15px; margin-top: 4px; }
.login-error { background: #fdecec; color: #c0392b; border: 1px solid #f5c6c6;
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; text-align: center; margin-bottom: 16px; }

/* counters */
.counters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; margin-bottom: 20px; }
.counter { position: relative; display: block; background: var(--card); border-radius: 10px;
  padding: 14px; box-shadow: var(--shadow); border-left: 4px solid var(--cc, var(--line));
  color: inherit; text-decoration: none; cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.counter:hover { transform: translateY(-2px); text-decoration: none;
  box-shadow: 0 5px 16px rgba(20,40,60,.13); }
.counter.active { background: color-mix(in srgb, var(--cc) 12%, #fff);
  transform: translateY(-2px);
  box-shadow: inset 0 0 0 2px var(--cc), 0 6px 18px color-mix(in srgb, var(--cc) 28%, transparent); }
.counter.active .counter-num { color: var(--cc); }
.counter.active .counter-title { color: color-mix(in srgb, var(--cc) 65%, var(--ink)); font-weight: 600; }
.counter-num { font-size: 26px; font-weight: 700; transition: color .16s ease; }
.counter-title { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.c-total { --cc: var(--brand); }
.c-drafted { --cc: #c98a1a; }
.c-to_send { --cc: #7a5cc0; }
.c-sent { --cc: var(--accent); }
.c-replied { --cc: #2b7de0; }
.c-warm { --cc: #e0662b; }
.c-dead { --cc: #b0b7c1; }

/* actions */
.actions { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 18px; }
.action-card { background: var(--card); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.action-card h3 { margin: 0 0 10px; font-size: 15px; }
.action-card .row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.action-card input { flex: 1; min-width: 90px; }
input, select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 7px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button:hover { background: var(--accent-d); }
button:disabled { background: #b7c0c9; cursor: not-allowed; }
.btn-link { color: var(--accent-d); font-size: 13.5px; }

/* search checkboxes (вертикально) */
.checks { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.checks-title { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 7px;
  font-size: 14px; cursor: pointer; width: fit-content; transition: background .12s ease, color .12s ease; }
.check:hover { background: #eef3f4; }
.check input { flex: none; width: 17px; min-width: 0; height: 17px; margin: 0;
  accent-color: var(--accent); cursor: pointer; }
.check:has(input:checked) { background: color-mix(in srgb, var(--accent) 12%, #fff);
  color: var(--accent-d); font-weight: 600; }

/* job banner */
.job { position: relative; display: flex; gap: 12px; align-items: flex-start; background: var(--card);
  border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 18px;
  border-left: 4px solid var(--accent); }
.job-close { position: absolute; top: 8px; right: 10px; margin: 0; }
.job-close button { background: transparent; color: var(--muted); font-size: 20px; line-height: 1;
  padding: 2px 8px; font-weight: 400; }
.job-close button:hover { background: #eef1f4; color: var(--ink); }
.job-close-btn { margin-top: 10px; }
.job-ok { border-left-color: var(--ok); }
.job-err { border-left-color: #d24b4b; }
.job-log { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  color: var(--muted); white-space: pre-wrap; margin-top: 8px; max-height: 160px; overflow: auto; }
.spinner { width: 16px; height: 16px; border: 3px solid #cfe3e8; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; margin-top: 3px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* filters */
.filters { margin-bottom: 12px; }
.filters form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* selection bar */
.selbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }

/* table */
.col-check { width: 34px; text-align: center; }
.col-check input { width: auto; cursor: pointer; }
.table-wrap { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: #f7fafb; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.ok { color: var(--ok); font-weight: 700; }
.table-wrap .small { padding: 8px 14px; }

/* badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 600; }
.b-new { background: #eef1f4; color: #55606e; }
.b-drafted { background: #fbeecd; color: #8a5e10; }
.b-to_send { background: #eae2fb; color: #5b3ea8; }
.b-sent { background: #d6eef2; color: #17606e; }
.b-replied { background: #d8e8fb; color: #1b5cb0; }
.b-warm { background: #fbe0d0; color: #b0491c; }
.b-dead { background: #eceef1; color: #99a1ac; }

/* lead card */
.lead-head { display: flex; align-items: center; gap: 14px; margin: 14px 0 18px; }
.lead-head h1 { margin: 0; font-size: 23px; }
.lead-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--card); border-radius: 10px; padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 15px; }
dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; }
dt { color: var(--muted); font-size: 13.5px; }
dd { margin: 0; }
.mail-subject { margin-bottom: 10px; }
.mail-body { white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.6;
  background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin: 0; }

.status-actions { margin-top: 14px; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.status-buttons form { margin: 0; }
.badge-btn { border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 6px 14px; border-radius: 20px; font-weight: 600; }
.badge-btn.current { outline: 2px solid var(--accent); }

@media (max-width: 900px) {
  .counters { grid-template-columns: repeat(3, 1fr); }
  .actions, .lead-grid { grid-template-columns: 1fr; }
  dl { grid-template-columns: 100px 1fr; }
}
