/* ============================================================
   HATA CRM — UI-компоненти v2 (світла тема, десктоп-first)
   Будується ТІЛЬКИ на tokens.css. Жодних хардкод-кольорів.
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--text-strong); margin: 0 0 var(--space-sm); font-weight: 650; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--primary-soft); }

/* --- Кнопки --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.5rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-strong);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-dim); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--text-on-brand); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-strong); }
.btn-danger { background: var(--status-danger-soft); border-color: var(--status-danger); color: var(--status-danger); }
.btn-ghost-danger { background: transparent; border-color: transparent; box-shadow: none; color: var(--status-danger); font-size: var(--text-xs); }
.btn-ghost-danger:hover { background: var(--status-danger-soft); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn { padding: 0.45rem; border-radius: var(--radius-sm); }

/* --- Картки --- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

/* KPI-картки */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
}
.kpi { padding: var(--space-md) var(--space-lg); }
.kpi-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { font-size: var(--text-xl); font-weight: 750; color: var(--text-strong); margin-top: var(--space-xs); white-space: nowrap; }
.kpi-value.good { color: var(--status-success); }
.kpi-value.bad { color: var(--status-danger); }
.kpi-sub { font-size: var(--text-xs); color: var(--text-dim); margin-top: var(--space-2xs); }

/* --- Бейджі --- */
.badge {
  display: inline-block;
  padding: 0.16rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 650;
  white-space: nowrap;
}
.badge-success { background: var(--status-success-soft); color: var(--status-success); }
.badge-warning { background: var(--status-warning-soft); color: var(--status-warning); }
.badge-danger  { background: var(--status-danger-soft);  color: var(--status-danger); }
.badge-info    { background: var(--status-info-soft);    color: var(--status-info); }
.badge-neutral { background: var(--surface-3); color: var(--text-muted); }

/* --- Таблиці --- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--line-strong);
  white-space: nowrap;
}
.table td {
  padding: 0.65rem var(--space-md);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--text-primary);
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.clickable { cursor: pointer; }

/* --- Форми --- */
.form-control {
  padding: 0.5rem 0.75rem;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-strong);
  font-family: inherit;
  font-size: var(--text-sm);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-label { display: block; font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-xs); }

/* --- Іконки --- */
.icon-16 { width: 16px; height: 16px; flex-shrink: 0; }
.icon-20 { width: 20px; height: 20px; flex-shrink: 0; }
.icon-24 { width: 24px; height: 24px; flex-shrink: 0; }

/* ============================================================
   Оболонка: sidebar + topbar + контент
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: var(--z-nav);
  transition: transform var(--transition-base);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  font-size: var(--text-md);
  font-weight: 750;
  color: var(--text-strong);
  border-bottom: 1px solid var(--line);
  letter-spacing: -0.01em;
}
.sidebar-logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 8px var(--primary-glow); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--space-sm); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 2px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-item:hover { background: var(--surface-2); color: var(--text-strong); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 650; }
.sidebar-footer { padding: var(--space-md); border-top: 1px solid var(--line); font-size: var(--text-xs); color: var(--text-dim); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
}
.topbar-title { font-size: var(--text-md); font-weight: 700; color: var(--text-strong); margin-right: auto; }
.content { padding: var(--space-lg); flex: 1; }
.screen { display: none; }
.screen.active { display: block; }

.burger { display: none; }
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: calc(var(--z-nav) - 1);
}

/* ============================================================
   Шахматка
   ============================================================ */
