/* FreeWater CRM — единый стиль. Палитра и базовые компоненты повторяют
   admin.css админки, чтобы два контура выглядели как одна система. */
:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #16242f;
  --muted: #6b7c8f;
  --line: #e3e9f0;
  --accent: #0aa5c4;
  --accent-ink: #057a92;
  --green: #22c55e;
  --yellow: #f5b50a;
  --red: #ef4444;
  --violet: #7c5cff;
  --shadow: 0 1px 2px rgba(16,40,60,.06), 0 6px 20px rgba(16,40,60,.06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }

/* ---------- каркас ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead .sub { color: var(--muted); font-size: 13.5px; }
.pagehead .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.cards-4 { grid-template-columns: repeat(4, 1fr); }
.cards-3 { grid-template-columns: repeat(3, 1fr); }
.cards-2 { grid-template-columns: 1fr 1fr; }
.col-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .cards-4 { grid-template-columns: 1fr 1fr; } .col-2-1 { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .cards-4, .cards-3, .cards-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card h3 { margin: 0 0 6px; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; }
.card .v { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.card .hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 2px 12px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 26px; text-align: center; font-size: 14px; }
.loading { color: var(--muted); padding: 34px; text-align: center; }

/* ---------- кнопки и поля ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; line-height: 1.2;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--red); border-color: rgba(239,68,68,.35); }
.btn.danger:hover { background: rgba(239,68,68,.08); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--ink); font-family: inherit; width: 100%;
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,165,196,.12);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .field { min-width: 150px; }
.toolbar input.search { min-width: 220px; }

/* ---------- таблицы ---------- */
.table-scroll { overflow-x: auto; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl thead th {
  text-align: left; padding: 11px 12px; border-bottom: 2px solid var(--line);
  font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; background: var(--card); position: sticky; top: 0;
}
table.tbl tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: rgba(10,165,196,.05); }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl td.num, table.tbl th.num { text-align: right; white-space: nowrap; }
table.tbl td.dim { color: var(--muted); }
table.tbl td .who { font-size: 12px; color: var(--muted); }

