:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2126; --muted: #6b7280; --line: #e3e6ea;
  --accent: #1f6f5f; --accent-dark: #17554a; --red: #c62828; --red-bg: #fdecea; --amber: #b7791f; --amber-bg: #fdf3e0;
  --green: #2e7d32; --green-bg: #e8f5e9; --gray-bg: #eceff1;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h1 small { font-weight: 400; font-size: 15px; }
h2 { font-size: 15px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
section.card h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, Menlo, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }
.hidden { display: none; }
.inline { display: inline; }

/* шапка */
.top { display: flex; align-items: center; gap: 18px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; color: var(--text); }
.brand span { color: var(--accent); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); }
.top nav a:hover, .top nav a.on { background: var(--gray-bg); text-decoration: none; }
.top nav a.btn-new { background: var(--accent); color: #fff; }
.top nav a.btn-new:hover { background: var(--accent-dark); }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.langs a { padding: 2px 6px; border-radius: 4px; }
.langs a.on { background: var(--gray-bg); font-weight: 600; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
button.link:hover { text-decoration: underline; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* карточки и сетки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 760px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.grid2 .span2 { grid-column: 1 / -1; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.crumbs { margin: 0 0 8px; }

/* формы */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input:not([type]), select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #cfd4da; border-radius: 6px; font: inherit; color: var(--text); background: #fff; margin-top: 3px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ccfc3; border-color: var(--accent); }
.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd4da; background: #fff; color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { background: var(--gray-bg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; margin: 0; }
.filters input[type=search] { min-width: 220px; }
.row-form { display: flex; gap: 8px; align-items: end; }
.row-form select { margin: 0; }
.comment-form { margin-top: 10px; display: flex; gap: 8px; align-items: start; }
.comment-form textarea { margin: 0; }
#status-form select, #status-form textarea { margin-bottom: 8px; }

/* сообщения */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.flash-ok { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }
.badges { display: flex; gap: 8px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 12px; background: var(--gray-bg); }
.tag.amber { background: var(--amber-bg); color: var(--amber); }
.tag.res-lead_created { background: var(--green-bg); color: var(--green); }
.tag.res-junk, .tag.res-skipped { color: var(--muted); }
.tag.res-error { background: var(--red-bg); color: var(--red); }

/* таблицы */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
tfoot th { text-transform: none; font-size: 14px; color: var(--text); }
table.stats { background: #fff; }
table.stats td, table.stats th { text-align: right; }
table.stats td:first-child, table.stats th:first-child { text-align: left; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #f7f9fa; }
tr.sla-red td:nth-child(2) { border-left: 4px solid var(--red); }
tr.sla-amber td:nth-child(2) { border-left: 4px solid var(--amber); }
tr.kind-won td { background: #f5fbf5; }
tr.kind-lost td, tr.kind-junk td { color: var(--muted); }
td.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 30px; text-align: center; }
.pager { display: flex; gap: 4px; margin: 12px 0; flex-wrap: wrap; }
.pager a { padding: 4px 9px; border-radius: 4px; border: 1px solid var(--line); background: #fff; }
.pager a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.legend { margin-top: 12px; font-size: 12px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; }
.sw.sla-red { background: var(--red); }
.sw.sla-amber { background: var(--amber); }

/* статусы и источники */
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-bg); white-space: nowrap; }
.st-novo { background: var(--red-bg); color: var(--red); }
.st-kontaktiran { background: #e3f2fd; color: #1565c0; }
.st-ponuda_poslata { background: var(--amber-bg); color: var(--amber); }
.st-dobijen { background: var(--green-bg); color: var(--green); }
.st-izgubljen { background: var(--gray-bg); color: var(--muted); }
.st-nije_upit { background: var(--gray-bg); color: var(--muted); text-decoration: line-through; }
.src { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 12px; background: #eef2f5; }
.src-spa { background: #e0f2f1; color: #00695c; }
.src-deking { background: #efebe9; color: #5d4037; }
.src-akcija { background: #fff3e0; color: #e65100; }
.src-mejl { background: #ede7f6; color: #4527a0; }
.src-poziv { background: #e8eaf6; color: #283593; }
.src-viber { background: #f3e5f5; color: #6a1b9a; }

/* карточка обращения */
.lead-head { padding: 12px 16px; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 8px; margin-bottom: 16px; }
.lead-head.sla-red { border-left-color: var(--red); }
.lead-head.sla-amber { border-left-color: var(--amber); }
.lead-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.props { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.props dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
.props dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 4px 0 10px 12px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: #b0bec5; }
.timeline li.ev-received::before { background: var(--accent); }
.timeline li.ev-status::before { background: #1565c0; }
.timeline li.ev-mail_in::before, .timeline li.ev-mail_reply::before { background: #6a1b9a; }
.timeline .when { color: var(--muted); font-size: 12px; margin-right: 8px; white-space: nowrap; }
.timeline .who { font-weight: 600; margin-right: 6px; }
.timeline .old { color: var(--muted); text-decoration: line-through; }
.ev-comment { margin-top: 4px; padding: 8px 10px; background: #f7f9fa; border-radius: 6px; }

/* плитки статистики */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; color: var(--text); }
.tile b { display: block; font-size: 24px; line-height: 1.1; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.red b { color: var(--red); }
.tile.amber b { color: var(--amber); }
a.tile:hover { text-decoration: none; border-color: var(--accent); }

/* вход */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: 100%; max-width: 360px; }
.login-box h1 { font-size: 24px; }
.login-box h1 span { color: var(--accent); }
.login-box .btn { width: 100%; margin-top: 6px; }
.login-box .langs { text-align: center; margin: 14px 0 0; }