.cal-wrap {
  overflow: auto;
  max-height: calc(100vh - var(--topbar-height) - 130px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  box-shadow: var(--shadow-sm);
}
.cal-row {
  display: grid;
  grid-template-columns: var(--cal-first-col) repeat(var(--cal-days, 31), var(--cal-cell-w));
  min-width: max-content;
}
/* Все в один грід-рядок: стикові броні перекриваються в колонці дня виїзду,
   без цього грід перекидає другу смугу на новий рядок */
.cal-row > * { grid-row: 1; }
.cal-row:not(:last-child) { border-bottom: 1px solid var(--line); }
.cal-row.head {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  z-index: 3;
  border-bottom: 2px solid var(--line-strong);
}
.cal-head-cell {
  height: var(--cal-cell-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--text-primary);
  border-left: 1px solid var(--line);
}
.cal-head-cell .dow { font-size: var(--text-2xs); font-weight: 500; color: var(--text-dim); }
.cal-head-cell.weekend { background: var(--cal-weekend); }
.cal-head-cell.today { background: var(--cal-today); color: var(--primary-strong); }
.cal-head-cell.today .dow { color: var(--primary-strong); }
.cal-apt {
  display: flex;
  align-items: center;
  padding: 0 var(--space-sm);
  height: var(--cal-cell-h);
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--text-strong);
  position: sticky;
  left: 0;
  background: var(--surface-1);
  border-right: 2px solid var(--line-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 2;
}
.cal-row.head .cal-apt { z-index: 4; }
.cal-cell {
  height: var(--cal-cell-h);
  border-left: 1px solid var(--line);
}
.cal-cell.weekend { background: var(--cal-weekend); }
.cal-cell.today { background: var(--cal-today); }
.cal-span {
  height: calc(var(--cal-cell-h) - 10px);
  margin: 5px 0; /* без бічних зазорів — стикові броні зустрічаються опівдні, як у старій CRM */
  border-radius: 8px;
  background: var(--cal-span-confirmed);
  color: var(--text-on-brand);
  font-size: var(--text-2xs);
  font-weight: 650;
  display: flex;
  align-items: center;
  padding: 0 var(--space-sm);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: filter var(--transition-fast), box-shadow var(--transition-fast);
}
.cal-span:hover { filter: brightness(1.08); box-shadow: var(--shadow-md); }
/* Готельні пів-дні: смуга від середини дня заїзду до середини дня виїзду.
   Колонки смуги включають день виїзду (+1 у JS), а краї зрізаються на пів клітинки.
   position+z-index — щоб смуга лежала ПОВЕРХ вільної клітинки дня виїзду (низ sticky-колонок). */
.cal-span { position: relative; z-index: 1; }
.cal-span.half-start { margin-left: calc(var(--cal-cell-w) / 2); }
.cal-span.half-end { margin-right: calc(var(--cal-cell-w) / 2); }
/* Погодинний слот: вузька смужка в межах дня, ширина/позиція = час (ставить calendar.js) */
.cal-span-hourly {
  min-width: 10px;
  font-size: 0.62rem;
  justify-content: center;
  padding: 0 1px;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, #fff 40%, transparent);
  border-radius: 4px;
}
.cal-span.status-pending {
  background: repeating-linear-gradient(-45deg, #f59e0b, #f59e0b 5px, #fbbf24 5px, #fbbf24 10px);
  opacity: 0.88;
  z-index: 2; /* заявка лягає ПОВЕРХ броні — конфлікт дат видно одразу */
  color: rgba(30, 20, 0, 0.9);
}
.cal-span.status-other { background: var(--cal-span-other); }
.cal-span.status-done { background: var(--text-dim); opacity: 0.75; } /* сірий = виїхав */
/* Притримка (soft-hold): ОКРЕМА смуга-хвіст на захолджених днях (не вся бронь).
   Штрихована бурштинова = «слот притримано»; сама бронь лишається бірюзовою. */
.cal-span.cal-span-hold {
  background: repeating-linear-gradient(45deg, #fcd34d, #fcd34d 6px, #fef3c7 6px, #fef3c7 12px);
  box-shadow: inset 0 0 0 2px #f59e0b;
  color: #92400e;
  font-weight: 650;
  justify-content: center;
  opacity: 0.96;
}

/* --- Легенда --- */
.legend { display: flex; gap: var(--space-md); align-items: center; font-size: var(--text-xs); color: var(--text-muted); flex-wrap: wrap; }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: var(--space-xs); vertical-align: -1px; }
.swatch.sw-confirmed { background: var(--cal-span-confirmed); }
.swatch.sw-pending { background: var(--cal-span-pending); }
.swatch.sw-other { background: var(--cal-span-other); }
.swatch.sw-living { background: var(--cal-span-other); }
.swatch.sw-done { background: var(--text-dim); opacity: 0.75; }

/* ============================================================
   Бічна картка броні (drawer)
   ============================================================ */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 92vw;
  height: 100vh;
  height: 100dvh; /* мобільні: 100vh лізе під адресний рядок браузера — низ дровера зникає */
  background: var(--surface-1);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-drawer);
  transform: translateX(105%);
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
  /* iOS: fixed+transform інколи лишає «привид» шару при скролі — гасимо */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.drawer.open { transform: translateX(0); }
@media (min-width: 1280px) {
  .drawer { width: 440px; }
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--line);
}
.drawer-body { padding: var(--space-lg); overflow-y: auto; flex: 1; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* --- Вміст картки броні: шапка гостя, смуга заїзд→виїзд, грошовий блок --- */
.bk-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-sm); margin-bottom: var(--space-md); }
.bk-guest { min-width: 0; }
.bk-name { font-size: var(--text-lg); font-weight: 700; color: var(--text-strong); line-height: 1.25; word-break: break-word; }
.bk-phone { font-size: var(--text-sm); font-weight: 600; }
.bk-head .badge { flex-shrink: 0; margin-top: 0.2rem; }

.bk-stay {
  display: flex;
  align-items: stretch;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}
