:root {
    --bg: #f4f5f7;
    --card: #fff;
    --line: #e3e6ea;
    --text: #1d2433;
    --muted: #8a94a6;
    --accent: #5b6ee1;
    --green: #2faa6a;
    --danger: #d9534f;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }

/* ─── Топбар ─── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; padding: 12px 20px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 50;
}
.logo { font-weight: 700; font-size: 16px; color: var(--text); }
.topbar nav a { margin-left: 18px; font-weight: 500; }
main { padding: 20px; }

/* ─── KPI ─── */
.kpi-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 14px 18px; min-width: 120px; color: var(--muted); font-size: 12px;
}
.kpi span { display: block; font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 2px; }

/* ─── Канбан ─── */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.col { flex: 0 0 250px; background: #eceef1; border-radius: 12px; display: flex; flex-direction: column; }
.col-head {
    padding: 10px 14px; font-weight: 600; font-size: 13px;
    border-bottom: 3px solid var(--accent); border-radius: 12px 12px 0 0; background: #fff;
}
.col-head b { float: right; color: var(--muted); }
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 40px; }

.card {
    display: block; background: var(--card); border: 1px solid var(--line);
    border-radius: 10px; padding: 10px 12px; color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,.04); transition: .12s;
}
.card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.10); transform: translateY(-1px); }
.card-name { font-weight: 600; margin-bottom: 6px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.card-niche { color: var(--muted); font-size: 12px; }
.card-amount { color: var(--green); font-weight: 700; margin-top: 4px; }
.card-foot { color: var(--muted); font-size: 11px; margin-top: 6px; }

.src, .tag {
    font-size: 10px; padding: 2px 7px; border-radius: 20px; font-weight: 600;
    background: #eef0f4; color: #5a6478;
}
.src-telegram { background: #e3f1fb; color: #2b87c9; }
.src-vk { background: #e6ecf7; color: #4a6ea9; }
.src-instagram { background: #fde7f1; color: #c13584; }
.src-manual { background: #eceff2; color: #6a7385; }
.tag { background: #fff3e0; color: #b9772a; }

/* Цвета этапов (левый бордер заголовка колонки) */
.col-head.stage-new { border-color: #9aa4b8; }
.col-head.stage-checklist { border-color: #5b9bd5; }
.col-head.stage-telegram { border-color: #38b6ff; }
.col-head.stage-audit_booked { border-color: #f0a500; }
.col-head.stage-audit_done { border-color: #d98b00; }
.col-head.stage-sale { border-color: #2faa6a; }
.col-head.stage-lost { border-color: #d9534f; }

/* ─── Карточка лида ─── */
.back { display: inline-block; margin-bottom: 12px; }
.lead-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; align-items: start; }
.lead-main, .lead-timeline { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.lead-main h1 { margin: 0 0 10px; font-size: 22px; }
.lead-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.stage-pill { font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; background: #eef0f4; }
.stage-pill.stage-sale { background: #e3f7ec; color: var(--green); }
.stage-pill.stage-lost { background: #fbe7e6; color: var(--danger); }

.inline-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.inline-form select, .inline-form input { flex: 1; min-width: 90px; }
.sale-form { padding: 12px; background: #f6fbf8; border-radius: 10px; }

.props { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 16px 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }

.edit-block { margin: 12px 0; }
.edit-block summary { cursor: pointer; color: var(--accent); }

/* Таймлайн */
.lead-timeline h2 { margin-top: 0; font-size: 16px; }
.note-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.ev { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); position: relative; }
.ev::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.ev-payment::before { background: var(--green); }
.ev-stage_change::before { background: #f0a500; }
.ev-time { font-size: 11px; color: var(--muted); }
.ev-body { margin-top: 2px; }

/* ─── Формы / кнопки ─── */
label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
input, select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 14px; font-family: inherit; background: #fff; margin-top: 3px;
}
button {
    background: var(--accent); color: #fff; border: 0; border-radius: 8px;
    padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button.green { background: var(--green); }
button.danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); margin-top: 14px; }

/* ─── Аналитика ─── */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.panel h2 { margin-top: 0; font-size: 16px; }
.funnel-row { display: grid; grid-template-columns: 160px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 8px; }
.funnel-label { font-size: 13px; }
.funnel-bar-wrap { background: #eceef1; border-radius: 6px; height: 22px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--accent); border-radius: 6px; min-width: 4px; }
.funnel-bar.stage-sale { background: var(--green); }
.funnel-bar.stage-lost { background: var(--danger); }
.funnel-count { text-align: right; font-weight: 600; }

/* ─── Логин ─── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; padding: 32px; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.10); width: 300px; }
.login-box h1 { font-size: 20px; margin: 0 0 18px; text-align: center; }
.login-box button { width: 100%; margin-top: 10px; }
.err { background: #fbe7e6; color: var(--danger); padding: 8px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

/* ─── Модалка ─── */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; align-items: flex-start; justify-content: center; padding-top: 60px; }
.modal.show { display: flex; }
.modal-box { background: #fff; border-radius: 14px; padding: 22px; width: 360px; max-height: 85vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; margin-bottom: 14px; }
.modal-head .x { cursor: pointer; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-box button { width: 100%; margin-top: 6px; }

@media (max-width: 800px) {
    .lead-grid, .analytics-grid { grid-template-columns: 1fr; }
}
