/* Rent & Stay CRM. Mobile-first, светлая/тёмная тема по системе. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #5d6470;
  --border: #d9dde3;
  --brand-ink: #000000;
  --accent: #ef965a;        /* оранжевый из логотипа: заливки */
  --accent-soft: #fdebdd;
  --accent-text: #1a1206;   /* тёмный текст на оранжевом */
  --link: #b4581c;          /* тот же оранжевый темнее: текст и ссылки на белом (контраст ≥ 4.5) */
  --error: #c62828;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #d9b310;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}
/* Тёмная тема: по системе (если пользователь не выбрал светлую) или выбрана вручную. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e8eaed;
    --muted: #9aa1ac;
    --border: #2c313a;
    --accent-soft: #3a2414;
    --link: #f2a774;
    --error: #ef5350;
    --danger: #ef5350;
    --ok: #66bb6a;
    --warn: #f5d33d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --text: #e8eaed;
  --muted: #9aa1ac;
  --border: #2c313a;
  --accent-soft: #3a2414;
  --link: #f2a774;
  --error: #ef5350;
  --danger: #ef5350;
  --ok: #66bb6a;
  --warn: #f5d33d;
  color-scheme: dark;
}

.theme-toggle {
  margin-left: auto; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer;
}

* { box-sizing: border-box; }
/* Атрибут hidden должен побеждать display из классов (.field и др.). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* --- Каркас ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 16px; height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; color: var(--text);
  font-family: Georgia, "Times New Roman", serif; letter-spacing: .14em; text-transform: uppercase;
  font-size: .95rem;
}
.brand:hover { text-decoration: none; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); }
.topnav a[aria-current="page"] { color: var(--link); background: var(--accent-soft); }

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.page-head p { margin-top: 4px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60px; font-size: .72rem; color: var(--muted); text-decoration: none;
}
.bottomnav .ico { font-size: 1.3rem; line-height: 1.2; }
.bottomnav a[aria-current="page"] { color: var(--link); }
.bottomnav a.call .ico {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-size: 1.3rem;
}

@media (min-width: 768px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .page { padding-bottom: 48px; }
}

/* --- Кнопки ---------------------------------------------------------- */
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; min-height: var(--tap); padding: 0 18px;
  border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-text); border: 0; }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-primary:hover, .btn-ghost:hover, .btn-danger:hover { text-decoration: none; filter: brightness(1.05); }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.btn-link { font: inherit; background: none; border: 0; color: var(--link); cursor: pointer; min-height: 44px; padding: 0 8px; }
.htmx-request .btn-primary, .btn-primary.htmx-request { opacity: .6; }