.bk-stay-col { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.bk-stay-right { text-align: right; align-items: flex-end; }
.bk-stay-label { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.bk-stay-date { font-size: var(--text-sm); font-weight: 700; color: var(--text-strong); white-space: nowrap; }
.bk-stay-time { font-size: var(--text-xs); color: var(--text-muted); }
.bk-stay-mid { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; }
.bk-stay-nights { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.bk-stay-line { width: 100%; max-width: 90px; height: 1px; background: var(--line-strong); }
.bk-stay-rate { font-size: var(--text-2xs); color: var(--text-dim); white-space: nowrap; }

.bk-money {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-md);
}
.bk-money-cell { padding: var(--space-sm) var(--space-md); display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bk-money-cell + .bk-money-cell { border-left: 1px solid var(--line); }
.bk-money-cell span { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.bk-money-cell b { font-size: var(--text-sm); color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-money-cell.debt { background: var(--status-danger-soft); }
.bk-money-cell.debt b { color: var(--status-danger); }

.field-row { display: flex; justify-content: space-between; gap: var(--space-md); padding: 0.55rem 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.field-row:last-child { border-bottom: none; }
.field-label { color: var(--text-muted); flex-shrink: 0; }
.field-value { color: var(--text-strong); font-weight: 600; text-align: right; word-break: break-word; }

/* ============================================================
   Міні-графік (CSS-бари, без chart.js)
   ============================================================ */
.bars { display: flex; align-items: flex-end; gap: var(--space-sm); height: 160px; padding-top: var(--space-md); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); min-width: 0; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; flex: 1; }
.bar { width: 12px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.income { background: var(--primary); }
.bar.expense { background: var(--status-danger); opacity: 0.75; }
.bar-label { font-size: var(--text-2xs); color: var(--text-dim); }
.bar-col.current .bar-label { color: var(--primary-strong); font-weight: 700; }

/* --- Оверлей "потрібен вхід", порожні стани --- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}
.empty-state { padding: var(--space-2xl); text-align: center; color: var(--text-muted); }
.empty-state.error-state { color: var(--status-danger); }

/* Друк картки броні: видно лише вміст дровера, без кнопок дій */
@media print {
  body.print-booking * { visibility: hidden; }
  body.print-booking #drawer, body.print-booking #drawer * { visibility: visible; }
  body.print-booking #drawer {
    position: absolute; inset: 0; width: 100%; max-width: none;
    box-shadow: none; border: none; transform: none;
  }
  body.print-booking #drawer-actions, body.print-booking #drawer-close { display: none; }
}

/* Панель фільтрів */
.filters { display: flex; gap: var(--space-sm); align-items: center; flex-wrap: wrap; }

/* Список карток людей */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-md); }
.person-name { font-weight: 700; color: var(--text-strong); }
.person-meta { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-2xs); }

/* ============================================================
   Мобільна адаптація (той самий код, менша ширина)
   ============================================================ */
@media (max-width: 920px) {
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-105%);
    box-shadow: var(--shadow-lg);
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .backdrop { display: block; }
  .burger { display: inline-flex; }
  .topbar {
    padding: var(--space-xs) var(--space-md);
    height: auto;
    min-height: var(--topbar-height);
    flex-wrap: wrap;
    row-gap: var(--space-xs);
  }
  body { overflow-x: hidden; }
  .content { padding: var(--space-md); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { min-width: 0; padding: var(--space-md); }
  .kpi-value { white-space: normal; font-size: var(--text-lg); }
  .cal-wrap { max-height: calc(100vh - var(--topbar-height) - 110px); }
  .drawer { width: 100vw; max-width: 100vw; }
  .bars { height: 120px; gap: var(--space-xs); }
  .bar { width: 7px; }
  .bar-pair { gap: 2px; }
}

/* ============================================================
   v3 — додатки: модалка, секції меню, дії у дровері, індикатори
   ============================================================ */

/* Секції бічного меню */
.nav-section {
  padding: var(--space-md) 0.75rem var(--space-xs);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Модалка (створення броні) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: var(--z-modal);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh var(--space-md) var(--space-md);
  overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 100%;
  /* Форма виросла (тип броні + часи погодинки) — на телефоні модалка обрізала поля
     без скролу (баг Віталія 06.07: «погодинно нема де ім'я вставлять») */
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--line);
}
.modal-body { padding: var(--space-lg); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; min-height: 0; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--line);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.form-grid .span-2 { grid-column: span 2; }
.form-hint { font-size: var(--text-xs); color: var(--text-dim); margin-top: var(--space-2xs); }
.form-error { font-size: var(--text-sm); color: var(--status-danger); font-weight: 600; }

/* Індикатор боргу на смузі броні */
.cal-span.has-debt::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-danger-soft);
  border: 2px solid var(--status-danger);
  margin-right: var(--space-xs);
  flex-shrink: 0;
}
/* Порожня клітинка: підказка що можна створити бронь */
.cal-cell.free { cursor: pointer; transition: background var(--transition-fast); }
.cal-cell.free:hover { background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }

/* Списки на екрані «Сьогодні» */
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
  cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-2); }
.list-time { font-family: var(--font-mono); font-weight: 700; color: var(--text-strong); width: 52px; flex-shrink: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 650; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: var(--text-xs); color: var(--text-muted); }

/* Смужка частки (аналітика по джерелах) */
.share-track { background: var(--surface-3); border-radius: var(--radius-full); height: 8px; min-width: 90px; overflow: hidden; }
.share-fill { height: 100%; background: var(--primary); border-radius: var(--radius-full); }

/* Дії у дровері */
.drawer-actions { padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--space-sm); overflow-y: auto; min-height: 0; }
.drawer .drawer-body { min-height: 140px; } /* шапка гостя видима навіть з розгорнутою формою; решту площі віддаємо діям */
/* Дрібні дії (виїхав/прибрано/копіювати/друк/кабінет) — 2 колонки замість стосу full-width кнопок */
.drawer-actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-xs) var(--space-sm); }
.drawer-actions-grid .btn { width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.drawer-actions-pair { display: flex; gap: var(--space-2xs); grid-column: 1 / -1; }
.drawer-actions-pair .btn-ghost { flex-shrink: 0; width: auto; padding-left: 0.6rem; padding-right: 0.6rem; }
@media (max-width: 920px) {
  .drawer-actions-grid { grid-template-columns: 1fr; }
}
.pay-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}
.pay-form .span-2 { grid-column: span 2; }
/* Інпут без ширини розпирає грід-колонку вправо за край дровера — тому завжди 100%.
   appearance:none — iOS Safari інакше не дає date/time-інпутам стискатись (вилазили за край),
   а порожні time-інпути мали іншу висоту; min-height вирівнює всі поля під одну лінійку */
.pay-form .form-control {
  width: 100%;
  min-width: 0;
  min-height: 2.6rem;
  -webkit-appearance: none;
  appearance: none;
}
.pay-form select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
}
.pay-form input[type="date"], .pay-form input[type="time"] { display: block; }
.pay-form > label { min-width: 0; }
.pay-form .form-label { margin-bottom: var(--space-2xs); }
/* Заголовок секції всередині довгої форми (Дати й час / Гроші / Інше) */
.form-section {
  grid-column: 1 / -1;
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-top: 1px dashed var(--line-strong);
  padding-top: var(--space-sm);
  margin-top: var(--space-2xs);
}
.form-section:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); align-items: start; }
.two-col > * { min-width: 0; } /* інакше широка таблиця розпирає колонку замість скролу в table-wrap */
@media (max-width: 920px) {
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}

/* ============================================================
   v3.1 — глобальний пошук у топбарі
   ============================================================ */
.search-box { position: relative; width: 300px; }
.search-box .form-control { width: 100%; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-modal);
  max-height: 380px;
  overflow-y: auto;
}
.search-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.search-row:last-child { border-bottom: none; }
.search-row:hover { background: var(--surface-2); }
.search-empty { padding: var(--space-md); color: var(--text-muted); font-size: var(--text-sm); }
.help-list { margin: var(--space-sm) 0 0; padding-left: var(--space-lg); display: grid; gap: var(--space-xs); }
.help-list li { line-height: 1.45; }

