/* Глобальные стили, перекрывающие/дополняющие Tailwind */

/* Mobile карточки для responsive-таблиц.
   На мобиле каждая строка становится карточкой:
     LABEL мелкой меткой сверху, значение под ней.
   Колонка "Действия" (последняя) — горизонтальный ряд иконок. */
@media (max-width: 640px) {
  /* Контейнер таблицы (overflow-x-auto, рамка) — на мобиле прозрачный,
     рамка идёт уже на каждой строке-карточке.
     :has() — для современных браузеров. Класс .responsive-wrap — fallback. */
  div.overflow-x-auto:has(> table.responsive),
  div.overflow-hidden:has(> table.responsive),
  .responsive-wrap {
    overflow-x: visible !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* Сама таблица + tbody становятся блоками */
  table.responsive,
  table.responsive > tbody {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    table-layout: auto !important;
  }
  /* Скрытие thead/colgroup ОБЯЗАТЕЛЬНО с !important, иначе перебиваются
     общим display:block выше */
  table.responsive > thead,
  table.responsive > colgroup,
  table.responsive thead,
  table.responsive colgroup {
    display: none !important;
  }

  table.responsive > tbody > tr,
  table.responsive tr {
    display: block !important;
    margin-bottom: 12px;
    padding: 14px 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    width: auto;
  }

  table.responsive td {
    display: block !important;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    width: auto !important;
    word-break: break-word;
  }
  table.responsive td:last-child { border-bottom: none; }

  table.responsive td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
  }

  /* Последняя ячейка (обычно «Действия» с иконками) — иконки в ряд справа,
     без подписи метки. */
  table.responsive td:last-child {
    display: flex !important;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 12px;
    margin-top: 8px;
    border-top: 1px solid #e2e8f0;
  }
  table.responsive td:last-child::before { display: none !important; }

  /* Sticky-пины на мобиле не нужны — таблица в карточном режиме */
  table.responsive .col-pinned {
    position: static !important;
    left: auto !important;
    background: transparent !important;
    box-shadow: none !important;
  }
}

/* Inline-editable ячейка — общий стиль для всех справочников */
.cell-edit { padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.cell-edit:hover { background: #f1f5f9; }

/* ─── Help tooltip (?) ─────────────────────────────────────────────
   Использование:
     <span class="help" tabindex="0" data-tip="Текст подсказки">?</span>
   Внутри тега обязательно символ «?». Hover на десктопе, focus/tap на мобиле. */
.help {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  min-width: 14px;
  margin-left: 6px;
  background: #cbd5e1;
  color: #475569;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
  position: relative;
  vertical-align: 1px;
  user-select: none;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.help:hover, .help:focus, .help.open {
  background: #2563eb;
  color: #ffffff;
  outline: none;
}

.help::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  white-space: pre-line;
  width: max-content;
  max-width: 320px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .2);
  text-align: left;
}
.help::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1e293b;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 100;
}
/* Подсказка у правого края (последние колонки таблиц, правая колонка попапов) —
   открывать влево, чтобы не уезжала за край экрана/диалога. */
.help.tip-left::after { left: auto; right: 0; transform: none; }
.help.tip-left::before { left: auto; right: 6px; transform: none; }
/* Подсказка у левого края (левая колонка попапов) — открывать вправо. */
.help.tip-right::after { left: 0; right: auto; transform: none; }
.help.tip-right::before { left: 6px; right: auto; transform: none; }
/* Подсказка в шапке таблицы (внутри overflow-x-auto) — открывать ВНИЗ, иначе
   верхний край скролл-контейнера её обрезает. Стрелка смотрит вверх. */
.help.tip-down::after { top: calc(100% + 8px); bottom: auto; }
.help.tip-down::before {
  top: calc(100% + 2px); bottom: auto;
  border-top-color: transparent; border-bottom-color: #1e293b;
}

/* ─── Drag-and-drop зона загрузки (file-dropzone.js) ───
   Любой [data-dropzone] с <input type=file> внутри принимает перетаскивание. */
[data-dropzone] { transition: background .15s, box-shadow .15s; border-radius: 8px; }
[data-dropzone].dropzone-over {
  background: #ecfdf5;
  box-shadow: inset 0 0 0 2px #10b981;
}