/* --- Карточки и списки ------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 60px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
a.list-item:hover { border-color: var(--accent); text-decoration: none; }
.list-main { display: grid; min-width: 0; }
.list-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-side { color: var(--muted); white-space: nowrap; font-size: .9rem; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.badge {
  display: inline-block; padding: 0 8px; border-radius: 999px; font-size: .75rem;
  background: var(--accent-soft); color: var(--link);
}
.status { font-weight: 600; }
.status-listed, .status-showing { color: var(--link); }
.status-rented { color: var(--ok); }
.status-agreement_signed { color: var(--warn); }
.status-archived { color: var(--muted); }

.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.notes { margin-top: 12px; white-space: pre-wrap; }
.quick-actions { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.quick-actions > * { flex: 1 1 140px; }
.danger-zone { margin-top: 40px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline-item {
  display: grid; gap: 2px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text);
}
.timeline-item:hover { text-decoration: none; border-color: var(--accent); }
.timeline-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.timeline-note { white-space: pre-wrap; }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; }

/* --- Формы ----------------------------------------------------------- */
.form { display: grid; gap: 16px; }
.form-section { margin: 8px 0 -4px; font-size: .95rem; color: var(--muted); }
.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > span, .field > legend { font-weight: 500; font-size: .92rem; padding: 0; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-height: var(--tap); width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--error); }
.field-error, .error { color: var(--error); font-size: .88rem; margin: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.check input { width: 22px; min-height: 22px; height: 22px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions > * { flex: 1 1 140px; }
.notice {
  padding: 10px 14px; border-radius: 10px; background: var(--accent-soft);
  display: grid; gap: 4px;
}
.grid-2, .grid-3 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 520px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* Чипы: радио/чекбоксы в виде крупных кнопок */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.chip span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  user-select: none;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { outline: 2px solid var(--link); outline-offset: 2px; }

.chips-big .chip span { min-height: 52px; padding: 0 16px; font-weight: 500; }
.chip-agreed_open input:checked + span,
.chip-agreed_exclusive input:checked + span,
.chip-meeting_booked input:checked + span { background: var(--ok); border-color: var(--ok); color: #ffffff; }

/* Переключатель «собственник / арендатор / другое» */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.segmented span {
  display: flex; align-items: center; justify-content: center; min-height: 44px;
  border-radius: 9px; color: var(--muted); font-weight: 500;
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.segmented input:focus-visible + span { outline: 2px solid var(--link); }

.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .is-active { border-color: var(--accent); color: var(--link); }
.more-fields summary { cursor: pointer; color: var(--muted); min-height: var(--tap); display: flex; align-items: center; }
.more-fields[open] summary { margin-bottom: 8px; }
.sticky-actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--bg); padding: 8px 0;
}
@media (min-width: 768px) { .sticky-actions { bottom: 0; } }
.toast {
  margin-bottom: 12px; padding: 10px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); font-weight: 500;
}

/* «Сегодня»: счётчики */
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.counter {
  display: grid; gap: 2px; padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--border);
  color: var(--text); text-decoration: none;
}
.counter:hover { text-decoration: none; border-color: var(--accent); }
.counter-title { font-size: .8rem; color: var(--muted); }
.counter-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.counter-value small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.counter-green { border-top-color: var(--ok); }
.counter-yellow { border-top-color: var(--warn); }
.counter-red { border-top-color: var(--danger); }
.counters-hint { margin-top: 6px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 24px 0 8px; }
.section-head h2 { margin: 0; }
.overdue-title { color: var(--danger); }
.no-date { margin-top: 16px; }
.no-date summary { cursor: pointer; font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }

/* Задачи */
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; min-height: 60px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.task-main { display: grid; flex: 1; min-width: 0; }
.task-title { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.task-actions { display: flex; gap: 6px; align-items: center; }
.task-actions form { margin: 0; }
.task-actions .btn-ghost { min-width: 44px; padding: 0 12px; font-size: 1.05rem; }
.task-done .task-title, .task-cancelled .task-title { text-decoration: line-through; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 999px; color: var(--muted); white-space: nowrap; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--link); }

.export-card { display: grid; gap: 12px; }

/* Сегодня: 4 счётчика, ссылки в шапке, сигналы */
.counters-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .counters-4 { grid-template-columns: repeat(4, 1fr); } }
.counter-none { border-top-color: var(--border); }
.counters-2 { grid-template-columns: repeat(2, 1fr); }
.counters-3 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .counters-3 { grid-template-columns: repeat(3, 1fr); } }
.tiles-label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 0 8px; }
.tiles-label small { text-transform: none; letter-spacing: 0; }
.head-links { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.signal { border-left: 4px solid var(--warn); }
.signal-count { font-weight: 700; font-size: 1.2rem; color: var(--text); }
.day-label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 12px 0 6px; }