/* Ціни і знижки: стрічка ночей у картці квартири */
.price-strip { display: flex; gap: var(--space-xs); overflow-x: auto; padding-bottom: var(--space-xs); }
.price-cell {
  min-width: 64px;
  padding: var(--space-xs);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.price-cell.weekend { background: var(--cal-weekend); }
.price-cell.has-disc { border-color: var(--status-warning); background: var(--status-warning-soft); }
.price-cell-day { font-size: var(--text-2xs); color: var(--text-dim); white-space: nowrap; }
.price-cell-val { font-weight: 700; font-size: var(--text-sm); }
.price-cell-tag { font-size: var(--text-2xs); color: var(--status-warning); font-weight: 600; }

/* Лічильник нових заявок у меню */
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--status-danger);
  color: #fff;
  font-size: var(--text-2xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.search-group {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
@media (max-width: 920px) {
  .search-box { display: none; }
}

/* ============================================================
   v3.2 — історія платежів у дровері + мобільний таб-бар
   ============================================================ */
.pay-history-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: var(--space-lg) 0 var(--space-xs);
  padding-top: var(--space-md);
  border-top: 2px solid var(--line-strong);
}
.pay-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
}
.pay-row:last-child { border-bottom: none; }
.pay-row-main { flex: 1; min-width: 0; }
.pay-row > .btn, .pay-row > .badge { flex-shrink: 0; }

.good { color: var(--status-success); }
.bad { color: var(--status-danger); }

.tabbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface-1);
  border-top: 1px solid var(--line);
  z-index: var(--z-nav);
  /* iOS: кнопки над home-індикатором, але втоплені (env−22px) — калібровано
     Віталієм на реальному айфоні (тест v1-v3: 34px = «пробіл», 20px = «зависоко») */
  padding-bottom: max(calc(env(safe-area-inset-bottom, 0px) - 22px), 2px);
  box-shadow: var(--shadow-lg);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 5px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.tab-item.active { color: var(--primary-strong); }

@media (max-width: 920px) {
  .tabbar { display: flex; }
  .content { padding-bottom: calc(64px + var(--space-md)); }
  .drawer { padding-top: env(safe-area-inset-top, 0px); padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  /* <16px в інпуті = мобільний браузер зумить сторінку при фокусі і верстка їде */
  .drawer .form-control { font-size: 16px; }
}

/* ============================================================
   v3.5 — блюр закритих розділів + перемикачі дозволів
   ============================================================ */
.screen.locked { position: relative; min-height: 320px; }
.screen.locked > * {
  filter: blur(7px);
  pointer-events: none;
  user-select: none;
}
.screen.locked::after {
  content: "🔒 Розділ закрито власником";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text-strong);
}
.nav-item.locked { opacity: 0.55; }
.nav-item.locked::after { content: "🔒"; margin-left: auto; font-size: var(--text-xs); }

/* Перемикач (switch) */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
  cursor: pointer;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--surface-1);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.switch input:disabled + .switch-slider { opacity: 0.5; }

/* ============================================================
   v3.9 — фотострічка квартири
   ============================================================ */
