:root {
  --accent: #f2a93b;          /* фірмовий помаранчевий FOCUS */
  --blue: #2f86e0;            /* посилання й активні елементи */
  --ink: #1c1e21;
  --muted: #6b7280;
  --line: #e6eaf0;
  --bg: #eef2f7;              /* холодне тло, на ньому картки читаються */
  --card: #fff;
  --shadow: 0 1px 3px rgba(28, 40, 60, .07), 0 1px 2px rgba(28, 40, 60, .04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
}
a { color: var(--blue); }

header {
  display: flex; align-items: center; gap: 28px;
  padding: 0 22px; background: #fff; border-bottom: 3px solid var(--accent);
  position: sticky; top: 0; z-index: 5;
}
header b { font-size: 17px; letter-spacing: .5px; padding: 14px 0; }
header b span { color: var(--accent); margin-left: 4px; }
nav { display: flex; gap: 4px; }
nav a {
  padding: 15px 14px; color: var(--muted); text-decoration: none;
  border-bottom: 3px solid transparent; margin-bottom: -3px;
}
nav a:hover { color: var(--ink); }
nav a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1420px; margin: 20px auto; padding: 0 20px 60px; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 24px 0 10px; }

.card { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1 1 220px; }
.bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }

/* ── Стрічка карток-рядків (як у KeyCRM) ───────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }
.list .head, .list .item {
  display: grid; align-items: center; gap: 14px;
  grid-template-columns: 175px 112px minmax(190px, 1fr) 84px 112px 112px 106px 106px 120px 34px;
}
.list .head {
  padding: 0 18px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-weight: 600;
}
.list .item {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  padding: 14px 18px;
}
.list .item:hover { box-shadow: 0 2px 8px rgba(28, 40, 60, .12); }
.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .debt { color: #b32b2b; font-weight: 700; }
.list .who { font-weight: 600; text-decoration: none; }
.list .who:hover { text-decoration: underline; }
.goods { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.goods li { display: flex; gap: 6px; padding: 1px 0; }
.goods .no { color: var(--muted); flex: 0 0 auto; }
.files { font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.files a { text-decoration: none; }
.files a:hover { text-decoration: underline; }

/* ── Фільтр статусів ───────────────────────────────────────────────────── */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: #fff; border-radius: 999px; padding: 6px 14px;
  box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600;
}
.chip:hover { color: var(--ink); box-shadow: 0 2px 8px rgba(28, 40, 60, .14); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip .n { color: var(--muted); font-weight: 500; }
.chip.on { outline: 2px solid var(--accent); }
.chip.lead { color: #1a7f37; } .chip.qualify { color: #6b7280; }
.chip.kp { color: #2f86e0; }   .chip.invoice { color: #8a5a00; }
.chip.prepaid { color: #b26a00; } .chip.production { color: #7a4bd0; }
.chip.ready { color: #0f766e; } .chip.shipped { color: #2f86e0; }
.chip.done { color: #1a7f37; }  .chip.lost { color: #c0392b; }
/* «Все» — перша плашка: нейтральний темний, щоб не конкурувала
   кольором зі стадіями й читалась як «без фільтра». */
.chip.all { color: #1c283c; font-weight: 600; }
/* типи контрагентів */
.chip.blue { color: #2065ad; } .chip.amber { color: #8a5a00; }
.chip.violet { color: #5b3bab; }

/* ── Таблетки статусів ─────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: 12px; white-space: nowrap; background: #eef1f5; color: #4b5563;
}
.pill.green { background: #e3f5e9; color: #1a7f37; }
.pill.blue { background: #e4f0fd; color: #2065ad; }
.pill.amber { background: #fdf1d8; color: #8a5a00; }
.pill.violet { background: #efe8fb; color: #5b3bab; }
.pill.teal { background: #ddf3f0; color: #0f766e; }
.pill.red { background: #fdeaea; color: #b32b2b; }
.pill.grey { background: #f1f3f6; color: #8a9099; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfd; }
table a { color: var(--ink); text-decoration: none; font-weight: 600; }
table a:hover { color: var(--blue); }
.wrap { overflow-x: auto; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field { margin-bottom: 12px; }

button, .btn {
  padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: inherit; cursor: pointer; text-decoration: none; color: var(--ink);
  display: inline-block; white-space: nowrap; box-shadow: var(--shadow);
}
button:hover, .btn:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; color: var(--ink); }
.link { border: 0; background: 0; box-shadow: none; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.link:hover { color: #c0392b; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: #eef1f5; color: #4b5563; white-space: nowrap; }
.tag.hot { background: #fdf1d8; color: #8a5a00; }
.tag.done { background: #e3f5e9; color: #1a7f37; }
.tag.lost { background: #f1f3f6; color: #8a9099; }
.muted { color: var(--muted); }
.right { text-align: right; }
.empty { padding: 34px; text-align: center; color: var(--muted); }

.totals { margin-left: auto; min-width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .sum { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 19px; font-weight: 700; }
.warn { background: #fdf1d8; border: 1px solid var(--accent); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }

/* Вузький екран: сітка розсипається на рядки, нічого не ховаємо */
@media (max-width: 1100px) {
  .list .head { display: none; }
  .list .item { grid-template-columns: 1fr 1fr; }
  .list .num { text-align: left; }
  /* Заголовки колонок сховані — підписуємо значення на місці, інакше
     «66 612 / — / —» неможливо розрізнити. */
  .list .item [data-l]::before {
    content: attr(data-l); display: block;
    font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
    color: var(--muted); font-weight: 600;
  }
}

/* Телефон */
@media (max-width: 700px) {
  main { padding: 0 12px 40px; margin-top: 14px; }
  header { gap: 12px; padding: 0 12px; }
  /* Меню не влазить — гортається вбік, а не обрізається */
  nav { overflow-x: auto; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { padding: 14px 10px; white-space: nowrap; }
  /* Те саме для фільтра статусів: рядок замість п'яти */
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  /* ── Список на телефоні: рядок, а не розгорнута картка ──────────────────
     Денис, 17.09.2026: «одна картка на весь екран, а мені потрібно бачити
     порядково картину загалом і по кліку відкривати картку».
     Було: усі десять полів стовпчиком із підписами — одна угода займала
     весь екран. Стало: клієнт і сума в першому рядку, стадія й залишок
     у другому; решта — у картці угоди, куди веде клік. */
  .list .item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 10px;
    align-items: center;
    padding: 10px 12px;
  }
  /* Ховаємо те, що в загальній картині не потрібне: товари, дату створення,
     статус оплати (його заміняє червоний залишок), сплачену суму,
     документи й хрестик видалення. Усе це є в самій картці. */
  .list .item > *:nth-child(3),
  .list .item > *:nth-child(6),
  .list .item > *:nth-child(7),
  .list .item > *:nth-child(9),
  .list .item > *:nth-child(10) { display: none; }

  /* Порядок у рядку: клієнт | сума, стадія | залишок, дата останнім рядком
     (Денис, 17.09.2026: «дату додай дрібним»). */
  .list .item > *:nth-child(1) { order: 1; }
  .list .item > *:nth-child(5) { order: 2; }
  .list .item > *:nth-child(2) { order: 3; }
  .list .item > *:nth-child(8) { order: 4; }
  .list .item > *:nth-child(4) { order: 5; font-size: 11px; margin-top: 2px; }

  /* Підписи колонок тут зайві — значення і так зрозумілі. */
  .list .item [data-l]::before { display: none; }
  .list .item .num { text-align: right; }
  .list .item .who { font-size: 15px; }
  /* Стадія по вмісту, а не на всю колонку. */
  /* Ширину задаємо жорстко: select міряє себе за найдовшою опцією
     («Готово до відвантаження»), і без цього плашка розтягується на весь
     рядок. */
  .list .item .pill-select {
    font-size: 11px; padding: 3px 18px 3px 8px;
    width: auto; max-width: 165px; text-overflow: ellipsis;
  }
  .list .item > *:nth-child(2) { justify-self: start; }

  /* Клік у будь-яке порожнє місце рядка відкриває картку угоди. Посилання
     на угоду розтягується накладкою на всю картку, а решта елементів
     лишається над ним — тож імʼя клієнта веде до клієнта, а випадайка
     стадії працює як працювала. */
  .list .item { position: relative; }
  .list .item .deal-link::after { content: ''; position: absolute; inset: 0; }
  .list .item > * { position: relative; }
  .list .item .who,
  .list .item .pill-select { position: relative; z-index: 1; }

  .bar { align-items: flex-start; }
  /* Ряд кнопок у картці угоди теж гортається */
  .bar > div { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .bar > div::-webkit-scrollbar { display: none; }
  .row > * { flex-basis: 100%; }
}

/* ── Вхід ─────────────────────────────────────────────────────────────── */
body.login { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; margin: 0; }
body.login .card { width: 320px; }
body.login b { display: block; margin-bottom: 18px; font-size: 20px; }
body.login button { width: 100%; margin-top: 8px; }
body.login b span { color: var(--accent); margin-left: 4px; }
header .exit { margin-left: auto; }

/* ── Пошук у шапці списку ──────────────────────────────────────────────── */
.search { display: flex; gap: 8px; flex: 1 1 340px; max-width: 520px; }
.search input { border-radius: 8px; }
@media (max-width: 700px) {
  .search { flex-basis: 100%; max-width: none; }
}

/* ── Вікно завантаження документів ─────────────────────────────────────── */
.drop {
  border: 2px dashed var(--line); border-radius: 10px;
  background: #fbfcfe; text-align: center; padding: 26px 18px;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: #fdf7ec; }
.drop.has { border-style: solid; border-color: var(--accent); background: #fdf9f2; }
.drop-in b { display: block; font-size: 15px; }
.drop .btn { margin: 0 4px; }
@media (max-width: 700px) {
  .drop { padding: 20px 12px; }
  .drop .btn { display: block; width: 100%; margin: 6px 0 0; }
}

/* ── Смужка «сторінка думає» ───────────────────────────────────────────── */
#bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent); z-index: 10; transition: width .2s;
}
#bar.on { animation: crawl 12s ease-out forwards; }
@keyframes crawl {
  0%   { width: 0; }
  8%   { width: 35%; }
  40%  { width: 70%; }
  100% { width: 92%; }
}
button[disabled] { opacity: .65; cursor: progress; }

/* Лічильник задач у меню */
.badge {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; background: #e4f0fd; color: #2065ad;
  font-size: 11px; font-weight: 700; text-align: center; vertical-align: 1px;
}
.badge.hot { background: #fdeaea; color: #b32b2b; }

/* Згортка «+ Додати контакт». Стандартний трикутник прибираємо: замість
   нього своя кругла плашка з плюсом. Форма розгортається без перезавантаження
   сторінки — це нативний <details>, JS не потрібен. */
.contact-add > summary::-webkit-details-marker { display: none; }
.contact-add > summary::marker { content: ''; }
.contact-add > summary:hover { background: #fafafa; }
.contact-add[open] > summary { border-bottom: 1px solid #eee; }

/* Стадія просто в списку — випадайка, схожа на звичайну плашку.
   Міняється одним дотиком, без заходу в картку (як у KeyCRM). */
.pill-select {
  border: 1px solid transparent; cursor: pointer; font: inherit;
  font-size: 12px; font-weight: 600; padding: 4px 22px 4px 10px;
  border-radius: 999px; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 9px top 50%, right 5px top 50%;
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
  max-width: 100%;
}
.pill-select:hover { border-color: rgba(28,40,60,.18); }
.pill-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Швидкі суми під формою оплати: «уся доплата» і «половина» — щоб не
   набирати число руками з телефона (Денис, 17.09.2026). */
.pay-quick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.pay-quick .btn { font-size: 12px; padding: 5px 12px; }
@media (max-width: 700px) {
  .pay-quick .btn { flex: 1 1 auto; }
}