/* События (встречи, показы, задачи) */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.event {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; min-height: 56px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.event:hover { text-decoration: none; border-color: var(--accent); }
.event-time { font-weight: 700; min-width: 3.2em; font-variant-numeric: tabular-nums; }
.event-main { display: grid; min-width: 0; }
.event-main small { color: var(--muted); }
.event-meeting { border-left-color: var(--accent); }
.event-showing { border-left-color: var(--ok); }
.event-task { border-left-color: var(--muted); }
.event-overdue { border-left-color: var(--danger); }
.event-overdue small { color: var(--danger); }
.event-done { opacity: .7; }

/* Календарь */
.cal-nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cal-views { margin-left: auto; display: flex; gap: 4px; }
.cal-views a { padding: 8px 12px; border-radius: 999px; color: var(--muted); }
.cal-views a[aria-current="page"] { background: var(--accent-soft); color: var(--link); }
.week { display: grid; gap: 4px; }
.week-day.is-today .day-label { color: var(--link); font-weight: 700; }
.month { display: grid; gap: 4px; }
.month-head, .month-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-head span { text-align: center; font-size: .75rem; color: var(--muted); }
.month-cell {
  display: grid; align-content: start; gap: 2px; min-height: 76px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); overflow: hidden; font-size: .7rem;
}
.month-cell:hover { text-decoration: none; border-color: var(--accent); }
.month-cell.other { opacity: .45; }
.month-cell.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.month-day { font-weight: 700; font-size: .8rem; }
.dot {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 1px 4px; border-radius: 4px; border-left: 3px solid var(--border);
}
.dot-meeting { border-left-color: var(--accent); }
.dot-showing { border-left-color: var(--ok); }
.dot-task { border-left-color: var(--muted); }
.dot-overdue { border-left-color: var(--danger); }
.more { color: var(--muted); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.legend .dot { display: inline-block; }

/* Дашборд */
.dash-grid { display: grid; gap: 12px; }
@media (min-width: 900px) { .page:has(.dash-grid) { max-width: 1100px; } .dash-grid { grid-template-columns: 1fr 1fr; } }
.metrics h2, .card > h2 { margin-top: 0; }
.metrics table, .facts { width: 100%; border-collapse: collapse; }
.metrics th, .metrics td, .facts th, .facts td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.metrics td, .facts td { text-align: right; font-variant-numeric: tabular-nums; }
.metrics thead th, .facts thead th { font-size: .8rem; color: var(--muted); font-weight: 500; }
.metrics thead th:not(:first-child), .facts thead th:not(:first-child) { text-align: right; }
.metrics tbody th, .facts tbody th { font-weight: 500; }
.metric-green .pct { color: var(--ok); font-weight: 700; }
.metric-yellow .pct { color: var(--warn); font-weight: 700; }
.metric-red .pct { color: var(--danger); font-weight: 700; }
section.card { margin-top: 12px; }
.info-rows { margin-top: 10px; }
.info-rows summary { cursor: pointer; color: var(--muted); font-size: .9rem; min-height: 40px; display: flex; align-items: center; }
.info-rows table { width: 100%; border-collapse: collapse; }
.signal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.signal-list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.signal-list .ok .signal-status { color: var(--ok); }
.signal-list .warn .signal-status { color: var(--danger); font-weight: 700; }
.close-form { margin-top: 16px; }

/* Объекты: карточки в списке */
.prop-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
@media (min-width: 640px) { .prop-cards { grid-template-columns: 1fr 1fr; } }
.page:has(.prop-cards) { max-width: 1000px; }
.prop-card {
  display: grid; overflow: hidden; height: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text);
}
.prop-card:hover { text-decoration: none; border-color: var(--accent); }
.prop-photos {
  display: grid; gap: 2px; aspect-ratio: 16 / 9; background: var(--surface-2);
  grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr;
}
.prop-photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prop-photos img:first-child { grid-row: 1 / 3; }
.photos-1 img:first-child, .photos-0 .no-photo { grid-column: 1 / 3; }
.photos-2 img:nth-child(2) { grid-row: 1 / 3; }
.no-photo { grid-column: 1 / 3; grid-row: 1 / 3; display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.prop-body { display: grid; gap: 2px; padding: 12px 14px; }
.prop-top { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }
.prop-title { font-size: 1.02rem; line-height: 1.3; }
.prop-price { display: flex; gap: 8px; align-items: baseline; margin-top: 4px; }
.prop-price strong { font-size: 1.1rem; }
.prop-facts { font-size: .9rem; }

/* Объект: галерея */
.gallery-card { display: grid; gap: 12px; }
.gallery { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.gallery-item { margin: 0; display: grid; gap: 4px; position: relative; cursor: grab; user-select: none; }
.gallery-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; display: block;
  transition: transform .2s ease, box-shadow .2s ease; }
.gallery-item:first-child img { outline: 3px solid var(--accent); outline-offset: -3px; }
.cover-badge { display: none; position: absolute; top: 6px; left: 6px; }
.gallery-item:first-child .cover-badge { display: inline-block; }
.drag-handle {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  color: var(--muted); cursor: grab; touch-action: none; font-size: 1.2rem;
}
.drag-handle:hover { background: var(--surface-2); color: var(--text); }
.gallery-item.is-dragging { z-index: 5; cursor: grabbing; }
.gallery-item.is-dragging img { transform: scale(1.05) rotate(-1deg); box-shadow: 0 12px 28px rgba(0, 0, 0, .28); }
.gallery.is-sorting .gallery-item:not(.is-dragging) img { opacity: .85; }
.gallery.saved { animation: saved-flash .7s ease-out; }
.gallery.save-failed { outline: 2px solid var(--danger); border-radius: 10px; }
@keyframes saved-flash { 0% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 6px var(--accent-soft); } 100% { box-shadow: 0 0 0 0 transparent; } }
.gallery-item figcaption { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.gallery-item figcaption form { margin: 0; }
.danger-link { color: var(--danger); }
.upload { display: grid; gap: 6px; }
.upload-btn { position: relative; overflow: hidden; justify-self: start; }
.upload-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.tag { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); }
.amenities { margin-top: 12px; }
.inline-area { gap: 8px; }