.photo-strip { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: center; }
.photo-thumb { position: relative; width: 96px; height: 72px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.photo-thumb:hover .photo-del { opacity: 1; }
.photo-add {
  width: 96px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: var(--text-xl);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.photo-add:hover { border-color: var(--primary); color: var(--primary); }

/* ---- Сервіси: хаб профі-модулів (конструктор) ---- */
.services-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--space-md); }
.service-tile {
  display: flex; align-items: center; gap: var(--space-md);
  padding: var(--space-lg);
  text-decoration: none; color: inherit; cursor: pointer;
  border: 1px solid var(--line);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  position: relative;
}
.service-tile::after {
  content: "→"; position: absolute; right: var(--space-lg); color: var(--text-dim);
  font-weight: 700; opacity: 0; transform: translateX(-6px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.service-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.service-tile:hover::after { opacity: 1; transform: translateX(0); }
.service-icon {
  font-size: 1.5rem; line-height: 1; flex-shrink: 0;
  width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); border-radius: var(--radius-md);
}
.service-name { font-weight: 700; color: var(--text-strong); }
.service-note { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

/* ---- Агенти: робочий меседжер (чат-лейаут, v3.47) ---- */
.ag-shell { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-height) - 2 * var(--space-lg)); min-height: 320px; }
.ag-top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.ag-search { max-width: 180px; flex-shrink: 0; }
.ag-filter { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; flex: 1; }
.ag-filter::-webkit-scrollbar { display: none; }
.ag-filter .chip { font-size: .78rem; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-1); cursor: pointer; white-space: nowrap; flex-shrink: 0; color: var(--text); }
.ag-filter .chip.active { background: var(--brand, #0d9488); color: #fff; border-color: transparent; }
.ag-feed { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md); }
.ag-day { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; }
.ag-day::before, .ag-day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.ag-day span { font-size: .7rem; color: var(--text-muted); white-space: nowrap; }
.ag-msg { display: flex; gap: 8px; align-items: flex-start; max-width: 88%; }
.ag-msg .ag-body { background: var(--surface-1); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 7px 11px; min-width: 0; box-shadow: var(--shadow-sm); }
.ag-msg.ag-mine { align-self: flex-end; flex-direction: row-reverse; }
.ag-msg.ag-mine .ag-body { background: var(--brand-soft, rgba(13,148,136,.12)); border-radius: 14px 4px 14px 14px; }
.ag-msg.ag-unread .ag-body { border-left: 3px solid var(--brand, #0d9488); }
.ag-msg.ag-withdrawn-msg .ag-body { opacity: .72; }
.ag-withdrawn { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--line); color: var(--text-muted); font-size: .78rem; }
.ag-withdrawn strong { color: var(--text-strong); }
.ag-avatar { font-size: 1.15rem; line-height: 1.6; flex-shrink: 0; }
.ag-head { font-size: .72rem; color: var(--text-muted); margin-bottom: 2px; display: flex; gap: 6px; align-items: baseline; }
.ag-names { font-weight: 600; color: var(--text-strong); }
.ag-arrow { color: var(--text-muted); font-weight: 400; }
.ag-time { font-variant-numeric: tabular-nums; }
.ag-prio { color: #d33; font-weight: 800; }
.ag-text { white-space: pre-wrap; word-break: break-word; font-size: .875rem; line-height: 1.45; }
.ag-compose { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; flex-wrap: nowrap; }
.ag-compose select { width: 140px; flex-shrink: 0; }
.ag-compose textarea { flex: 1; min-width: 0; resize: none; min-height: 2.5rem; max-height: 7rem; border-radius: 18px; padding: 10px 14px; }
.ag-compose .btn { flex-shrink: 0; height: 2.5rem; width: 2.5rem; border-radius: 50%; font-size: 1rem; padding: 0; display: flex; align-items: center; justify-content: center; }
@media (max-width: 640px) {
  .ag-shell { height: calc(100dvh - var(--topbar-height) - 64px - 2 * var(--space-md)); }
  .ag-top { flex-direction: column; align-items: stretch; gap: 6px; }
  .ag-search { max-width: none; }
  .ag-msg { max-width: 96%; }
  .ag-compose select { width: 110px; font-size: 16px; }
  .ag-compose textarea { font-size: 16px; } /* 16px = без iOS-зуму */
  .ag-to-label { font-size: .8rem; }
}

/* ---- Легенда шахматки внизу, на телефоні непомітна (Віталій 04.07) ---- */
.cal-legend-row { opacity: 0.85; }
@media (max-width: 640px) {
  .cal-legend-row { font-size: 10px; opacity: 0.7; }
  .cal-legend-row .legend { gap: 8px; }
  .cal-legend-row .legend-hint { display: none; } /* довга підказка зʼїдала екран */
  .cal-legend-row .swatch { width: 9px; height: 9px; }
}

/* ---- v3.41: анти-«гума» на iOS (Віталій: тягнеться у всі боки) ----
   Мобільний = застосунок-каркас: сторінка НЕ скролиться взагалі,
   скрол живе тільки всередині .content (вертикальний) і .cal-wrap (шахматка). */
html, body { overscroll-behavior: none; }
@media (max-width: 640px) {
  /* iOS Safari auto-zooms focused controls whose text is smaller than 16px. */
  .form-control,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* Без position:fixed — у Telegram/in-app webview воно зсуває полотно.
     Ланцюжок height:100% + overflow:hidden дає той самий замок безпечно. */
  html, body { height: 100%; overflow: hidden; }
  .shell { height: 100%; min-height: 0; overflow: hidden; }
  .main { height: 100%; overflow: hidden; }
  .content {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none; /* без відскоку і без протікання на сторінку */
    min-height: 0;
    flex: 1;
  }
  .cal-wrap {
    overscroll-behavior: none;
    max-height: calc(100dvh - var(--topbar-height) - 150px);
  }
  .ag-feed { overscroll-behavior: none; }
}

/* ---- Дід Коля: задачі й закупівлі ---- */
.dk-task { display: flex; gap: var(--space-md); justify-content: space-between; align-items: flex-start; margin-bottom: var(--space-sm); border-left: 4px solid var(--line-strong); }
.dk-task.dk-urgent { border-left-color: var(--status-danger); }
.dk-task.dk-strategic { border-left-color: var(--status-info); }
.dk-task.dk-done { opacity: .65; }
.dk-task-main { min-width: 0; flex: 1; }
.dk-title { font-weight: 700; color: var(--text-strong); margin-bottom: var(--space-xs); }
.dk-title .dk-id { color: var(--text-dim); font-weight: 500; font-size: var(--text-xs); margin-right: 4px; }
.dk-meta { display: flex; gap: var(--space-sm); flex-wrap: wrap; font-size: var(--text-xs); color: var(--text-muted); align-items: center; }
.dk-desc { font-size: var(--text-sm); margin-top: var(--space-sm); white-space: pre-wrap; color: var(--text-primary); }
.dk-age-hot { color: var(--status-danger); font-weight: 700; }
.dk-actions { display: flex; flex-direction: column; gap: var(--space-xs); flex-shrink: 0; }
.dk-add { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.dk-add .span-2 { grid-column: span 2; }
@media (max-width: 640px) {
  .dk-task { flex-direction: column; }
  .dk-actions { flex-direction: row; flex-wrap: wrap; }
  .dk-add { grid-template-columns: 1fr; }
  .dk-add .span-2 { grid-column: span 1; }
}

.ag-to-label { flex-shrink: 0; font-size: .85rem; font-weight: 650; color: var(--brand, #0d9488); padding: 0 4px; align-self: center; white-space: nowrap; }

/* ---- OLX / Google Ads ---- */
.olx-apt { font-weight: 650; color: var(--text-strong); }
.th-sub { display: block; font-size: 0.65rem; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-dim); }
#olx-table td.num, #olx-table th.num, #gads-campaigns td.num, #gads-days td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi-value.kpi-bad { color: var(--status-danger); }

/* ---- Аналітика Pro ---- */
.ap-cash-now { font-size: var(--text-md); margin-bottom: var(--space-sm); }
.ap-cash-now b { font-size: var(--text-lg); color: var(--text-strong); }
.ap-cash-delta { font-size: var(--text-xs); font-weight: 650; margin-left: 8px; }
.ap-cash-delta.good { color: var(--status-success); }
.ap-cash-delta.bad { color: var(--status-danger); }
.ap-spark { display: flex; align-items: flex-end; gap: 3px; height: 72px; }
.ap-spark-bar { flex: 1; min-width: 4px; background: var(--primary); opacity: .75; border-radius: 3px 3px 0 0; transition: opacity var(--transition-fast); }
.ap-spark-bar:hover { opacity: 1; }
.ap-flag { padding: var(--space-sm) 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.ap-flag:last-child { border-bottom: none; }
.ap-flag b { display: block; color: var(--text-strong); }
.ap-flag .muted { font-size: var(--text-xs); }
.ap-flag-hot b::before { content: "🔥 "; }

/* ---- Аналітика Pro v2: графіки і «кров» ---- */
.ap-chart { height: 96px; margin-top: var(--space-sm); }
.ap-spark-sm { height: 40px; margin-top: var(--space-sm); }
.ap-bar-alt { background: var(--status-info); }
.ap-section-title { margin: var(--space-md) 0 var(--space-sm); font-size: var(--text-md); color: var(--text-strong); }
.ap-h4 { margin: var(--space-md) 0 var(--space-xs); font-size: var(--text-sm); color: var(--text-strong); }
.ap-h4:first-child { margin-top: 0; }
.ap-none { font-size: var(--text-xs); padding: 2px 0 6px; }
.ap-flag span { display: block; }
.kpi-sub.bad, .ap-flag .bad { color: var(--status-danger); font-weight: 650; }
.kpi-sub.good { color: var(--status-success); }
.ap-bonus-bar { height: 10px; background: var(--surface-3); border-radius: var(--radius-full); overflow: hidden; margin: var(--space-xs) 0; }
.ap-bonus-fill { height: 100%; background: var(--primary); border-radius: var(--radius-full); }

/* ---- KPI динаміка (як на старому дашборді) ---- */
.ap-kpi-chart-wrap { position: relative; height: 300px; margin-top: var(--space-sm); }
.ap-kpi-controls { align-items: center; }
.ap-toggle { display: flex; gap: 6px; align-items: center; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; cursor: pointer; }
.kpi-info-btn { border: 1px solid var(--line-strong); background: transparent; color: var(--text-muted); border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: .8rem; line-height: 1; }
.kpi-info-box { font-size: var(--text-xs); color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-sm) var(--space-md); margin-top: var(--space-sm); line-height: 1.6; }
.ap-c-blue { color: #3b82f6; } .ap-c-green { color: #10b981; } .ap-c-orange { color: #f59e0b; }
@media (max-width: 640px) { .ap-kpi-chart-wrap { height: 220px; } }

/* ---- Динаміка v2: метрики-картки як перемикачі графіка ---- */
.ap-period-chips { flex: 0 0 auto; }
.ap-metric-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-sm); margin: var(--space-sm) 0; }
.ap-mcard {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md); cursor: pointer; text-align: left;
  background: var(--surface-1); transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.ap-mcard:hover { border-color: var(--m-color, var(--primary)); }
.ap-mcard.active { border-color: var(--m-color, var(--primary)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--m-color, var(--primary)) 15%, transparent); }
.ap-mcard-name { font-size: var(--text-xs); font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.ap-mcard-row { display: flex; align-items: baseline; gap: 8px; }
.ap-mcard { min-height: 108px; justify-content: space-between; }
.ap-mcard-delta { min-height: 1.15em; }
.ap-mcard-value { font-size: var(--text-lg); font-weight: 750; color: var(--text-strong); }
.ap-mcard-delta { font-size: var(--text-xs); font-weight: 700; }
.ap-mcard-delta.up { color: var(--status-success); }
.ap-mcard-delta.down { color: var(--status-danger); }
.ap-mcard-spark { display: flex; align-items: flex-end; gap: 2px; height: 26px; margin-top: 4px; }
.ap-mcard-spark i { flex: 1; background: var(--m-color, var(--primary)); opacity: .5; border-radius: 2px 2px 0 0; min-width: 2px; }
.ap-mcard.active .ap-mcard-spark i { opacity: .85; }
@media (max-width: 640px) {
  .ap-metric-cards { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .ap-mcard { padding: 8px; min-height: 92px; }
  .ap-mcard-value { font-size: var(--text-md); }
  .ap-mcard-spark { height: 18px; }
}

/* Динаміка: короткі підписи на мобільному — без ламання в 3 рядки */
.mn-short { display: none; }
@media (max-width: 640px) {
  .mn-full { display: none; }
  .mn-short { display: inline; }
  .ap-delta-tail { display: none; }
  .ap-mcard-row { flex-wrap: wrap; gap: 2px 6px; }
}

/* iOS: подвійний тап по кнопках/чипах зумив сторінку — вимикаємо (пінч-зум лишається) */
button, .chip, .ap-mcard, .nav-item, .cal-span, .service-tile, .cal-cell, .ag-msg, select, .tabbar a, .tabbar button { touch-action: manipulation; }
@media (max-width: 640px) { body { touch-action: manipulation; } }

/* ---- HR: kanban найму ---- */
.hr-kpi { flex: 1; min-width: 0; }
.hr-board { display: flex; gap: var(--space-md); overflow-x: auto; align-items: flex-start; padding-bottom: var(--space-sm); }
.hr-col { flex: 0 0 272px; min-width: 0; }
.hr-col-head { display: flex; justify-content: space-between; font-size: var(--text-sm); font-weight: 700; color: var(--text-strong); margin-bottom: var(--space-sm); }
.hr-count { color: var(--text-muted); font-weight: 650; }
.hr-card { padding: var(--space-sm) var(--space-md); margin-bottom: var(--space-sm); }
.hr-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; cursor: pointer; }
.hr-name { font-weight: 650; color: var(--text-strong); min-width: 0; overflow-wrap: anywhere; }
.hr-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.hr-src { color: var(--primary); font-weight: 650; }
.hr-move { display: flex; gap: 6px; margin-top: var(--space-sm); }
.hr-move .btn { flex: 1; font-size: .72rem; padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hr-detail { border-top: 1px solid var(--line); margin-top: var(--space-sm); padding-top: var(--space-sm); display: flex; flex-direction: column; gap: 6px; }
.hr-fact-line { font-size: var(--text-sm); }
.hr-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--text-xs); }
.hr-fact b { color: var(--text-strong); font-weight: 650; }
.hr-flags { color: var(--status-danger); font-size: var(--text-xs); font-weight: 650; }
.hr-lbl { font-size: var(--text-xs); color: var(--text-muted); }
.hr-score { width: 68px; display: inline-block; margin-left: 6px; }
.hr-detail-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hr-msgs { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.hr-msg { font-size: var(--text-xs); background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px 8px; }
.hr-msg.ours { border-left: 3px solid var(--primary); }
.hr-msg-who { font-weight: 650; color: var(--text-strong); margin-right: 4px; }
.hr-empty { padding: var(--space-md) 0; font-size: var(--text-xs); }
.hr-stages { display: none; }
@media (max-width: 640px) {
  .hr-kpi { width: 100%; grid-template-columns: 1fr 1fr; gap: 6px; }
  .hr-kpi .kpi { padding: 8px 12px; }
  .hr-kpi .kpi-value { font-size: var(--text-md); margin-top: 0; }
  #hr-add-toggle { width: 100%; }
  .hr-stages { display: flex; }
  .hr-board { display: block; overflow-x: visible; }
  .hr-col { display: none; }
  .hr-col.sel { display: block; }
  .hr-col-head { display: none; } /* лічильник уже на чіпі */
}

/* ---- Система: сервіси і крони ---- */
.sys-help { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-1); padding: var(--space-sm) var(--space-md); font-size: var(--text-sm); }
.sys-help summary { cursor: pointer; font-weight: 650; color: var(--text-strong); }
.sys-help-body { margin-top: var(--space-sm); color: var(--text-muted); line-height: 1.6; }
.sys-sched code, .sys-file code { font-size: .72rem; }
.sys-desc { max-width: 420px; }
.sys-edit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sys-edit .form-control { max-width: 200px; font-family: ui-monospace, monospace; }
.sys-edit-cmd { font-size: var(--text-xs); margin-top: 4px; word-break: break-all; }
@media (max-width: 640px) { .sys-desc { max-width: none; } .sys-file { display: none; } }

/* ---- Контакти: телефонна книга ---- */
.ct-search { max-width: 340px; }
.ct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-sm); }
.ct-card { position: relative; padding: var(--space-sm) var(--space-md); }
.ct-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding-right: 34px; }
.ct-name { font-weight: 650; color: var(--text-strong); overflow-wrap: break-word; flex: 1 1 55%; min-width: 0; }
.ct-head .badge { flex: 0 1 auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-notes a { color: var(--primary); }
.ct-links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--text-sm); margin-top: 2px; }
.ct-links a { color: var(--primary); text-decoration: none; }
.ct-notes { font-size: var(--text-xs); margin-top: 4px; line-height: 1.5; }
.ct-edit { position: absolute; top: 8px; right: 8px; padding: 2px 8px; }
@media (max-width: 640px) {
  .ct-search { max-width: none; width: 100%; }
  #ct-add-toggle { width: 100%; }
  .ct-grid { grid-template-columns: 1fr; }
}

