/* Clean Engine CRM v0.5 — дизайн-система: нейтральная основа, один акцент, смысловые цвета только для статусов */
:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1f2329; --muted: #5f6873; --faint: #9aa3ae; --line: #e3e6eb; --line2: #eef0f3;
  --accent: #0b7a75; --accent-2: #e6f2f1; --accent-ink: #fff;
  --red: #d93f3f; --red-bg: #fdecec; --green: #1f9d55; --green-bg: #e7f6ee; --amber: #c98a00; --amber-bg: #fff5dc; --grey: #9aa3ae; --blue: #2f6feb;
  --nav: #16212b; --nav-ink: #c9d2dc;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --r: 8px;
  font-family: "Golos Text", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.4; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.num, .money { font-variant-numeric: tabular-nums; } .num { text-align: right; }
.error { color: var(--red); min-height: 1em; }
.grow { flex: 1; } .nowrap { white-space: nowrap; }
a { color: var(--accent); }
h2 { font-size: 18px; margin: 0; } h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code { background: var(--line2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
kbd { font: 11px/1 inherit; border: 1px solid #40505e; border-bottom-width: 2px; border-radius: 4px; padding: 2px 4px; color: var(--nav-ink); }

/* элементы управления */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: var(--r); cursor: pointer; font: inherit; white-space: nowrap; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: #cfd5dc; background: #fafbfc; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); } .btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; } .btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.danger { color: var(--red); } .btn.won { background: var(--green); border-color: var(--green); color: #fff; } .btn.lost { color: var(--red); border-color: #f1c6c6; }
.btn.small { padding: 4px 9px; font-size: 12px; } .btn:disabled { opacity: .5; cursor: default; }
.icon { border: 0; background: transparent; cursor: pointer; font-size: 15px; line-height: 1; padding: 5px 7px; border-radius: 6px; color: var(--muted); }
.icon:hover { background: rgba(0,0,0,.06); color: var(--ink); }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; color: var(--ink); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,122,117,.25); border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; }
.switch input { width: auto; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .full { grid-column: 1 / -1; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--line2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--green-bg); color: var(--green); } .badge.warn { background: var(--amber-bg); color: var(--amber); } .badge.danger { background: var(--red-bg); color: var(--red); }
.seg { display: inline-flex; background: var(--line2); border-radius: var(--r); padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; color: var(--ink); display: inline-flex; gap: 6px; align-items: center; }
.chip b { font-variant-numeric: tabular-nums; } .chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.red b { color: var(--red); } .chip.green b { color: var(--green); } .chip.amber b { color: var(--amber); } .chip.on b { color: #fff; }
.panel { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 14px 16px; }
.section-gap { margin-bottom: 14px; }
.notice { background: var(--amber-bg); border-radius: var(--r); padding: 10px 12px; margin: 8px 0; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow-lg); width: min(360px, 100%); display: grid; gap: 14px; }
.login-brand { display: flex; gap: 10px; align-items: center; } .login-brand small { display: block; color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: 0 0 auto; }

/* каркас */
.app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
.nav { background: var(--nav); color: var(--nav-ink); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; font-weight: 600; padding: 0 6px 12px; } .brand small { display: block; color: #7d8b98; font-weight: 400; font-size: 11px; }
.nav-search { display: flex; justify-content: space-between; align-items: center; background: #223140; border: 0; color: #9fb0c0; border-radius: var(--r); padding: 7px 10px; margin-bottom: 8px; cursor: pointer; font: inherit; font-size: 13px; }
.nav-item { text-align: left; background: transparent; border: 0; color: var(--nav-ink); padding: 8px 10px; border-radius: var(--r); cursor: pointer; font: inherit; display: flex; justify-content: space-between; align-items: center; }
.nav-item:hover { background: #1f2d3a; } .nav-item.active { background: var(--accent); color: #fff; }
.nav-badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-variant-numeric: tabular-nums; }
.nav-foot { margin-top: auto; display: grid; gap: 6px; padding: 10px 6px 0; border-top: 1px solid #263544; font-size: 12px; }
.nav-foot .btn.ghost { color: var(--nav-ink); } .nav-foot .btn.ghost:hover { background: #1f2d3a; }
.me { color: #fff; } .me small { display: block; color: #7d8b98; }
.main { overflow: auto; padding: 14px 18px 40px; min-width: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { width: 220px; } .toolbar select { width: auto; }
.pipe-switch { display: flex; align-items: center; gap: 2px; }
.pipeline-select { font-weight: 600; font-size: 15px; border: 0; background: transparent; padding: 4px 6px; max-width: 340px; cursor: pointer; }
.quickbar { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.totals { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; } .totals b { color: var(--ink); }

/* доска */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; min-height: 60vh; }
.col { background: #eceff3; border-radius: 10px; width: 272px; flex: 0 0 auto; display: flex; flex-direction: column; max-height: calc(100vh - 150px); border-top: 3px solid var(--stage, transparent); }
.col.won { background: #e9f4ee; } .col.lost { background: #f7ecec; }
.col header { padding: 9px 10px 2px 12px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-weight: 600; }
.col header[draggable="true"] { cursor: grab; }
.col-title { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.col-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-count { color: var(--muted); font-weight: 400; font-size: 12px; }
.col-tools { display: flex; gap: 0; opacity: .5; } .col:hover .col-tools { opacity: 1; }
.col-sum { padding: 0 12px 8px; font-size: 12px; color: var(--muted); min-height: 16px; font-variant-numeric: tabular-nums; }
.col-input { padding: 3px 6px; font-weight: 600; }
.col .cards { padding: 0 8px 10px; overflow-y: auto; min-height: 50px; display: grid; gap: 8px; align-content: start; }
.col.drop .cards { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 8px; }
.col.col-dragging { opacity: .4; } .col.col-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.add-col { background: transparent; border: 2px dashed #d7dce2; width: 200px; padding: 10px; border-top-width: 2px; }
.col-add-form { display: grid; gap: 6px; }
.card { background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); padding: 9px 10px; cursor: pointer; display: grid; gap: 4px; border-left: 3px solid transparent; position: relative; }
.card:hover { box-shadow: 0 3px 10px rgba(16,24,40,.12); }
.card.dragging { opacity: .45; } .card.rot { border-left-color: var(--red); }
.card .t { font-weight: 600; padding-right: 18px; } .card .sub { font-size: 12px; color: var(--muted); }
.card .meta { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); align-items: center; }
.card .amt { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.card .id { position: absolute; top: 8px; right: 9px; font-size: 11px; color: var(--faint); }
.avatar { width: 20px; height: 20px; border-radius: 50%; background: #dfe7ee; color: #435363; display: inline-grid; place-items: center; font-size: 10px; font-weight: 600; flex: 0 0 auto; }
.avatar.none { background: var(--amber-bg); color: var(--amber); }
.act { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; white-space: nowrap; }
.act::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--grey); }
.act.overdue { color: var(--red); } .act.overdue::before { background: var(--red); }
.act.today { color: var(--green); } .act.today::before { background: var(--green); }
.act.none { color: var(--amber); } .act.none::before { background: var(--amber); }
.act.future { color: var(--muted); }
.rotbadge { font-size: 11px; color: var(--red); background: var(--red-bg); border-radius: 999px; padding: 0 6px; }
.src { padding: 1px 6px; border-radius: 6px; background: var(--line2); font-size: 11px; }
.src-avito { background: #e6f4ea; color: #146c2e; } .src-site { background: #e8f0fe; color: #1a4fb4; }
.src-direct { background: #fff4e0; color: #8a5300; } .src-phone { background: #f3e8fd; color: #6a1b9a; }
.quick-form { cursor: default; gap: 6px; }
.drop-marker { height: 3px; background: var(--accent); border-radius: 2px; }
.dropzones { position: fixed; left: 210px; right: 0; bottom: 0; display: flex; gap: 10px; padding: 12px 18px; background: rgba(245,246,248,.94); box-shadow: 0 -6px 20px rgba(16,24,40,.12); z-index: 40; }
.dz { flex: 1; text-align: center; padding: 16px; border: 2px dashed; border-radius: 10px; font-weight: 600; }
.dz.won { color: var(--green); border-color: #9fd8b6; background: var(--green-bg); }
.dz.lost { color: var(--red); border-color: #f0b4b4; background: var(--red-bg); }
.dz.del { color: var(--muted); border-color: #cfd5dc; background: #fff; }
.dz.hover { filter: brightness(.94); transform: scale(1.01); }

/* список сделок */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line2); font-size: 13px; vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; background: #fafbfc; white-space: nowrap; }
.table th.sortable { cursor: pointer; } .table th.sorted::after { content: " ↓"; } .table th.sorted.asc::after { content: " ↑"; }
.table tbody tr:hover { background: #fafbfc; } .table tbody tr[data-id], .table tbody tr[data-deal] { cursor: pointer; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.table td.num, .table th.num { text-align: right; }

/* карточка сделки */
.drawer { position: fixed; inset: 0; background: rgba(15,23,32,.35); z-index: 50; display: flex; justify-content: flex-end; }
.drawer-body { background: var(--bg); width: min(1080px, 96vw); height: 100%; overflow-y: auto; box-shadow: var(--shadow-lg); }
.dh { background: var(--panel); padding: 14px 18px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.dh-top { display: flex; gap: 10px; align-items: flex-start; }
.dh-title { font-size: 18px; font-weight: 600; border: 1px solid transparent; padding: 3px 6px; margin-left: -7px; }
.dh-title:hover { border-color: var(--line); } .dh-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stagebar { display: flex; gap: 3px; margin-top: 12px; }
.stagebar button { flex: 1; border: 0; background: var(--line2); color: var(--muted); font: inherit; font-size: 11px; padding: 6px 4px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stagebar button:first-child { border-radius: 6px 0 0 6px; } .stagebar button:last-child { border-radius: 0 6px 6px 0; }
.stagebar button.past { background: #b9dcd9; color: #0d4f4b; } .stagebar button.cur { background: var(--accent); color: #fff; font-weight: 600; }
.stagebar button:hover:not(.cur) { filter: brightness(.95); }
.closed-banner { margin-top: 10px; padding: 8px 12px; border-radius: var(--r); display: flex; gap: 10px; align-items: center; }
.closed-banner.won { background: var(--green-bg); color: var(--green); } .closed-banner.lost { background: var(--red-bg); color: var(--red); }
.dgrid { display: grid; grid-template-columns: 380px 1fr; gap: 14px; padding: 14px 18px 40px; align-items: start; }
.fields { display: grid; gap: 2px; }
.fld { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: center; min-height: 32px; }
.fld > span { color: var(--muted); font-size: 12px; }
.fld input, .fld select { border-color: transparent; background: transparent; padding: 5px 7px; }
.fld input:hover, .fld select:hover { border-color: var(--line); background: #fff; }
.fld input:focus, .fld select:focus { background: #fff; }
.fld.req > span::after { content: " *"; color: var(--red); }
.saved-dot { font-size: 11px; color: var(--green); opacity: 0; transition: opacity .3s; } .saved-dot.show { opacity: 1; }
.contact-actions { display: flex; gap: 6px; margin-top: 4px; }
.items input, .items select { width: 100%; min-width: 50px; padding: 5px 6px; }
.items td:first-child { min-width: 160px; }
.composer { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; display: grid; gap: 8px; }
.composer .presets { display: flex; gap: 4px; flex-wrap: wrap; }
.plan { display: grid; gap: 6px; }
.planned { display: flex; gap: 8px; align-items: center; background: #fffbea; border: 1px solid #f3e3a5; border-radius: var(--r); padding: 7px 10px; }
.planned.overdue { background: var(--red-bg); border-color: #f1c6c6; }
.planned input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.planned .w { flex: 1; min-width: 0; } .planned .d { font-size: 12px; color: var(--muted); }
.nudge { background: var(--amber-bg); color: #7a5600; border-radius: var(--r); padding: 8px 10px; font-size: 13px; }
.timeline { display: grid; gap: 8px; }
.ev { background: var(--panel); border-radius: var(--r); padding: 8px 11px; box-shadow: var(--shadow); font-size: 13px; }
.ev .h { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 3px; gap: 8px; }
.ev.sys { background: transparent; box-shadow: none; padding: 2px 11px; color: var(--muted); font-size: 12px; }
.ev.sys .h { display: none; }
.ev.note { border-left: 3px solid var(--blue); } .ev.lead { border-left: 3px solid var(--green); } .ev.done { border-left: 3px solid var(--grey); }
.transcript { white-space: pre-wrap; font-size: 12px; max-height: 260px; overflow: auto; background: var(--line2); padding: 8px; border-radius: 6px; }
.pre { white-space: pre-wrap; max-width: 520px; }

/* модальные окна, поиск, тосты, меню */
.modal { position: fixed; inset: 0; background: rgba(15,23,32,.4); display: grid; place-items: center; z-index: 70; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 12px; padding: 18px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; display: grid; gap: 12px; box-shadow: var(--shadow-lg); }
.modal-card h3 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.search-card { background: var(--panel); border-radius: 12px; width: min(620px, 100%); box-shadow: var(--shadow-lg); align-self: start; margin-top: 10vh; overflow: hidden; }
.search-card input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 16px; font-size: 16px; }
#search-res { max-height: 60vh; overflow-y: auto; }
.sr-group { padding: 8px 16px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sr { padding: 8px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.sr.sel, .sr:hover { background: var(--accent-2); } .sr small { color: var(--muted); }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 90; }
.toast { background: #1f2a35; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); display: flex; gap: 14px; align-items: center; font-size: 13px; }
.toast.err { background: var(--red); } .toast button { background: transparent; border: 0; color: #8ee0d8; font: inherit; font-weight: 600; cursor: pointer; }
.popover { position: absolute; z-index: 60; background: var(--panel); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; width: 230px; display: grid; gap: 2px; }
.popover button { text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; cursor: pointer; font: inherit; color: var(--ink); }
.popover button:hover:not(:disabled) { background: var(--line2); } .popover button:disabled { opacity: .4; cursor: default; }
.popover button.on { font-weight: 600; } .popover .danger { color: var(--red); }
.pop-label { font-size: 11px; color: var(--muted); padding: 6px 8px 2px; text-transform: uppercase; letter-spacing: .03em; }
.pop-row { display: flex; } .pop-row button { flex: 1; text-align: center; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 8px 6px; }
.popover .sw { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
.popover .sw.on { border-color: var(--ink); }

/* аналитика */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; } .tile span { color: var(--muted); font-size: 12px; }
.cards2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 70px; gap: 8px; align-items: center; font-size: 13px; margin: 4px 0; }
.bar { height: 16px; background: var(--line2); border-radius: 4px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.red i { background: var(--red); }

/* интеграции и настройки */
.integr { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-bottom: 10px; }
.integr .item { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; display: grid; gap: 4px; align-content: start; justify-items: start; }
.integr .item > b, .integr .item > div, .integr .item > span:not(.badge) { justify-self: stretch; }
.endpoint { display: flex; gap: 8px; margin: 3px 0; } .endpoint span { width: 110px; color: var(--muted); }
.row.pl { gap: 6px; align-items: center; padding: 3px 4px; border-radius: 6px; } .row.pl.sel { background: var(--accent-2); }
code.big { font-size: 18px; padding: 6px 10px; display: inline-block; user-select: all; }
.req-list { display: flex; flex-wrap: wrap; gap: 4px 12px; } .req-list label { display: flex; flex-direction: row; gap: 4px; align-items: center; color: var(--ink); }
.req-list input { width: auto; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; } .nav { flex-direction: row; overflow-x: auto; padding: 8px; } .nav-foot, .brand, .nav-search { display: none; }
  .dgrid { grid-template-columns: 1fr; } .cards2 { grid-template-columns: 1fr; } .dropzones { left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