/* Вспышка-подсветка строки документа при переходе по 📎 из строки платежа/расхода */
@keyframes doc-flash { 0%, 100% { background: transparent; } 25% { background: #fde68a; } }  /* amber-300 */
tr.doc-flash > td { animation: doc-flash 0.9s ease-in-out 2; }
.help:hover::after, .help:focus::after, .help.open::after,
.help:hover::before, .help:focus::before, .help.open::before {
  opacity: 1;
}

/* ─── Pin column (произвольное закрепление любой колонки) ─────────
   Реализация: на <table data-pinnable="table-id"> JS добавляет
   иконку 📌 в каждый <th>. Клик → колонка становится sticky-left.
   Состояние хранится в localStorage по data-pinnable id.

   Класс .col-pinned ставится JS-ом на <th> и <td> закреплённой колонки. */
.col-pinned {
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
  box-shadow: 1px 0 0 #e2e8f0;
}
thead .col-pinned { background: #f8fafc; z-index: 2; }
tbody tr:hover .col-pinned { background: #f8fafc; }

/* ─── sticky-first: первая колонка (PK/Артикул) всегда залипает слева ─── */
table.sticky-first th:first-child,
table.sticky-first td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  box-shadow: 1px 0 0 #e2e8f0;
}
table.sticky-first thead th:first-child { background: #f8fafc; z-index: 2; }
table.sticky-first tbody tr:hover td:first-child { background: #f8fafc; }

.pin-btn {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  opacity: 0.25;
  cursor: pointer;
  background: none;
  border: none;
  padding: 2px;
  font-size: 12px;
  transition: opacity 0.15s, transform 0.15s;
  vertical-align: middle;
}
.pin-btn:hover { opacity: 0.7; }
.pin-btn.active {
  opacity: 1;
  color: #2563eb;
  transform: rotate(-15deg);
}

/* Заголовки пинабельных таблиц — не переносим текст на новую строку,
   чтобы иконка 📌 не оказывалась под заголовком на узких колонках (ABC, XYZ).
   На мобиле эта таблица всё равно превращается в карточки (responsive). */
table[data-pinnable] thead th { white-space: nowrap; }

/* На мобиле таблицы коллапсируются в карточки → пин не нужен */
@media (max-width: 640px) {
  .pin-btn { display: none; }
}

/* Единое поле даты (date-field.js): курсор-указатель + скрытие "дд.мм.гггг" когда пусто.
   При фокусе/вводе текст проявляется. Работает в Chromium/WebKit. */
input[type="date"] { cursor: pointer; }
input[type="date"].date-empty::-webkit-datetime-edit { color: transparent; }
input[type="date"].date-empty:focus::-webkit-datetime-edit { color: inherit; }

/* ─── Action-icons (Изменить/Отключить/Активировать на иконки) ─── */
.action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin: 0 2px;
  padding: 0;
  border-radius: 6px;
  color: #64748b;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.action-icon:hover { background: #f1f5f9; }
.action-icon.icon-edit:hover    { color: #2563eb; background: #eff6ff; }
.action-icon.icon-disable:hover { color: #dc2626; background: #fef2f2; }
.action-icon.icon-enable:hover  { color: #059669; background: #ecfdf5; }
.action-icon.icon-delete:hover  { color: #b91c1c; background: #fef2f2; }
.action-icon svg { width: 16px; height: 16px; pointer-events: none; }

/* Кликабельные строки (row-click.js) — наведение слегка подсвечивает, курсор-указатель */
[data-href] { cursor: pointer; }
tr[data-href]:hover { background-color: #f8fafc; }   /* slate-50 */
[data-href].card:hover, [data-search-row][data-href]:hover { background-color: #f8fafc; }
/* внутри кликабельной строки текстовые ссылки не подсвечиваем отдельным фоном */
tr[data-href] a:hover { background: transparent; }

/* Печать: скрываем интерактив/навигацию, оставляем документ (упаковочный лист и т.п.) */
@media print {
  .no-print { display: none !important; }
  /* убираем шапку приложения, меню и подвал — печатаем только документ */
  body > header, body > nav, header, nav, footer, .site-nav { display: none !important; }
  body { background: #fff !important; }
  main { padding: 0 !important; }
  /* документ во всю ширину, без теней/рамок-обрезки */
  main > div { max-width: 100% !important; }
  .print\:break-inside-avoid, table, tr, td, th { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