/* ---- Відгуки гостей і чайові ---- */
.rv-kpi { flex: 1; min-width: 0; }
.rv-card { padding: var(--space-sm) var(--space-md); margin-bottom: var(--space-sm); }
.rv-head { display: flex; justify-content: space-between; gap: 8px; font-size: var(--text-sm); }
.rv-stars { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: var(--text-sm); margin-top: 4px; }
.rv-star { letter-spacing: 2px; color: var(--status-warning); }
.rv-star.good { color: var(--status-success); }
.rv-star.bad { color: var(--status-danger); }
.rv-comment { font-size: var(--text-sm); font-style: italic; margin-top: 6px; color: var(--text-strong); }
.rv-meta { display: flex; align-items: center; gap: 14px; font-size: var(--text-xs); margin-top: 6px; }
.rv-del { margin-left: auto; padding: 2px 8px; opacity: .6; }
.rv-del:hover { opacity: 1; }
.rv-tips-card { align-self: flex-start; }
.rv-tip { display: flex; justify-content: space-between; gap: 10px; padding: var(--space-sm) 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.rv-tip:last-child { border-bottom: none; }
.rv-tip-sum { color: var(--status-success); white-space: nowrap; }
.kpi-value.good { color: var(--status-success); }
@media (max-width: 640px) {
  .rv-kpi { width: 100%; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .rv-kpi .kpi { padding: 8px 12px; }
  .rv-kpi .kpi-value { font-size: var(--text-md); margin-top: 0; }
  #rv-apt { width: 100%; }
}

/* ---- Контакти v2: агрегована книга (книга + майстри Діда Колі + власники) ---- */
.ct-card.ct-verified { border-left: 4px solid var(--status-success); }
.ct-card.ct-warning { border-left: 4px solid var(--status-warning); }
.ct-notes { white-space: pre-line; }
.ct-src { font-size: var(--text-xs); margin-top: 6px; }
.btn-link.ct-more { border: none; background: none; color: var(--primary); font-size: var(--text-xs); cursor: pointer; padding: 2px 0; }


/* ---- iOS-пакет v3.70 (прийнято Віталієм на тест-полігоні test.html v1→v4) ---- */
.tab-item .icon-20 { width: 23px; height: 23px; }
@media (max-width: 920px) {
  /* Бічне меню: чесний власний скрол; хвіст (Дозволи адміна/Вийти) не під таб-баром */
  .sidebar { height: 100dvh; }
  .sidebar-nav {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  }
}
@media (max-width: 640px) {
  /* Контент не ховається за таб-баром */
  .content { padding-bottom: calc(64px + max(calc(env(safe-area-inset-bottom, 0px) - 22px), 2px)); }
  #manual-receipt-form .manual-receipt-actions {
    flex-direction: column;
    gap: 24px;
  }
  #manual-receipt-form .manual-receipt-actions > .btn {
    width: 100%;
    min-height: 44px;
  }
  /* Шапка: компенсація статус-бару лише у standalone-PWA (у Safari — ні) */
  @media (display-mode: standalone) {
    .topbar { padding-top: env(safe-area-inset-top, 0px); height: auto; min-height: var(--topbar-height); }
  }
  /* Порядок у шапці: ряд 1 — бургер·назва·+бронь·тема; ряд 2 — місяць на всю
     ширину, підпис праворуч (було 3 криві ряди з мертвими зонами) */
  .topbar { row-gap: 4px; }
  .topbar .burger { order: 1; }
  .topbar-title { order: 2; flex: 1 1 auto; }
  #new-booking { order: 3; }
  #theme-toggle { order: 4; }
  .search-box { order: 5; }
  #month-nav { order: 6; flex: 1 1 100%; }
  #month-nav #cal-label { margin-left: auto; }
}

