@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* Feel IT design system — warm neutral foundation + indigo accent (CRM).
     Shared family tokens, see D:/Projects/Brand/feelit-tokens.css */
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f5f3f0;
  --surface-3: #ece8e2;
  --border: #ece8e2;
  --border-strong: #ddd7cd;

  --text: #2a2725;
  --muted: #8a8278;

  --primary: #6b6ee0;          /* softer indigo (was sharper #2f6feb) */
  --primary-700: #4f52c4;
  --primary-soft: #eeeefb;

  --ok: #5fa980;               /* sage instead of vivid green */
  --ok-soft: #ebf3ee;
  --danger: #d96a5f;           /* coral instead of red */
  --danger-soft: #f6e7e4;
  --warn: #c99257;             /* warm amber */
  --warn-soft: #f6ece0;
  --accent: #efe7f5;

  --radius:    12px;           /* was 8px — softer corners */
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* Shadows — multi-layer, lower opacity for a more diffused look. */
  --shadow:     0 1px 2px rgba(40, 35, 30, .05), 0 4px 14px rgba(40, 35, 30, .07);
  --shadow-lg:  0 12px 32px rgba(40, 35, 30, .10), 0 4px 10px rgba(40, 35, 30, .05);

  /* Плашки статуса. Светлые значения — те же литералы, что стояли врассыпную
     по видам, чтобы светлая тема не изменилась; в тёмной они переопределяются
     парой «тёмный фон + светлый текст». */
  --tag-ok-bg:     #e3f4e6;  --tag-ok-fg:     #2c8a4a;
  --tag-warn-bg:   #fff4e0;  --tag-warn-fg:   #c98a17;
  --tag-danger-bg: #fbeaea;  --tag-danger-fg: #d2453c;
  --tag-info-bg:   #eef2ff;  --tag-info-fg:   #3730a3;
  --tag-role-bg:   #efe7f5;  --tag-role-fg:   #7d5a96;

  /* Текст-сигнал: просрочка, сумма в минус, «сегодня». Отдельно от плашек —
     это цвет БУКВ на обычном фоне, и в тёмной теме он должен быть светлее. */
  --text-danger: #b91c1c;
  --text-warn:   #d97706;
  --text-ok:     #16a34a;
  --text-info:   #2563eb;
  --text-orange: #ea580c;

  /* Текст на заливке. В светлой теме заливка тёмная — буквы белые; в тёмной
     заливка светлая, и белым по ней не прочитать. */
  --on-primary: #ffffff;
  --on-solid:   #ffffff;

  /* Графики. Ось и подпись — служебные, серия — данные. */
  --chart-1:     #2f6feb;
  --chart-2:     #1a9d6a;
  --chart-3:     #60a5fa;
  --chart-empty: #e3e6ea;
  --chart-axis:  #6b7480;
  --chart-label: #374049;

  /* Подложки и тени. Лежат токенами, потому что в тёмной теме тень работает
     иначе: мягкое серое пятно на тёмном фоне не видно вовсе, нужен контур. */
  --overlay:   rgba(40,30,20,.35);
  --ring:      var(--primary-soft);
  --shadow-sm: 0 1px 3px rgba(60,50,30,.06);
  --shadow-md: 0 4px 12px rgba(60,50,30,.14);
  --shadow-modal: 0 20px 60px rgba(40,30,20,.18), 0 4px 12px rgba(40,30,20,.08);
  --shadow-toast: 0 10px 28px rgba(40,30,20,.16), 0 2px 6px rgba(40,30,20,.08);
  --login-bg: radial-gradient(circle at 30% 20%, #eeeefb 0%, transparent 50%),
              radial-gradient(circle at 80% 80%, #f6ece0 0%, transparent 50%),
              linear-gradient(180deg, #faf8f5 0%, #f7f6f4 100%);
  /* Стрелка у <select> рисуется картинкой, а в картинке цвет зашит строкой —
     переменную туда не подставить, поэтому две готовые стрелки. */
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%238a8278' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
}

/* ====================================================================== *
 *  ТЁМНАЯ ТЕМА
 *
 *  Выбор темы — на устройстве (localStorage), не в настройках CRM: один и тот
 *  же человек смотрит с ноутбука днём и с телефона вечером. «Авто» разрешается
 *  в light/dark ещё до первой отрисовки — см. загрузчик в index.html, — так что
 *  здесь достаточно одного селектора и набор токенов не приходится дублировать.
 *
 *  Тёмная палитра НЕ инвертированная: фон тёплый (тот же сдвиг в жёлтый, что и
 *  у светлой), а не сине-чёрный. Индиго в темноте осветлён: насыщенный цвет на
 *  тёмном фоне читается хуже, чем на белом.
 * ====================================================================== */
:root[data-theme="dark"] {
  --bg: #1b1917;
  --surface: #232120;
  --surface-2: #2b2826;
  --surface-3: #35312d;
  --border: #35312d;
  --border-strong: #4a443d;

  --text: #eae6e0;
  --muted: #a39a8f;

  /* --primary остаётся заливкой кнопки, --primary-700 — цветом БУКВ на тёмном
     (ссылки, суммы, активный пункт меню). В светлой теме «700» темнее базового,
     в тёмной светлее: иначе текст тонет в фоне. */
  --primary: #7d80e8;
  --primary-700: #a9abf4;
  --primary-soft: #2e2e4d;

  --ok: #74c49a;
  --ok-soft: #21322a;
  --danger: #ef8d80;
  --danger-soft: #3b2724;
  --warn: #ddaa6d;
  --warn-soft: #3a2f1f;
  --accent: #332c3e;

  --tag-ok-bg:     #21322a;  --tag-ok-fg:     #7ccfa2;
  --tag-warn-bg:   #3a2f1f;  --tag-warn-fg:   #e3b071;
  --tag-danger-bg: #3b2724;  --tag-danger-fg: #f0948a;
  --tag-info-bg:   #2e2e4d;  --tag-info-fg:   #a9abf4;
  --tag-role-bg:   #332c3e;  --tag-role-fg:   #c4a9dd;

  --text-danger: #f0948a;
  --text-warn:   #e3b071;
  --text-ok:     #7ccfa2;
  --text-info:   #9aa9f2;
  --text-orange: #eaa06b;

  /* Заливка светлая — буквы на ней тёмные. */
  --on-primary: #16151d;
  --on-solid:   #1b1917;

  --chart-1:     #7d9ff0;
  --chart-2:     #57c599;
  --chart-3:     #7fb3f5;
  --chart-empty: #35312d;
  --chart-axis:  #8e857b;
  --chart-label: #cdc6bd;

  /* Затемнение поверх и так тёмного экрана должно быть плотнее, иначе окно не
     отделяется от страницы. */
  --overlay: rgba(0,0,0,.6);
  --ring: rgba(125,128,232,.45);
  /* Тень на тёмном фоне почти не видна — роль границы берёт на себя светлый
     контур внутри самой тени (первый слой). */
  --shadow:       0 0 0 1px rgba(255,255,255,.04), 0 4px 14px rgba(0,0,0,.45);
  --shadow-lg:    0 0 0 1px rgba(255,255,255,.05), 0 12px 32px rgba(0,0,0,.55);
  --shadow-sm:    0 1px 3px rgba(0,0,0,.4);
  --shadow-md:    0 4px 12px rgba(0,0,0,.5);
  --shadow-modal: 0 0 0 1px rgba(255,255,255,.06), 0 20px 60px rgba(0,0,0,.6);
  --shadow-toast: 0 10px 28px rgba(0,0,0,.5);
  --login-bg: radial-gradient(circle at 30% 20%, #232338 0%, transparent 50%),
              radial-gradient(circle at 80% 80%, #2a2420 0%, transparent 50%),
              linear-gradient(180deg, #1b1917 0%, #1f1c1a 100%);
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%23a39a8f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");

  /* Тёмная тема гасит белые «вспышки»: так браузер рисует тёмными системные
     части — полосы прокрутки, поля ввода даты, автодополнение. */
  color-scheme: dark;
}

:root[data-theme="dark"] .toast {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong);
}
:root[data-theme="dark"] .toast.err { background: var(--danger); color: var(--on-solid); border-color: transparent; }
:root[data-theme="dark"] .toast.ok  { background: var(--ok);     color: var(--on-solid); border-color: transparent; }

/* Переключение темы не должно мигать: фон и текст переезжают плавно, всё
   остальное — мгновенно, иначе таблица на тысячу строк заметно тормозит. */
:root[data-theme] body { transition: background-color .18s ease, color .18s ease; }
@media (prefers-reduced-motion: reduce) { :root[data-theme] body { transition: none; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 'Inter', -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.splash { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.grow { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.right { margin-left: auto; }
.center { text-align: center; }

/* ---- app shell: vertical sidebar + content area ---- */
/* dvh shrinks with the browser chrome; vh on iOS is the tall viewport, which
   pushes the bottom of the app under the toolbar. vh first as the fallback. */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; min-height: 100dvh; }
.app-body  { display: flex; flex-direction: column; min-width: 0; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 14px;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.sidebar-close { display: none; background: transparent; border: 0; font-size: 18px; padding: 4px 8px; color: var(--muted); cursor: pointer; }
.brand { font-weight: 600; font-size: 16px; letter-spacing: -.1px; }
.sidebar-foot {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
[data-module-route="1"] .sidebar-foot { display: none; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; overflow-y: auto; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600;
  padding: 12px 12px 4px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; padding-left: 8px; }
.nav-group a { font-size: 13px; }
.nav a {
  text-decoration: none; color: var(--muted);
  padding: 9px 12px; border-radius: var(--radius-sm); font-weight: 500;
  font-size: 13.5px;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary-700); }

.user-box { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.user-box .name { font-weight: 500; font-size: 13px; }
.user-box .role { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; }
/* Sidebar location switcher reuses base select styles; just stretch to full width. */
.loc-switcher select { width: 100%; }
.lang-switcher { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; flex-wrap: wrap; }
.lang-select { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 11px; font-weight: 600; background: var(--surface); color: inherit; cursor: pointer; }
.lang-select:focus { outline: none; border-color: var(--primary); }

/* Mobile header — only visible on narrow screens */
.topbar-mobile {
  display: none; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 9;
}
.sidebar-toggle { background: transparent; border: 0; font-size: 22px; line-height: 1; padding: 4px 8px; cursor: pointer; }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 20;
}

/* ---- main layout ---- */
.main { padding: 18px; max-width: 1400px; margin: 0 auto; width: 100%; min-width: 0; }
/* Calendar + Deals kanban benefit from extra horizontal space — let them
   fill the viewport on wide screens (forms/text on other pages still cap at
   1400 for readability). */
body[data-route="calendar"] .main,
body[data-route="deals"] .main { max-width: none; }

/* ---- responsive: tablet & phone ---- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .topbar-mobile { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; width: 260px;
    z-index: 25; transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-block; }
  .sidebar-backdrop.show { display: block; }
  .main { padding: 14px; }
}
@media (min-width: 901px) {
  .topbar-mobile .brand { display: none; }
}
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 18px; margin: 18px 0 10px; }
h3 { font-size: 15px; margin: 10px 0 6px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -.2px; }

/* ---- forms / inputs ---- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }

/* Base styles for every text/number input, textarea and select — wrapped in
 * a label or not. Native select arrow is hidden and replaced with a custom
 * SVG chevron so it looks the same in every browser. */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=datetime-local], input[type=tel],
input[type=search], input[type=url], input:not([type]),
select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 11px;
  transition: border-color .15s ease, box-shadow .15s ease;
  box-sizing: border-box; line-height: 1.3;
}
textarea { min-height: 72px; resize: vertical; }

select {
  /* Remove native chevron + draw a clean one via background-image.
   * Keep extra right padding so option text doesn't overlap the arrow. */
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 30px; cursor: pointer;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select::-ms-expand { display: none; }    /* hide arrow in IE/Edge legacy */

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2); color: var(--muted); cursor: not-allowed;
}
/* minmax(0, …) rather than a bare 1fr: a plain `1fr` track keeps an automatic
   MINIMUM, so it can never be narrower than the widest item's min-content. One
   <select> in Settings («Календарь: что видит сотрудник») measures 376px at its
   longest option, and that dragged the whole column to 376px inside a 336px
   form — nineteen fields hung 25px past the edge of the card on a phone.
   minmax(0, …) drops that floor; min-width on the items lets them actually
   shrink; max-width stops a long option spilling back out of a shrunk field. */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.form-grid > * { min-width: 0; }
.form-grid input, .form-grid select, .form-grid textarea { max-width: 100%; }
.form-grid .full { grid-column: 1 / -1; }

button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: var(--radius-sm);
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(.5px); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.primary:hover { background: var(--primary-700); border-color: var(--primary-700); }
button.danger  { background: var(--surface); border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.ghost   { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.err { color: var(--danger); min-height: 18px; font-size: 13px; }
.ok  { color: var(--ok); font-size: 13px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .4px; }
tr:last-child td { border-bottom: 0; }
.clickable { cursor: pointer; transition: background .12s ease; }
tr.clickable:hover td { background: var(--surface-2); }
/* Rows that are not table rows highlight themselves instead of their cells. */
div.clickable:hover, .task-row.clickable:hover { background: var(--surface-2); }
/* The whole row opens the task; the checkbox keeps its own job, so give it
   back the ordinary pointer rather than inheriting the row's. */
.task-row { border-radius: 6px; margin: 0 -6px; padding-left: 6px; padding-right: 6px; }
.task-row input[type="checkbox"] { cursor: pointer; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }

/* ---- login ---- */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  background: var(--login-bg);
}
.login { width: min(380px, 92vw); padding: 24px; }
.login h1 { font-size: 18px; margin: 0 0 14px; }
.login label { margin-bottom: 10px; }
.login button.primary { width: 100%; margin-top: 6px; }
.login .hint { margin-top: 10px; font-size: 12px; }
.loc-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.loc-list button { text-align: left; padding: 10px 12px; }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; background: var(--overlay);
  backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 100;
  padding: 16px;
  animation: fadein .15s ease-out;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%; max-width: 640px;
  /* dvh follows the browser chrome as it slides away; plain vh is the LARGE
     viewport on iOS, so a sheet sized by it can reach under the toolbar and
     hide its own buttons. The vh line stays first as the fallback. */
  max-height: 88vh;
  max-height: 88dvh;
  /* Head and footer hold still, only the body scrolls: on a phone a long form
     used to move «Сохранить» off-screen and it had to be hunted for. */
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: scalein .18s ease-out;
}
.modal.wide { max-width: 960px; }
.modal-head { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head .close { margin-left: auto; font-size: 20px; line-height: 1; padding: 2px 8px; }
.modal-body { padding: 18px 22px; flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex: 0 0 auto; flex-wrap: wrap; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes scalein { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---- toast ---- */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-toast);
  font-size: 13px; font-weight: 500;
  animation: slidein .22s cubic-bezier(.2,.7,.4,1);
}
.toast.err { background: var(--danger); }
.toast.ok  { background: var(--ok); }
@keyframes slidein { from { transform: translateX(12px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---- calendar ---- */
.cal-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-toolbar .date { font-weight: 600; min-width: 200px; text-align: center; }
.cal {
  display: grid;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; overflow-y: hidden; box-shadow: var(--shadow);
}
.cal-head { display: grid; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal-head > div { padding: 8px 10px; font-weight: 600; font-size: 13px; border-right: 1px solid var(--border); }
.cal-head > div:last-child { border-right: 0; }
.cal-day-head { display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.cal-day-head:hover { background: var(--surface); }
.cal-day-head .wd { font-size: 11px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.cal-day-head .dn { font-size: 16px; font-weight: 700; line-height: 1; }
.cal-day-head.today .dn {
  background: var(--primary); color: var(--on-primary); border-radius: 999px;
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-grid { display: grid; position: relative; }
.cal-col {
  border-right: 1px solid var(--border); position: relative;
  background-image: linear-gradient(to bottom, var(--surface-2) 1px, transparent 1px);
  background-size: 100% var(--row-h, 40px);
  background-position: 0 -1px;
}
.cal-col:last-child { border-right: 0; }
.cal-col.hours { background: var(--surface); border-right: 2px solid var(--border); background-image: none; }
.cal-hour-label { font-size: 11px; color: var(--muted); padding: 2px 6px; border-bottom: 1px dashed var(--border); display: flex; align-items: flex-start; }
.cal-slot { position: absolute; left: 4px; right: 4px; }
.cal-appt {
  position: absolute; left: 4px; right: 4px;
  background: var(--primary-soft); border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm); padding: 5px 8px; font-size: 12px;
  overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease;
}
.cal-appt:hover { box-shadow: var(--shadow-md); }
.cal-appt .t { font-weight: 600; }
.cal-appt .c { color: var(--text); }
.cal-appt .s { color: var(--muted); font-size: 11px; }
.cal-appt.status-done      { background: var(--ok-soft);     border-left-color: var(--ok); }
.cal-appt.status-cancelled { background: var(--danger-soft); border-left-color: var(--danger); opacity: .6; text-decoration: line-through; }
.cal-appt.status-no_show   { background: var(--warn-soft);   border-left-color: var(--warn); }

/* misc */
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag.role-director { background: var(--tag-role-bg); color: var(--tag-role-fg); }
.tag.role-admin    { background: var(--primary-soft); color: var(--primary-700); }
.tag.role-staff    { background: var(--ok-soft); color: var(--ok); }
.tag.ok            { background: var(--ok-soft); color: var(--ok); }
.tag.danger        { background: var(--danger-soft); color: var(--danger); }
.tag.warn          { background: var(--warn-soft); color: var(--warn); }
.tag.info          { background: var(--primary-soft); color: var(--primary-700); }
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; }

.empty { padding: 32px; text-align: center; color: var(--muted); }
/* Footer under a paged list: "shown N of M" + the load-more button. */
.list-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.list-foot .muted { font-size: 13px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.builder-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 6px; }
.builder-row select, .builder-row input { width: 100%; }

/* ---- month grid ---- */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.month-head {
  padding: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px;
  color: var(--muted); background: var(--surface-2); text-align: center;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.month-head:last-child { border-right: 0; }
.month-cell {
  min-height: 110px; padding: 6px 6px 8px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.month-cell:hover { background: var(--surface-2); }
.month-cell.other-month { background: var(--surface-2); }
.month-cell.other-month .month-cell-head .d { color: var(--muted); }
.month-cell.today { background: var(--warn-soft); }
.month-cell.today .month-cell-head .d { background: var(--primary); color: var(--on-primary); }
.month-cell-head { display: flex; align-items: center; justify-content: space-between; }
.month-cell-head .d {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; font-weight: 600; font-size: 12px;
}
.month-cell-head .cnt {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: var(--accent); color: var(--primary-700); font-weight: 600;
}
.month-cell-list { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.month-item {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
  background: var(--primary-soft); border-left: 2px solid var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.month-item .t { font-weight: 600; }
.month-item.status-done      { background: var(--ok-soft);     border-left-color: var(--ok); }
.month-item.status-cancelled { background: var(--danger-soft); border-left-color: var(--danger); opacity: .65; text-decoration: line-through; }
.month-item.status-no_show   { background: var(--warn-soft);   border-left-color: var(--warn); }

/* Цель, над которой удерживают перетаскиваемую запись.
 *
 * Обводка появляется сразу — она говорит «сюда попадёшь». Заливка наливается
 * за то же время, что идёт отсчёт, и это не украшение: две секунды ожидания
 * без обратной связи неотличимы от зависания, и человек уводит мышь ровно
 * перед тем, как сработало бы. Длительность перехода совпадает с
 * SPRING_DAY_MS в public/views/calendar.js — если менять, то в обоих местах.
 */
.cal-spring { outline: 2px solid var(--primary); outline-offset: -2px; }
.month-cell.cal-spring-fill { background: var(--primary-soft); transition: background 2s linear; }
.month-more { font-size: 11px; color: var(--muted); padding: 0 5px; }

.mode-switch { display: inline-flex; gap: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.mode-switch button { border-radius: 0; border: 0; border-right: 1px solid var(--border); }
.mode-switch button:last-child { border-right: 0; }

/* Переключатель темы — та же раскладка, что у режимов календаря, но кнопки
   узкие: в подвале бокового меню на них вместе с языком приходится 220px. */
.theme-switch button { padding: 3px 9px; font-size: 15px; line-height: 1.35; color: var(--muted); }
.theme-switch button:hover { color: var(--text); }
.theme-switch button.primary { color: var(--on-primary); }

/* Client card — tab nav + timeline of events ----------------------------- */
.card-tab-nav {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin: -4px -4px 14px; padding: 0 4px;
}
.card-tab-nav button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; padding: 8px 14px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 13px;
}
.card-tab-nav button:hover { color: var(--text); }
.card-tab-nav button.primary {
  background: transparent; color: var(--primary-700);
  border-bottom-color: var(--primary);
}
.card-tab-content { min-height: 120px; }

.event-list { display: flex; flex-direction: column; gap: 6px; }
.event-row {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: start;
  padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border-left: 3px solid var(--border);
}
.event-row .ev-icon { font-size: 16px; line-height: 22px; text-align: center; }
.event-row .ev-head { font-size: 13px; line-height: 1.3; }
.event-row .ev-body { color: var(--text); font-size: 13px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.event-row.kind-note { border-left-color: var(--warn); background: var(--warn-soft); }
.event-row.kind-client-created { border-left-color: var(--ok); }
.event-row.kind-lead-linked, .event-row.kind-lead-status_changed { border-left-color: var(--primary); }
.event-row.kind-appt-created, .event-row.kind-appt-status_changed { border-left-color: var(--chart-2); }
.event-row.kind-deal-created, .event-row.kind-deal-stage_changed, .event-row.kind-deal-won, .event-row.kind-deal-lost { border-left-color: var(--text-orange); }

/* ---- Deals: kanban board + cards --------------------------------------- */
.deals-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.deals-toolbar label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.deals-toolbar label.inline select { font-weight: 500; }

.kanban-board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr);
  gap: 12px; overflow-x: auto; padding-bottom: 8px;
  align-items: stretch;
  /* Fill the viewport below the page header + toolbar so columns are tall
     and the board doesn't leave a big empty gap on wide/tall screens. */
  height: calc(100vh - 170px);
}
.kanban-col {
  background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.kanban-col.drop-target { background: var(--primary-soft); border-color: var(--primary); }
.kanban-col.kind-won  { background: linear-gradient(180deg, var(--ok-soft) 0%, var(--surface-2) 80%); }
.kanban-col.kind-lost { background: linear-gradient(180deg, var(--danger-soft) 0%, var(--surface-2) 80%); }

.kanban-col-head { padding: 10px 12px; border-bottom: 1px solid var(--border); border-top: 3px solid var(--border); border-radius: 10px 10px 0 0; }
.kanban-col-title { font-weight: 600; font-size: 14px; }
.kanban-col-meta  { font-size: 11px; color: var(--muted); margin-top: 2px; }

.kanban-col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.kanban-empty { font-size: 12px; padding: 18px 6px; text-align: center; font-style: italic; }

.kanban-card {
  background: var(--surface); border-radius: 8px; padding: 8px 10px;
  border-left: 3px solid var(--primary); box-shadow: var(--shadow-sm);
  cursor: grab; transition: transform .12s ease, box-shadow .12s ease;
  user-select: none;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card.status-won  { border-left-color: var(--ok); }
.kanban-card.status-lost { border-left-color: var(--danger); opacity: .7; }
.kanban-card .kc-title { font-weight: 600; font-size: 13px; line-height: 1.3; }
.kanban-card .kc-client { font-size: 11px; margin-top: 3px; }
.kanban-card .kc-meta { display: flex; gap: 8px; margin-top: 5px; align-items: center; font-size: 11px; }
.kanban-card .kc-amount { font-weight: 600; color: var(--primary-700); }
.kanban-card .kc-owner { font-size: 11px; margin-top: 3px; text-align: right; }

.client-deals-list { display: flex; flex-direction: column; gap: 6px; }
.client-deal-row { padding: 6px 10px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.client-deal-row:hover { background: var(--primary-soft); }

/* ---- Properties: listing grid + cards --------------------------------- */
.prop-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.prop-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .12s ease; display: flex; flex-direction: column;
}
.prop-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.prop-card.status-sold, .prop-card.status-rented, .prop-card.status-archived { opacity: .72; }
.prop-thumb {
  height: 150px; background-size: cover; background-position: center;
  background-color: var(--surface-2);
}
.prop-thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; font-style: italic; }
.prop-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.prop-card-top { display: flex; align-items: center; justify-content: space-between; }
.prop-price { font-weight: 700; font-size: 16px; color: var(--primary-700); }
.prop-card-title { font-weight: 600; font-size: 13px; line-height: 1.3; }
.prop-card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.tag.prop-status-available { background: var(--ok-soft); color: var(--ok); }
.tag.prop-status-reserved  { background: var(--warn-soft); color: var(--warn); }
.tag.prop-status-sold, .tag.prop-status-rented { background: var(--surface-2); color: var(--muted); }
.tag.prop-status-draft     { background: var(--surface-2); color: var(--muted); }
.tag.prop-status-archived  { background: var(--surface-2); color: var(--muted); }

.match-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); margin-bottom: 6px;
}

/* Photo gallery (property editor) */
.photo-gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-thumb {
  position: relative; width: 96px; height: 72px; border-radius: 8px;
  background-size: cover; background-position: center; background-color: var(--surface-2);
  border: 1px solid var(--border);
}
.photo-del {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: 0; background: var(--danger); color: var(--on-solid);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
  box-shadow: var(--shadow-sm);
}

/* Deals — pipeline/stage management modal */
.mng-section { margin-bottom: 8px; }
.mng-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.mng-stages { display: flex; flex-direction: column; gap: 6px; }
.mng-stage-row { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.mng-move { display: flex; flex-direction: column; gap: 1px; }
.mng-move .xs { padding: 0 5px; font-size: 9px; line-height: 1.4; border-radius: 4px; }
.mng-prob { display: inline-flex; align-items: center; gap: 2px; }
button.ghost.xs { background: transparent; border: 1px solid var(--border); cursor: pointer; }
button.ghost.xs:disabled { opacity: .35; cursor: default; }

/* tel: links — subtle accent, no underline by default, dotted on hover.
   A phone number must never wrap (least of all char-by-char in a squeezed
   mobile table cell — it renders as a vertical column of digits). */
a.tel-link { color: var(--primary-700); text-decoration: none; border-bottom: 1px dotted transparent; white-space: nowrap; }
a.tel-link:hover { border-bottom-color: var(--primary-700); }
.event-row.kind-call-in, .event-row.kind-call-out { border-left-color: var(--ok); }
.event-row.kind-property-notified { border-left-color: var(--chart-2); }

.cal-appt-ghost { box-shadow: var(--shadow-lg); }
.cal-appt { user-select: none; }

/* ---- report wizard ---- */
.wiz-q { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.wiz-label { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.wiz-sublabel { font-size: 12px; color: var(--muted); margin-top: 8px; margin-bottom: 4px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.pill:hover { background: var(--surface-2); }
.pill.on {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.pill.on:hover { background: var(--primary-700); }

/* ---- template editor with live preview ---- */
.tpl-edit-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start;
}
.tpl-edit-left, .tpl-edit-right { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tpl-edit-right .preview-subject-wrap {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; display: flex; align-items: baseline; flex-wrap: wrap;
}
.tpl-edit-right .preview-subject { font-weight: 600; font-size: 14px; word-break: break-word; }
.tpl-edit-right .preview-frame {
  width: 100%; min-height: 320px;
  /* Белый НАМЕРЕННО: во врезке показано письмо, а письмо у получателя
     откроется на белом независимо от темы CRM. */
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
@media (max-width: 980px) {
  .tpl-edit-grid { grid-template-columns: 1fr; }
  .tpl-edit-right .preview-frame { min-height: 220px; }
}

/* ---- leads (open-lines style inbox) ---- */
.leads-layout { display: grid; grid-template-columns: 360px 1fr; gap: 14px; align-items: start; }
.leads-list { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 220px); overflow-y: auto; }
.lead-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; transition: background .12s ease, border-color .12s ease;
}
.lead-card:hover { background: var(--surface-2); }
.lead-card.active { border-color: var(--primary); background: var(--primary-soft); }
.lead-card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.lead-card-name { font-weight: 600; font-size: 13.5px; }
.lead-card-last { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-source-badge {
  font-size: 11px; background: var(--surface-2); color: var(--text);
  padding: 2px 8px; border-radius: 999px; font-weight: 500;
}
.lead-chat-label {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
  background: var(--accent); color: var(--primary-700);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.leads-detail { min-height: 320px; }
.lead-thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; max-height: 50vh; overflow-y: auto; padding-right: 4px; }
.lead-comment { padding: 8px 12px; border-radius: 10px; max-width: 78%; }
.lead-comment.in  { background: var(--surface-2); align-self: flex-start; }
.lead-comment.out { background: var(--primary-soft); align-self: flex-end; border: 1px solid var(--primary); }
.lead-comment.note { background: var(--warn-soft); align-self: stretch; max-width: 100%; border-left: 3px solid var(--warn); }
.lead-comment-meta { font-size: 10.5px; margin-bottom: 3px; }
.lead-comment-text { white-space: pre-wrap; word-break: break-word; }
.lead-comment-status { font-size: 11px; margin-top: 2px; }
.lead-comment-status.err { color: var(--danger); }
.lead-reply { display: flex; flex-direction: column; gap: 4px; }

@media (max-width: 900px) {
  .leads-layout { grid-template-columns: 1fr; }
  .leads-list { max-height: none; }
  .lead-comment { max-width: 92%; }
  /* Stacked, the detail card lands under every row — on a 375px screen that
     measured 1145px below the top of the list with only twelve leads, and it
     grows with the list. An OPEN lead therefore goes first; the placeholder
     ("pick a lead") does not, or it would push the list down for nothing. */
  .leads-layout.has-active .leads-detail { order: -1; }
}

/* ---- help page ---- */
.help-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.help-toc {
  position: sticky; top: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  max-height: calc(100vh - 36px); overflow-y: auto;
  min-width: 0;
}
.help-toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.help-toc-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--primary-700); font-weight: 600;
  margin-top: 12px; padding: 4px 6px;
  border-top: 1px solid var(--border);
}
.help-toc ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.help-toc a { text-decoration: none; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 4px; display: block; }
.help-toc a:hover { background: var(--surface-2); color: var(--text); }
.help-module-divider {
  margin: 32px -28px 16px;
  padding: 14px 28px;
  background: var(--primary-soft);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.help-module-divider h2 {
  margin: 0; color: var(--primary-700); font-size: 18px;
  border: 0; padding: 0;
}
.help-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; box-shadow: var(--shadow); min-width: 0; }
.help-body pre { background: var(--surface-2); padding: 10px 12px; border-radius: 6px; overflow-x: auto; font-size: 12px; line-height: 1.4; }
.help-body pre code { background: transparent; padding: 0; font-size: inherit; }
.help-body section { margin-bottom: 28px; scroll-margin-top: 18px; }
.help-body section:last-child { margin-bottom: 0; }
.help-body h2 { margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.help-body h3 { margin: 16px 0 8px; }
.help-body p, .help-body ul, .help-body ol { margin: 8px 0; }
.help-body ul, .help-body ol { padding-left: 22px; }
.help-body li { margin: 4px 0; }
.help-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; font-family: ui-monospace, "SF Mono", Consolas, Menlo, monospace; }
.help-body .warn { background: var(--warn-soft); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 0 6px 6px 0; }
.help-banner {
  background: var(--primary-soft); border-radius: 6px; padding: 10px 14px;
  margin-bottom: 16px; font-size: 13px;
}

/* ---- responsive: phone (collapse 2-col grids, stack builder rows) ---- */
@media (max-width: 700px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .builder-row { grid-template-columns: 1fr; gap: 6px; }
  .builder-row > button { justify-self: end; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
  .kv dd { margin-bottom: 6px; }

  /* Reference and status grids in module views pin a wide label column INLINE
     (`220px 1fr` in the mail/SMS/cadence status cards, `60px 220px 1fr` in the
     API reference) — and an inline style outranks any stylesheet rule, so the
     one-column rule below never reached them. At 390px that left 164px for
     `mail.privateemail.com`, which got cut, and 36px for a whole sentence of
     description, which wrapped to one syllable per line.
     The calendar opts out by name: its columns are a real time × staff matrix,
     not a label/value pair, and collapsing them would destroy the grid. */
  .main [style*="grid-template-columns"]:not(.cal-head):not(.cal-grid),
  .modal [style*="grid-template-columns"]:not(.cal-head):not(.cal-grid) {
    grid-template-columns: 1fr !important;
  }

  /* Modal — tighter horizontal padding so content has more room. The width
     comes from the backdrop's padding now, so there is nothing to override. */
  .modal-head, .modal-body, .modal-foot { padding-left: 14px; padding-right: 14px; }

  /* Page headers — wrap toolbar buttons under the title */
  .page-head { flex-wrap: wrap; }
  h1 { font-size: 19px; }
  h2 { font-size: 16px; }

  /* Cards inside cal/dashboard padding tighter */
  .card { padding: 14px; }

  /* Calendar toolbar: smaller date label so it wraps less */
  .cal-toolbar .date { min-width: auto; flex: 1; text-align: center; }

  /* Help: stack TOC above content */
  .help-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .help-toc { position: static; max-height: none; }
  .help-body { padding: 16px; }
  /* Cancel the desktop full-bleed divider — there's no padding to bleed into. */
  .help-module-divider { margin: 24px 0 12px; padding: 12px 16px; }

  /* Wrap horizontal flex rows on phone — tab bars / toolbars / button groups
     have many items in a .row; without wrap they push the page wider than
     the viewport. */
  .row { flex-wrap: wrap; }
}

/* License banner — sits at the top of .app-body. Colour varies by severity. */
.license-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 500;
}
.license-banner a { font-weight: 600; }
.license-banner-expiring_soon, .license-banner-grace,
.license-banner-server_unreachable {
  background: var(--tag-warn-bg); color: var(--tag-warn-fg); border-bottom-color: var(--warn);
}
.license-banner-expired, .license-banner-revoked,
.license-banner-not_found, .license-banner-not_configured {
  background: var(--tag-danger-bg); color: var(--tag-danger-fg); border-bottom-color: var(--danger);
}
/* Reuse tag for status badges in the License settings tab */
.tag-ok     { background: var(--tag-ok-bg);     color: var(--tag-ok-fg); }
.tag-warn   { background: var(--tag-warn-bg);   color: var(--tag-warn-fg); }
.tag-danger { background: var(--tag-danger-bg); color: var(--tag-danger-fg); }

/* ------------------------------------------------------------------ *
 * Mobile hardening — portrait phone. The app is used one-handed in a
 * narrow viewport; the goal here is simple: nothing may push the page
 * wider than the screen ("floating"), and anything that is genuinely
 * wide (data tables, tab strips) scrolls inside its own box instead.
 * All rules are additive and scoped to ≤700px so desktop is untouched.
 * ------------------------------------------------------------------ */
@media (max-width: 700px) {
  /* Safety net against sideways drift. `clip` (not `hidden`) so it does
     not turn the sticky mobile top bar into a non-sticky element. With the
     wrap/scroll rules below there is nothing left to clip in practice.
     BOTH elements: clipping only body still lets the document itself scroll
     sideways on iOS, and a document that can scroll sideways is a layout
     viewport wider than the screen — which is what drags fixed dialogs out
     from under the visible area. */
  html, body { overflow-x: clip; max-width: 100%; }
  .main { max-width: 100%; padding: 12px; }

  /* Inline flex rows in module views (toolbars, opt-out forms, filter bars)
     are written with `display:flex` and no wrap — on a narrow screen their
     inputs/buttons overflow to the right. Let them wrap. The client-card tab
     strip opts out: it scrolls instead (rule further down). */
  .main [style*="display:flex"]:not(.card-tab-nav),
  .main [style*="display: flex"]:not(.card-tab-nav) { flex-wrap: wrap; }

  /* The same, for dialogs. #modal-root sits OUTSIDE .main, so the rule above
     never reached it — and several editors put their action buttons in a plain
     inline-flex row inside the body rather than in .modal-foot. The task editor
     is the loud one: with the shop module on it carries four (Удалить /
     🛒 Продажа / 📅 В календарь / Сохранить), the row measured 398px against a
     374px dialog, and «Сохранить» was cut off exactly there. */
  .modal [style*="display:flex"]:not(.card-tab-nav),
  .modal [style*="display: flex"]:not(.card-tab-nav) { flex-wrap: wrap; }

  /* Data tables scroll inside their own box rather than stretching the page.
     The box is .table-wrap, which already has overflow-x — the TABLE itself
     stays a table.
     It used to be `display:block; width:100%` on the table. That breaks table
     layout in a way that is easy to miss: the block stretches to 100% while the
     rows inside shrink-to-fit, so a four-column report table drew 299px of
     content inside a 364px grey box and left 78px of empty tail on the right.
     width:auto + min-width:100% instead — fill the box when the content is
     narrow, grow past it when it is wide, and let the wrapper scroll.
     Scoped to tables that HAVE a scrolling wrapper. Roughly a third of the
     tables in the app are written without one; those keep the plain
     width:100% they always had — cramped on a phone, but never wider than the
     page, which is the safe half of the trade. */
  .table-wrap > table {
    width: auto;
    min-width: 100%;
  }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Near full-width sheet. The gutter is the backdrop's padding, so the sheet
     cannot be wider than the screen no matter what a viewport unit reports. */
  .modal-back { padding: 12px; }
  .modal, .modal.wide { max-width: 100%; }
  .modal-head,
  .modal-body,
  .modal-foot { padding-left: 16px; padding-right: 16px; }

  /* Client-card tabs → a single swipeable strip (no wrap, no page widening). */
  .card-tab-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: -4px 0 14px;
    padding: 0;
    scrollbar-width: none;
  }
  .card-tab-nav::-webkit-scrollbar { display: none; }
  .card-tab-nav button { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; }
  .card-tab-content { overflow-x: auto; }

  /* Long unbreakable values (URLs, e-mails, ISO timestamps) inside status
     cards wrap instead of forcing the card wider than the screen. */
  .card dd,
  .kv dd,
  .card .muted { overflow-wrap: anywhere; }

  /* …but never inside a table cell. The old guard was `:not(td)`, which spares
     only the CELL ITSELF — and the request log puts its IP in a
     <span class="muted"> INSIDE the td. That span still broke anywhere, so the
     column was free to collapse: 46.232.155.188 came out as a vertical stack of
     single digits in a 29px column, 225px tall.
     Written as `.card td .muted` rather than `td *` on purpose: it has to
     OUTWEIGH `.card .muted` above (0,2,0), and `td *` (0,0,2) loses to it —
     the first attempt at this changed nothing for exactly that reason. It also
     leaves `.audit-diff td`, which asks for anywhere-breaking deliberately so a
     pasted IBAN cannot widen the modal, untouched.
     Cells break between words or not at all; a table that then needs more room
     than it has gets it from the wrapper, which scrolls. */
  .card td.muted, .card th.muted,
  .card td .muted, .card th .muted { overflow-wrap: normal; }

  /* Tighter cell padding so data tables (My day, clients, …) fit more per row
     before they need to scroll. */
  .main table th,
  .main table td { padding: 8px 9px; }
}


/* ---- Audit: readable details ------------------------------------------
   The trail stores raw JSON; the modal shows it as fields and values. These
   two tables carry that: .audit-kv is "field → value", .audit-diff is
   "field → was → became". Kept narrow-friendly because the audit screen is
   read on a phone as often as on a desk. */
.audit-sec {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.audit-sec:first-child { margin-top: 0; }

.audit-kv,
.audit-diff { width: 100%; border-collapse: collapse; font-size: 13px; }

.audit-kv td,
.audit-diff td,
.audit-diff th {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  /* A pasted note or an IBAN must wrap rather than widen the modal. */
  overflow-wrap: anywhere;
}
.audit-diff th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}
/* The field name is the column you scan down, so let it stay narrow and
   quiet while the values get the room. */
.audit-kv .audit-k,
.audit-diff .audit-k { width: 34%; color: var(--muted); }

/* Old value reads as superseded, new value as the answer. Colour is a hint,
   not the message — the column headers already say which is which. */
.audit-diff .audit-before { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.audit-diff .audit-after  { font-weight: 500; }

.audit-hint { font-size: 11px; margin: 6px 0 0; }

.audit-raw {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  padding: 8px;
  border-radius: 4px;
  max-height: 400px;
  overflow: auto;
  font-size: 12px;
  margin-top: 6px;
}

@media (max-width: 720px) {
  /* Three columns don't fit a phone: stack was/became under the field name
     and label them inline, so the pairing survives the reflow. */
  .audit-diff thead { display: none; }
  .audit-diff tr { display: block; padding: 6px 0; border-bottom: 1px solid var(--border); }
  .audit-diff td { display: block; border: 0; padding: 1px 0; }
  .audit-diff .audit-k { width: auto; font-weight: 600; color: var(--text); }
  .audit-diff .audit-before::before,
  .audit-diff .audit-after::before {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    text-decoration: none;
    display: inline-block;
    min-width: 4.5em;
  }
  .audit-diff .audit-before::before { content: attr(data-lbl) " "; }
  .audit-diff .audit-after::before  { content: attr(data-lbl) " "; }
  .audit-kv .audit-k { width: 42%; }
}

/* ---- first-run wizard ---- */
/* Wider than the login card: seven type tiles in two columns need the room. */
.card.login.onb { max-width: 520px; }
.onb-types {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 4px 0 10px;
}
.onb-type {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; text-align: left;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer;
  font-size: 14px; line-height: 1.2;
}
.onb-type:hover { border-color: var(--primary); }
.onb-type.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-700);
  font-weight: 600;
}
.onb-type-icon { font-size: 18px; line-height: 1; }

/* ---- global search ---- */
/* Кнопка живёт над списком разделов: поиск — не раздел, в него не «переходят»,
   и выглядеть он должен иначе, чем пункт меню. */
.gsearch-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin: 10px 0 2px; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted);
  font-size: 13px; text-align: left; cursor: pointer;
}
.gsearch-btn:hover { border-color: var(--primary); color: var(--text); }
.gsearch-btn-label { flex: 1 1 auto; }
.gsearch-btn kbd {
  font: inherit; font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--muted); white-space: nowrap;
}
/* На узком экране подсказка про клавиши бессмысленна — клавиатуры нет. */
@media (max-width: 900px) { .gsearch-btn kbd { display: none; } }

/* Кнопку к правому краю двигает КОНТЕЙНЕР: auto-поле на самой кнопке не
   работает — она лежит в своём слоте, а флекс-строка у шапки. */
[data-role="search-slot-mobile"] { margin-left: auto; }
.gsearch-btn-mobile {
  background: transparent; border: 0;
  font-size: 20px; line-height: 1; padding: 4px 8px; cursor: pointer;
}

.gsearch-input {
  width: 100%; font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}
.gsearch-status { font-size: 12px; margin: 8px 2px 4px; }
.gsearch-results { display: flex; flex-direction: column; }
.gsearch-group {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600;
  padding: 12px 2px 4px;
}
.gsearch-more { text-transform: none; letter-spacing: 0; font-weight: 400; }
.gsearch-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
}
.gsearch-row:hover, .gsearch-row.active { background: var(--surface-2); border-color: var(--border-strong); }
.gsearch-main { flex: 1 1 auto; min-width: 0; }
.gsearch-title { font-size: 14px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.gsearch-tag { font-size: 10px; }
/* Подрезаем строку, а не переносим: адрес, почта и заметка бывают длинными,
   а строка результата должна оставаться одной строкой. */
.gsearch-sub, .gsearch-snip {
  font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gsearch-snip { font-style: italic; }
.gsearch mark { background: var(--primary-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