/* ---------- бейджи ---------- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; white-space: nowrap; background: var(--bg); color: var(--muted); }
.badge.green { color: #0a7f3f; background: rgba(34,197,94,.14); }
.badge.blue { color: var(--accent-ink); background: rgba(10,165,196,.14); }
.badge.yellow { color: #9a6b00; background: rgba(245,181,10,.16); }
.badge.red { color: #b42318; background: rgba(239,68,68,.12); }
.badge.violet { color: #4c31c4; background: rgba(124,92,255,.14); }
.badge.gray { color: var(--muted); background: var(--bg); }
.dot-live { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); margin-right: 5px; vertical-align: middle; }

/* ---------- канбан ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol { flex: 0 0 258px; background: rgba(255,255,255,.6); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; min-height: 140px; }
.kcol.drag-over { border-color: var(--accent); background: rgba(10,165,196,.07); }
.kcol .khead { display: flex; align-items: baseline; gap: 8px; padding: 2px 4px 10px; }
.kcol .khead .t { font-weight: 700; font-size: 13px; }
.kcol .khead .n { font-size: 12px; color: var(--muted); }
.kcol .khead .sum { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent-ink); }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 9px; box-shadow: 0 1px 2px rgba(16,40,60,.05); cursor: grab; }
.kcard:hover { border-color: var(--accent); }
.kcard.dragging { opacity: .45; }
.kcard .t { font-weight: 650; font-size: 13.5px; margin-bottom: 4px; }
.kcard .c { font-size: 12.5px; color: var(--muted); }
.kcard .m { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.kcard .m .amt { font-weight: 700; }

/* ---------- модалка ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(12,24,34,.45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 18px; box-shadow: 0 24px 60px rgba(10,25,40,.3);
  width: 100%; max-width: 620px; padding: 22px 24px 20px; }
.modal.wide { max-width: 900px; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; gap: 9px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }
.modal .actions .spacer { flex: 1; }
.modal .err { color: var(--red); font-size: 13px; font-weight: 600; min-height: 16px; margin-top: 8px; }

/* ---------- карточка клиента ---------- */
.tabs { display: flex; gap: 6px; margin: 0 0 16px; flex-wrap: wrap; }
.tab { padding: 8px 15px; border-radius: 10px; font-weight: 600; font-size: 13.5px; cursor: pointer;
  color: var(--muted); background: var(--card); border: 1px solid var(--line); font-family: inherit; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab:disabled { opacity: .45; cursor: not-allowed; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.deflist { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: 13.5px; }
.deflist dt { color: var(--muted); font-weight: 600; }
.deflist dd { margin: 0; }
@media (max-width: 640px) { .deflist { grid-template-columns: 1fr; gap: 2px 0; } .deflist dd { margin-bottom: 8px; } }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(10,165,196,.14); }
.timeline li.sys::before { background: var(--muted); box-shadow: 0 0 0 3px rgba(107,124,143,.14); }
.timeline .tl-head { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.timeline .tl-text { font-size: 13.5px; white-space: pre-wrap; }

.mini-list { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list li .spacer { flex: 1; }
.mini-list li.done .t { text-decoration: line-through; color: var(--muted); }

/* строка воронки на дашборде: на узком экране переносим сумму на вторую строку,
   чтобы карточка не уезжала горизонтально */
.funlabel { min-width: 150px; }
.funbar { flex: 1; height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; min-width: 60px; }
.funn { min-width: 34px; text-align: right; }
.funsum { min-width: 96px; text-align: right; }
@media (max-width: 560px) {
  .funrow { flex-wrap: wrap; }
  .funlabel { min-width: 0; flex: 1 0 100%; }
  .funsum { min-width: 0; }
}

.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkline input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- переписка ---------- */
.chatlayout { display: grid; grid-template-columns: 330px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .chatlayout { grid-template-columns: 1fr; } }
.chatlist { padding: 8px; max-height: 74vh; overflow-y: auto; }
.chatitem { padding: 11px 12px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; }
.chatitem:hover { background: var(--bg); }
.chatitem.active { background: rgba(10,165,196,.09); border-color: rgba(10,165,196,.35); }
.chatitem + .chatitem { margin-top: 2px; }
.ci-top { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.ci-top .spacer { flex: 1; }
.ci-top .muted { font-size: 11.5px; }
.ci-last { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.ci-meta { font-size: 11.5px; color: #9fb0c0; margin-top: 3px; }

.chatpane { display: flex; flex-direction: column; min-height: 420px; max-height: 74vh; }
.chathead { display: flex; align-items: center; gap: 10px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.chathead .spacer { flex: 1; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; }
.msg .mtext { white-space: pre-wrap; word-break: break-word; }
.msg .mmeta { font-size: 11px; margin-top: 5px; opacity: .65; }
.msg.in { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: rgba(10,165,196,.13); border-bottom-right-radius: 5px; }
.msg.email { align-self: flex-end; background: rgba(124,92,255,.12); }
.msg.failed { background: rgba(239,68,68,.12); }
.sendbox { display: flex; gap: 10px; align-items: flex-end; margin-top: 12px;
  border-top: 1px solid var(--line); padding-top: 12px; }
.sendbox textarea { flex: 1; min-height: 62px; resize: vertical; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 14px; }
.sendbox textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10,165,196,.12); }

.chan-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; min-width: 120px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 390px; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px; }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn.primary { width: 100%; padding: 12px; font-size: 15px; justify-content: center; }
.login-logo { font-weight: 800; font-size: 18px; letter-spacing: .02em; }
.login-logo span { color: var(--accent); }
.error { color: var(--red); font-size: 13px; font-weight: 600; margin: 0 0 12px; min-height: 16px; }

/* ---------- тост ---------- */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #16242f; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 13.5px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: all .18s ease; z-index: 200; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: #b42318; }