/* ---- Фінанси: графіки v3.71 ---- */
#fin-cash-sub .good, #fin-days-sub .good { color: var(--status-success); }
#fin-cash-sub .bad { color: var(--status-danger); }
#fin-cash-sub, #fin-days-sub { margin-top: 2px; }

/* Меседжер: режим «лише читання» для адміна без agents_write */
.ag-readonly { padding: var(--space-sm) var(--space-md); border-top: 1px solid var(--line); font-size: var(--text-xs); text-align: center; }

/* ---- Покоївки: логістика з ієрархією (v3.75) ---- */
.cl-sec-title { margin: var(--space-md) 0 var(--space-sm); font-size: var(--text-md); font-weight: 700; color: var(--text-strong); }
.cl-cleaner { padding: var(--space-sm) var(--space-md); margin-bottom: var(--space-sm); }
.cl-list { padding: var(--space-xs) var(--space-md); margin-bottom: var(--space-sm); }
.cl-hot { border-left: 4px solid var(--status-danger); }
.cl-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: var(--space-sm) 0; border-bottom: 1px solid var(--line); }
.cl-row:last-child { border-bottom: none; }
.cl-order { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); color: var(--text-muted); font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cl-apt { min-width: 0; overflow-wrap: anywhere; }
.cl-assign { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.cl-sel { max-width: 160px; }
.cl-ctl { display: flex; align-items: center; gap: 2px; margin-left: auto; flex-shrink: 0; }
.cl-ctl .btn { padding: 2px 7px; opacity: .65; }
.cl-ctl .btn:hover { opacity: 1; }
.cl-move { width: 46px; padding: 2px 4px; font-size: .8rem; text-align: center; }
.cl-x { padding: 2px 8px; opacity: .6; }
.cl-pin { padding: 2px 6px; }
.cl-x:hover { opacity: 1; }
.cl-cleaner .cl-row .badge { flex-shrink: 0; }
.cl-rest summary { cursor: pointer; list-style: none; }
.cl-rest summary::before { content: '▸ '; }
.cl-rest[open] summary::before { content: '▾ '; }
@media (max-width: 640px) {
  .cl-assign { margin-left: 0; width: 100%; }
  .cl-sel { max-width: none; flex: 1; }
}

/* Drag-виділення діапазону в шахматці (десктоп-миша) */
.cal-cell.free.drag-sel {
  background: color-mix(in srgb, var(--primary, #3b82f6) 22%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary, #3b82f6) 55%, transparent);
}

/* ============ Постійний клієнт (№4757): бейдж + історія + свічення ============ */
.chip-vip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: .02em;
  color: var(--vip); background: var(--vip-soft);
  border: 1px solid var(--vip-glow); border-radius: var(--radius-full);
  padding: 1px 8px; white-space: nowrap; vertical-align: middle;
}
.chip-newclient {
  display: inline-flex; align-items: center;
  font-size: var(--text-2xs); font-weight: 600;
  color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-full);
  padding: 1px 8px; white-space: nowrap; vertical-align: middle;
}
/* Рядок історії: «4 броні · ⭐4.8 · Львівська …» */
.vip-line { display: block; margin-top: 1px; }
.vip-history { font-size: var(--text-xs); color: var(--text-muted); }
.vip-history b { color: var(--text-strong); font-weight: 600; }
.vip-star { color: var(--vip); font-weight: 600; }
.vip-dot { color: var(--text-dim); }
/* Список заявок: повторний світиться (ліва смуга + мʼякий бурштин) */
.list-row.is-returning {
  background: var(--vip-soft);
  box-shadow: inset 3px 0 0 var(--vip-bar);
  border-radius: var(--radius-sm);
  padding-left: 0.6rem; padding-right: 0.4rem;
}
.list-row.is-returning:hover { background: var(--vip-soft); filter: brightness(0.98); }
/* Дровер: блок історії гостя під шапкою */
.bk-vip-history {
  margin: -0.4rem 0 var(--space-md);
  background: var(--vip-soft); border: 1px solid var(--vip-glow);
  border-radius: var(--radius-sm); padding: 7px 11px;
  font-size: var(--text-xs); color: var(--text-primary); line-height: 1.55;
}
/* Таблиця «Броні»: тиха зірка біля постійного */
.vip-star-cell { color: var(--vip); margin-right: 2px; }