/* --- Доска (лиды, сделки) ---------------------------------------------------- */
.page:has(.kanban) { max-width: none; }
.kanban {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 10px;
  overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory;
}
.kanban-col {
  display: grid; align-content: start; gap: 8px; padding: 10px; min-height: 160px;
  background: var(--surface-2); border-radius: var(--radius); scroll-snap-align: start;
  border-top: 4px solid var(--border); transition: background-color .15s, box-shadow .15s;
}
.kanban-col.is-over { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.kanban-head { margin: 0; font-size: .9rem; display: flex; justify-content: space-between; align-items: center; }
.kanban-count { font-size: .8rem; color: var(--muted); background: var(--surface); border-radius: 999px; padding: 0 8px; }
.kanban-cards { display: grid; gap: 8px; min-height: 40px; }
.kanban-new, .kanban-signed { border-top-color: var(--accent); }
.kanban-deal, .kanban-paid { border-top-color: var(--ok); }
.kanban-lost, .kanban-failed { border-top-color: var(--danger); }
.kanban-decision { border-top-color: var(--warn); }
.kanban.is-dragging { cursor: grabbing; user-select: none; }
.is-placeholder { opacity: .35; }
.kanban-ghost { transform: rotate(-2deg) scale(1.03); box-shadow: 0 16px 34px rgba(0, 0, 0, .25); }
@media (hover: hover) { [data-kanban] [data-card-id] { cursor: grab; } }

.lead-card {
  display: grid; gap: 2px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 10px;
  color: var(--text); user-select: none;
}
.lead-card:hover { text-decoration: none; border-color: var(--accent); }
.lead-card.is-waiting { border-left-color: var(--danger); }
.lead-card-top, .lead-card-bottom { display: flex; justify-content: space-between; gap: 6px; align-items: center; flex-wrap: wrap; }
.lead-list .lead-card { min-height: 60px; }
.wait-badge { color: #fff; background: var(--danger); border-radius: 999px; padding: 0 8px; font-weight: 600; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.ok-text { color: var(--ok); font-weight: 600; }
.late-text { color: var(--danger); font-weight: 600; }

.stage-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.stage-bar form { margin: 0; }
.stage-step {
  font: inherit; font-size: .85rem; min-height: 38px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.stage-step:hover { border-color: var(--accent); color: var(--text); }
.stage-step.is-current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.stage-step.stage-lost.is-current, .stage-step.stage-failed.is-current { background: var(--danger); border-color: var(--danger); color: #fff; }
.stage-step.stage-deal.is-current, .stage-step.stage-paid.is-current { background: var(--ok); border-color: var(--ok); color: #fff; }
.waiting-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  border-color: var(--danger); margin-bottom: 12px; }

/* --- Анимации ------------------------------------------------------------- */
/* Плавная смена экранов (htmx + View Transitions, где поддерживается браузером). */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .22s; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.94); } 60% { transform: scale(1.04); } 100% { transform: none; } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.page > * { animation: rise .32s ease-out both; }
.page > *:nth-child(2) { animation-delay: .03s; }
.page > *:nth-child(3) { animation-delay: .06s; }
.page > *:nth-child(4) { animation-delay: .09s; }
.page > *:nth-child(n+5) { animation-delay: .12s; }

/* Элементы списков появляются лесенкой. */
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > * { animation: rise .3s ease-out both; }
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > *:nth-child(2) { animation-delay: .03s; }
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > *:nth-child(3) { animation-delay: .06s; }
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > *:nth-child(4) { animation-delay: .09s; }
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > *:nth-child(5) { animation-delay: .12s; }
:is(.list, .tasks, .events, .prop-cards, .counters, .gallery) > *:nth-child(n+6) { animation-delay: .15s; }

.toast { animation: slide-down .3s ease-out both; }
.chip input:checked + span { animation: pop .25s ease-out; }
.chip span, .segmented span { transition: background-color .15s, color .15s, border-color .15s; }
.btn-primary, .btn-ghost, .btn-danger, .chip span, .counter { transition: transform .12s ease, filter .15s, box-shadow .2s, border-color .15s; }
.btn-primary:active, .btn-ghost:active, .btn-danger:active, .chip:active span { transform: scale(.97); }
.task { transition: opacity .3s ease, background-color .3s ease; }
.task-done { animation: pop .3s ease-out; }
.task-done, .task-cancelled { opacity: .65; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
#results.htmx-request { opacity: .55; transition: opacity .15s; }

/* Наведение мышью (компьютер): лёгкий подъём карточек и строк. */
@media (hover: hover) {
  :is(.list-item, .prop-card, .event, .timeline-item, .counter, .task, .month-cell) {
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  }
  :is(a.list-item, .prop-card, .event, .timeline-item, .counter, .task):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .10);
  }
  .month-cell:hover { transform: scale(1.03); box-shadow: 0 6px 16px rgba(0, 0, 0, .10); }
  .prop-card img { transition: transform .35s ease; }
  .prop-card:hover img:first-child { transform: scale(1.04); }
  .btn-primary:hover { box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); }
  .gallery-item:hover img { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0, 0, 0, .18); }
  .topnav a { transition: background-color .15s, color .15s; }
}
.prop-photos { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}

