:root {
  --side: #0f2a44; --side-2: #163a5c; --side-ico: #b9c8d8;
  --accent: #1bb894; --accent-d: #149a7b; --accent-soft: #e3f6f1;
  --bg: #e9eef3; --card: #ffffff; --card-2: #f6f8fa; --line: #e3e8ee;
  --text: #1f2d3d; --muted: #6b7a8a; --link: #1a73c8;
  --danger: #e04a5a; --warn: #f2952f; --note: #fff4e3;
  --shadow: 0 1px 3px rgba(15, 42, 68, .08), 0 4px 14px rgba(15, 42, 68, .05);
  --radius: 10px;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text);
}
[data-theme="dark"] {
  --side: #0b1520; --side-2: #15263a; --side-ico: #93a6ba;
  --accent: #23c49c; --accent-d: #1ca784; --accent-soft: #143a33;
  --bg: #121b25; --card: #1b2734; --card-2: #223142; --line: #2c3d50;
  --text: #e3eaf2; --muted: #93a3b4; --link: #6fb2f2; --note: #3a3220;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
[data-theme="ocean"] {
  --side: #12355b; --side-2: #1b4a7a; --accent: #2a8fd8; --accent-d: #1f74b3; --accent-soft: #e2f0fb;
  --bg: #e6eef6; --link: #1f6fb3;
}
[data-theme="sand"] {
  --side: #3b2f2a; --side-2: #54443c; --side-ico: #d8c8bb; --accent: #c9773a; --accent-d: #a9612c; --accent-soft: #f8eadf;
  --bg: #f1ebe4; --card-2: #faf6f2; --line: #e8dfd6; --link: #a65a22;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- вхід ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(135deg, var(--side) 0%, var(--side-2) 55%, var(--accent-d) 140%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card .logo { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-card .logo img { width: 40px; height: 40px; }
.login-card p { margin: 0 0 22px; }

/* ---------- каркас ---------- */
.shell { display: flex; height: 100vh; }
.sidebar { width: 64px; flex: none; background: var(--side); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 6px; z-index: 5; }
.sidebar .brand { width: 40px; height: 40px; margin-bottom: 12px; }
.nav-btn { position: relative; width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: var(--side-ico); display: grid; place-items: center; cursor: pointer; }
.nav-btn:hover { background: var(--side-2); color: #fff; }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn .tip { position: absolute; left: 54px; white-space: nowrap; background: #102235; color: #fff; padding: 5px 9px; border-radius: 6px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .12s; }
.nav-btn:hover .tip { opacity: 1; }
.nav-btn .badge { position: absolute; top: 3px; right: 3px; }
.sidebar .spacer { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg) center/cover no-repeat fixed; }
.main.has-bg { background-image: url("/background"); }
.topbar { height: 56px; flex: none; background: var(--card); display: flex; align-items: center; gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; font-weight: 500; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .grow { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.round-add { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.round-add:hover { background: var(--accent-d); }
.icon-btn { position: relative; width: 36px; height: 36px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--card-2); }
.icon-btn svg { width: 20px; height: 20px; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 10px; min-width: 17px; height: 17px; padding: 0 4px; display: grid; place-items: center; font-weight: 600; }
.icon-btn .badge { position: absolute; top: -2px; right: -4px; }
.content { flex: 1; overflow: auto; padding: 14px; }

.search { display: flex; align-items: center; gap: 8px; background: var(--card-2); border-radius: 20px; padding: 0 14px; height: 36px; width: min(460px, 40vw); }
.search input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; }

/* ---------- елементи ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; font-size: 16px; }
.card-b { padding: 8px 16px 16px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--card-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 10px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 14px; font-size: 12px; background: var(--card-2); }
.chip.dark { background: #263445; color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--side); color: #fff; font-size: 11px; font-weight: 600; display: inline-grid; place-items: center; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- робочий стіл ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.stat { padding: 18px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.stat b { font-size: 22px; font-weight: 500; display: block; margin-bottom: 8px; }
.stat svg { width: 38px; height: 38px; color: var(--accent); }
.stat.red svg { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { height: 10px; background: var(--card-2); border-radius: 5px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 5px; background: var(--accent); }
.bar-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 16px; overflow-x: auto; }
.tab { padding: 12px 18px; border: 0; background: none; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; font-size: 13px; color: var(--text); padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: var(--card-2); }
.task-title { display: flex; align-items: center; gap: 8px; }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #b5c0cc; background: transparent; cursor: pointer; flex: none; display: grid; place-items: center; color: #fff; padding: 0; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check svg { width: 13px; height: 13px; }
.star { border: 0; background: none; cursor: pointer; color: #b5c0cc; padding: 0; font-size: 17px; line-height: 1; }
.star.on { color: #f5b301; }
.done-text { text-decoration: line-through; color: var(--muted); }
.overdue-text { color: var(--danger); }
.clock { width: 14px; height: 14px; color: var(--danger); flex: none; }

/* ---------- дошка лідів ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.view-switch { display: flex; gap: 2px; }
.view-switch button { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.view-switch button.active { background: var(--accent-soft); color: var(--accent); }
.view-switch svg { width: 20px; height: 20px; }
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 14px; min-height: calc(100vh - 160px); }
#leads-area { position: relative; }
.board-arrow { position: absolute; top: 45%; z-index: 4; width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(40, 50, 60, .55); color: #fff; font-size: 26px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.board-arrow:hover { background: rgba(40, 50, 60, .8); }
.board-arrow.left { left: 6px; }
.board-arrow.right { right: 6px; }
.col { width: 270px; flex: none; border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); max-height: calc(100vh - 170px); display: flex; flex-direction: column; }
.col.collapsed { width: 46px; }
.col.collapsed .col-body, .col.collapsed .col-add, .col.collapsed .col-count, .col.collapsed .col-plus { display: none; }
.col.collapsed .col-h { flex-direction: column; }
.col.collapsed .col-name { writing-mode: vertical-rl; margin-top: 6px; }
.col-h { display: flex; align-items: center; gap: 6px; padding: 2px 2px 8px; font-weight: 600; }
.col-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-count { font-weight: 400; color: var(--muted); }
.col-h button { border: 0; background: none; cursor: pointer; color: var(--text); width: 22px; height: 22px; border-radius: 5px; font-size: 16px; line-height: 1; }
.col-h button:hover { background: rgba(0,0,0,.06); }
.col-body { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 8px; }
.col.drop-over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.col-add { border: 0; background: none; text-align: left; padding: 10px 4px 2px; cursor: pointer; color: var(--text); }
.lead-card { background: var(--card); border-radius: 8px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.lead-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.14); }
.lead-card.dragging { opacity: .45; }
.lead-card .t { font-weight: 600; display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.lead-card .t svg { width: 14px; height: 14px; color: var(--muted); }
.lead-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.lead-card .meta b { color: var(--text); font-weight: 600; }
.lead-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.mini { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; font-size: 12px; }
.mini.red { color: var(--danger); border-color: var(--danger); }
.mini svg { width: 12px; height: 12px; }

/* ---------- картка ліда ---------- */
.lead-page { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.props { width: 100%; border-collapse: collapse; }
.props td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.props td:first-child { color: var(--text); width: 38%; border-right: 1px solid var(--line); }
.props tr:last-child td { border-bottom: 0; }
.props .val { word-break: break-word; }
.paid { padding: 16px 18px; }
.paid b { font-size: 18px; font-weight: 500; }
.log { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; }
.log-item { display: flex; gap: 10px; font-size: 13px; }
.log-item .body { flex: 1; min-width: 0; }
.log-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.log-item.note .body { background: var(--note); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }
.log-item .who { font-weight: 600; }
.bot-ava { background: var(--accent); }
.section-gap { margin-top: 14px; }

/* ---------- модальні вікна ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 25, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--card); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 17px; font-weight: 600; }
.modal-b { padding: 18px 20px 6px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.subtitle { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 8px 0 10px; }

/* ---------- спливаючі повідомлення ---------- */
#toasts { position: fixed; top: 64px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #ffe3e3; color: #2b1d1d; border-radius: 10px; box-shadow: var(--shadow); padding: 12px 36px 12px 14px; min-width: 260px; max-width: 360px; position: relative; font-size: 13px; cursor: pointer; }
.toast.ok { background: #dff5ec; }
.toast .x { position: absolute; top: 4px; right: 6px; font-size: 18px; color: #555; }

.dropdown { position: absolute; top: 46px; right: 0; width: 340px; max-height: 420px; overflow-y: auto; background: var(--card); border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.2); z-index: 40; }
.dropdown .item { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.dropdown .item.unread { background: var(--accent-soft); }
.dropdown .item:hover { background: var(--card-2); }

.themes { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-opt { width: 120px; border: 2px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; background: var(--card); text-align: center; font-size: 13px; }
.theme-opt.active { border-color: var(--accent); }
.theme-opt .sw { height: 40px; border-radius: 6px; margin-bottom: 6px; display: flex; overflow: hidden; }
.theme-opt .sw span { flex: 1; }
.status-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.status-row input[type=color] { width: 34px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2, .lead-page { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .sidebar { width: 52px; }
  .nav-btn { width: 40px; height: 40px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .user span { display: none; }
  .search { width: auto; flex: 1; }
  .content { padding: 10px; }
  .bar-row { grid-template-columns: 100px 1fr 30px; }
  .row { flex-direction: column; gap: 0; }
}
