:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2563eb; --accent-soft: #e8efff; --danger: #c62828; --warn: #b45309; --ok: #15803d;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0 0 8px; }
h4 { font-size: 14px; margin: 12px 0 6px; }
.muted { color: var(--muted); }

/* Шапка */
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 18px; background: #111827; color: #fff;
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 14px; align-items: center; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #cbd5e1; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar .btn-new { background: var(--accent); color: #fff !important; padding: 5px 12px; border-radius: 8px; }
.topbar .me { display: flex; gap: 10px; align-items: center; color: #cbd5e1; }
.topbar .me form { margin: 0; }
button.link { background: none; border: 0; color: #93c5fd; cursor: pointer; font: inherit; padding: 0; }

main { padding: 18px; max-width: 1200px; margin: 0 auto; }
main.wide { max-width: none; }
main.center { display: flex; justify-content: center; padding-top: 12vh; }

.messages { margin-bottom: 12px; }
.msg { padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 6px; }
.msg.error { background: #fdecec; color: var(--danger); }
.msg.success { background: #e9f7ee; color: var(--ok); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
input, select, textarea { font: inherit; width: 100%; padding: 7px 9px; border: 1px solid #cfd5dd; border-radius: 8px; background: #fff; }
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }

/* Вход */
.login { width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }

/* Фильтры */
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filters select { width: auto; }
.filters .search { max-width: 360px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Пропущенные */
.missed { background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius); padding: 9px 14px;
  display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

/* Доска */
.columns { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 10px;
  overflow-x: auto; padding-bottom: 10px; align-items: start; }
.column { background: #eceef2; border-radius: var(--radius); padding: 8px; min-height: 120px; }
.column header { display: flex; justify-content: space-between; font-weight: 600; padding: 2px 4px 8px; }
.column .count { background: #fff; border-radius: 999px; padding: 0 8px; font-size: 13px; }
.column .add { display: block; text-align: center; border: 1px dashed #9aa4b2; border-radius: 8px; padding: 7px;
  margin-bottom: 8px; color: var(--muted); }
.column .empty { color: #9aa4b2; text-align: center; padding: 14px 0; font-size: 13px; }
.tile { display: block; background: #fff; border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; color: var(--text);
  border-left: 4px solid #cbd5e1; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.tile:hover { text-decoration: none; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.tile-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.tile-main { margin: 3px 0; }
.tile-sub { font-size: 13px; color: var(--muted); }
.tile-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; margin-top: 5px; color: #374151; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 0 6px; }
.badge.warn { background: #fef3c7; color: var(--warn); }

/* Цвета стадий */
.stage-new .tile, .stage-pill.stage-new { border-left-color: #2563eb; }
.stage-negotiating .tile { border-left-color: #a855f7; }
.stage-searching .tile { border-left-color: #f59e0b; }
.stage-assigned .tile { border-left-color: #ea580c; }
.stage-on_way .tile, .stage-on_site .tile { border-left-color: #0891b2; }
.stage-long_repair .tile, .stage-installment .tile { border-left-color: #64748b; }
.stage-money_at_master .tile { border-left-color: #16a34a; }
.stage-pill { display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.stage-pill.stage-done { background: #e9f7ee; color: var(--ok); }
.stage-pill.stage-unclosed, .stage-pill.stage-spam, .stage-pill.stage-cancelled, .stage-pill.stage-refused { background: #fdecec; color: var(--danger); }

/* Карточка заявки */
.card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; gap: 10px; }
.card-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.order-form .fieldset { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.order-form summary { padding: 10px 14px; font-weight: 600; cursor: pointer; }
.order-form .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 0 14px 14px; }
.order-form.narrow { max-width: 640px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding-top: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field.check label { flex-direction: row; display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; padding-top: 22px; }
.field.wide { grid-column: 1 / -1; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.err { color: var(--danger); font-size: 13px; }
.actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.side { display: flex; flex-direction: column; gap: 12px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid #f0f1f4; font-size: 14px; }
.history li { font-size: 13px; }

/* Список закрытых */
table.list { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
table.list th { background: #f8f9fb; color: var(--muted); font-weight: 600; }
.pager { display: flex; gap: 14px; justify-content: center; padding: 14px; }

@media (max-width: 860px) {
  .card-grid { grid-template-columns: 1fr; }
  .order-form .fields { grid-template-columns: 1fr; }
  main { padding: 12px; }
}

/* Полоса «Пропущенные» и звонки в карточке */
.missed { flex-direction: column; align-items: stretch; gap: 0; }
.missed.calm { flex-direction: row; gap: 12px; background: #f0fdf4; border-color: #bbf7d0; }
.missed-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid #fde4c8; }
.missed-row .phone { font-weight: 600; }
.missed-row.overdue .phone { color: var(--danger); font-weight: 700; }
form.inline { display: inline; margin: 0; }
button.small { padding: 2px 8px; font-size: 12px; }
.calls li { font-size: 13px; }
.calls .lost { color: var(--danger); }

/* Деньги в карточке */
.hint { color: var(--muted); font-size: 12px; }
.money div { margin: 3px 0; }
.money .badge { display: inline-block; margin: 4px 0; }

/* Касса и сверка */
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { display: inline-block; color: var(--text); }
.btn.primary-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.onhands { margin-bottom: 12px; }
.onhands .pill { display: inline-block; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 999px; padding: 3px 12px; margin: 3px 6px 3px 0; }
table.cash td, table.cash th { white-space: nowrap; font-size: 13px; }
table.cash tfoot th { background: #f8f9fb; }
td.debt { color: var(--danger); font-weight: 700; }
h3.section { margin: 22px 0 8px; }
td.err { font-size: 13px; }