/* Фильтры списков */
.filters { display: grid; gap: 10px; margin-bottom: 16px; }
.filters-row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; align-items: end; }
.filters-row .field > span { display: none; }
.filters-row .check { grid-column: 1 / -1; }

/* Поле выбора с автодополнением */
.picker { position: relative; }
.picker-row { display: flex; gap: 6px; }
.picker-row .btn-ghost { padding: 0 14px; min-width: var(--tap); }
.picker-results:empty { display: none; }
.picker-results {
  display: grid; gap: 2px; padding: 4px; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.pick-item {
  display: grid; text-align: left; gap: 0; width: 100%;
  font: inherit; color: inherit; background: none; border: 0; border-radius: 8px;
  min-height: var(--tap); padding: 6px 10px; cursor: pointer;
}
.pick-item:hover, .pick-item:focus { background: var(--surface-2); }
.pick-empty { padding: 8px 10px; }

/* Вход */
.auth { max-width: 400px; margin: 0 auto; padding: 10vh 16px 32px; }
.auth { position: relative; }
.auth-theme { position: absolute; top: 16px; right: 16px; }
.auth-brand { display: grid; justify-items: center; gap: 6px; margin-bottom: 24px; }
.auth-brand h1 {
  font-family: Georgia, "Times New Roman", serif; font-weight: 400;
  letter-spacing: .2em; text-transform: uppercase; color: var(--link); font-size: 1.5rem;
}
.auth-brand p { letter-spacing: .3em; color: var(--muted); font-size: .8rem; }
.auth .card { display: grid; gap: 16px; padding: 20px; }
.auth label { display: grid; gap: 6px; font-weight: 500; }

/* --- Сделки ------------------------------------------------------------------- */
.deal-card.is-unpaid { border-left-color: var(--warn); }
.deal-sum { font-variant-numeric: tabular-nums; }
.calc-box {
  display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 10px 12px; border-radius: 10px;
  background: var(--accent-soft); font-variant-numeric: tabular-nums;
}
fieldset.payment { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px 12px; margin: 0; }
fieldset.payment legend { padding: 0 6px; color: var(--muted); font-size: .9rem; }
.money-table .total-row th, .money-table .total-row td { border-bottom: 0; }
.filter-note { margin: 4px 0 0; color: var(--muted); }
.back-link { display: inline-block; margin: 0 0 8px; padding: 6px 2px; color: var(--muted); font-size: .95rem; }
.back-link:hover { color: var(--accent); text-decoration: none; }
.new-person { margin: -4px 0 4px; }
.new-person summary { cursor: pointer; color: var(--accent); font-size: .92rem; padding: 4px 0; }
.new-person[open] { padding: 8px 12px 12px; border: 1px dashed var(--border); border-radius: 10px; }
.warn-text { color: var(--warn); font-weight: 600; }
.form-more summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.form-more[open] { display: grid; gap: 12px; }
.dossier { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.dossier-item { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.dossier-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.file-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.file-chips li { display: flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; background: var(--surface-2); border-radius: 999px; font-size: .9rem; }
.file-chips form { margin: 0; }
.dossier-new { margin-bottom: 12px; }
.dossier-new > summary { list-style: none; display: inline-block; cursor: pointer; }
.dossier-new > summary::-webkit-details-marker { display: none; }
.dossier-new[open] > summary { margin-bottom: 8px; }
.dossier-form { padding: 12px; border: 1px dashed var(--accent); border-radius: 10px; }
.dossier-form-title { margin: 0; font-weight: 600; }
.dossier-edit summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.file-add { background: transparent !important; border: 1px dashed var(--border); }
.file-add .upload-btn { color: var(--accent); cursor: pointer; padding-right: 6px; }

/* --- Бухгалтерия --------------------------------------------------------------- */
.fin-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 12px; border-bottom: 1px solid var(--border); }
.fin-tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.fin-tabs a:hover { color: var(--text); text-decoration: none; }
.fin-tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.month-switch { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.fin-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 12px; }
.fin-card {
  display: grid; gap: 4px; align-content: start; padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
a.fin-card:hover { text-decoration: none; border-color: var(--accent); }
.fin-main { border-color: var(--accent); }
.fin-big { font-size: 1.6rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.fin-usd { color: var(--muted); font-variant-numeric: tabular-nums; }
.fin-total { margin: 0 0 10px; }
.progress { display: block; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 4px 0; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .6s ease-out; }
.fin-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 170px; }
.fin-col { display: grid; grid-template-rows: 1fr auto; height: 100%; text-align: center; color: var(--muted); border-radius: 6px; }
.fin-col:hover { background: var(--surface-2); text-decoration: none; }
.fin-col.is-current small { color: var(--accent); font-weight: 600; }
.fin-bars { display: flex; align-items: end; justify-content: center; gap: 2px; height: 100%; }
.fin-bars > span { width: 40%; min-height: 1px; border-radius: 3px 3px 0 0; }
.bar-in, .legend-in { background: var(--ok); }
.bar-out, .legend-out { background: var(--danger); opacity: .75; }
.legend-in, .legend-out { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.list-item.is-planned { border-left: 3px solid var(--warn); }
.dossier-item.is-off { opacity: .55; }
@media (max-width: 420px) { .fin-chart small { font-size: .65rem; } }

/* --- Постер для сторис --------------------------------------------------------- */
.story-layout { display: grid; gap: 12px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) { .story-layout { grid-template-columns: 1fr 400px; } }
.story-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); margin: 8px 0 12px; }
.story-thumb { position: relative; padding: 0; border: 3px solid transparent; border-radius: 10px; overflow: hidden; background: none; cursor: pointer; aspect-ratio: 4 / 3; }
.story-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.story-thumb[aria-pressed="true"] { border-color: var(--accent); }
.story-num:not(:empty) {
  position: absolute; top: 6px; left: 6px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-weight: 700; display: grid; place-items: center;
}
.story-preview { display: grid; gap: 12px; justify-items: center; }
.story-preview img { width: 100%; max-width: 360px; height: auto; border-radius: 12px; background: #000; }
.badge-noads { background: var(--surface-2); color: var(--text); border: 1px dashed var(--accent); }

/* --- Подбор квартир под лида -------------------------------------------------- */
.match-list { display: grid; gap: 8px; }
.match {
  display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center;
  padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.match.is-near { border-style: dashed; }
.match-photo { width: 96px; height: 72px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.match-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.match-body { display: grid; gap: 2px; min-width: 0; }
.match-checks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.match-check { font-size: .8rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); }
.match-check.ok { color: var(--ok); }
.match-check.miss { color: var(--warn); }
@media (max-width: 520px) {
  .match { grid-template-columns: 72px 1fr; }
  .match-photo { width: 72px; height: 56px; }
  .match > .btn-ghost { grid-column: 1 / -1; justify-self: start; }
}

/* --- Общий поиск -------------------------------------------------------------- */
.global-search { position: relative; flex: 1 1 200px; min-width: 120px; max-width: 340px; }
.global-search input { width: 100%; height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.gs-dropdown:not(:empty) {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(480px, calc(100vw - 32px)); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 16px 34px rgba(0, 0, 0, .18); padding: 8px; z-index: 30;
}
.gs-groups { display: grid; gap: 8px; }
.gs-group h3 { margin: 4px 8px; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.gs-item { display: grid; gap: 1px; padding: 6px 8px; border-radius: 8px; color: var(--text); }
.gs-item:hover, .gs-item:focus { background: var(--accent-soft); text-decoration: none; }
.gs-empty { margin: 8px; }
.gs-all { display: block; padding: 8px; text-align: right; }
.gs-page .gs-groups { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.gs-page .gs-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
.topbar { gap: 16px; }
.brand { white-space: nowrap; flex: none; }
.topnav { overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { white-space: nowrap; }
@media (max-width: 1279px) { .brand span { display: none; } .global-search { max-width: 240px; } }
.merge-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.feedback { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 2px; color: var(--muted); }
.feedback-summary { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 8px; }

/* --- Договоры ------------------------------------------------------------------ */
.contract-progress { position: sticky; top: 60px; z-index: 5; margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); }
.contract-field.is-empty input { border-color: var(--accent); background: var(--accent-soft); }
.contract-field small { overflow-wrap: anywhere; }

/* --- Планы ---------------------------------------------------------------------- */
.plan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.plan-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.plan-row .progress, .plan-row > small { grid-column: 1 / -1; margin: 0; }
.plan-name { font-weight: 600; color: var(--text); }
.plan-nums { font-variant-numeric: tabular-nums; }
.progress.is-over > span { background: var(--danger); }

/* Telegram-канал */
.channel-dayhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.channel-dayhead h2 { margin: 0; text-align: center; }
.channel-posts { display: grid; gap: 10px; }
.channel-post { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.channel-post.channel-skipped { opacity: .6; }
.channel-post.channel-error { border-color: var(--danger); }
.channel-post-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.channel-state { margin-left: auto; font-size: .9rem; }
.channel-text { width: 100%; white-space: pre-wrap; font: inherit; font-size: .92rem; line-height: 1.45; }
.channel-preview { white-space: pre-wrap; margin: 8px 0 0; padding: 10px; border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; }
pre.channel-text { margin: 8px 0 0; padding: 10px; border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; }
.channel-actions { margin-top: 6px; }
.channel-actions > * { flex: 0 0 auto; }
.channel-weekday { margin: 18px 0 6px; font-size: 1rem; }
.channel-slot { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px 0; border-bottom: 1px solid var(--border); }
.channel-slot .channel-wide { grid-column: 1 / -1; }
.channel-slot-actions { display: flex; gap: 8px; align-items: end; grid-column: 1 / -1; }
@media (min-width: 900px) {
  .channel-slot { grid-template-columns: 130px minmax(200px, 2fr) repeat(4, minmax(70px, 1fr)) auto; align-items: end; }
  .channel-slot .channel-wide { grid-column: auto; }
  .channel-slot-actions { grid-column: auto; }
}

.roi-summary { margin: 0 0 12px; line-height: 1.5; }
