/* ==========================================================================
   IPG — единый дизайн-слой (v1)
   Подключается ПОСЛЕДНИМ на всех страницах.
   Здесь только оформление: типографика, кнопки, поля, отступы, hover,
   мобильная адаптация. Логика/поведение элементов не меняется.
   ========================================================================== */

:root {
  --ds-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --ds-ink: #0f172a;
  --ds-soft: #64748b;
  --ds-line: #e2e8f0;
  --ds-blue: #2563eb;
  --ds-blue-dark: #1d4ed8;
  --ds-radius: 12px;
  --ds-radius-sm: 10px;
  --ds-shadow-hover: 0 10px 22px -12px rgba(15, 23, 42, 0.38);
  --ds-transition: transform 0.16s ease, box-shadow 0.16s ease,
    background-color 0.16s ease, border-color 0.16s ease,
    color 0.16s ease, filter 0.16s ease, opacity 0.16s ease;
}

/* ---------- Базовая типографика ---------- */
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--ds-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ds-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea,
optgroup {
  font-family: var(--ds-font);
}

h1, .h1 { font-size: 22px; line-height: 1.25; letter-spacing: -0.015em; }
h2, .h2 { font-size: 18px; line-height: 1.3; letter-spacing: -0.01em; }
h3, .h3 { font-size: 15px; line-height: 1.35; }

/* ---------- Кнопки: единая база ---------- */
.btn,
.lg-btn,
.btn-print,
.cart-clear,
.cart-add,
.cart-toggle,
.card-settings-toggle,
.mobile-gallery-toggle,
.viewer-btn,
.filter-btn {
  font-family: var(--ds-font);
  font-weight: 600;
  line-height: 1.2;
  box-sizing: border-box;
  transition: var(--ds-transition);
}

/* Обычные submit-кнопки (вход, регистрация, редактор) ведут себя так же */
button[type="submit"]:not(.btn) {
  transition: var(--ds-transition);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: var(--ds-radius-sm);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-small {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
}

.btn-orange {
  background: linear-gradient(135deg, #ea580c, #f97316);
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(234, 88, 12, 0.5);
}

.btn-ghost {
  background: #f8fafc;
  color: #64748b;
  border: 1.5px solid var(--ds-line);
}
.btn-ghost:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}

/* Единое поведение hover: аккуратный подъём, без «прыжков» */
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled):not([aria-disabled="true"]),
  .lg-btn:hover,
  .cart-toggle:hover,
  button[type="submit"]:not(.btn):hover,
  .filter-btn:hover,
  .card-settings-toggle:hover,
  .mobile-gallery-toggle:hover,
  .viewer-btn:hover,
  .cart-add:hover,
  .btn-print:hover,
  .cart-clear:hover:not(:disabled),
  .type-option:hover,
  .tab:hover,
  .vc-tab:hover {
    transform: translateY(-1px);
  }

  .btn-primary:hover:not(:disabled),
  .btn-secondary:hover:not(:disabled),
  .btn-ghost:hover:not(:disabled),
  .btn-green:hover:not(:disabled),
  .btn-red:hover:not(:disabled),
  .btn-ai:hover:not(:disabled),
  .btn-orange:hover:not(:disabled),
  button[type="submit"]:not(.btn):hover,
  .filter-btn:hover,
  .btn-print:hover,
  .cart-add:hover {
    box-shadow: var(--ds-shadow-hover);
  }
}

.btn:active:not(:disabled),
.lg-btn:active,
.filter-btn:active,
.card-settings-toggle:active,
.mobile-gallery-toggle:active,
.viewer-btn:active,
.cart-add:active,
button[type="submit"]:not(.btn):active,
.btn-print:active,
.cart-clear:active:not(:disabled),
.type-option:active,
.tab:active,
.vc-tab:active {
  transform: translateY(0) scale(0.99);
}

.btn:disabled,
.btn[aria-disabled="true"],
.lg-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Доступный фокус для клавиатуры */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.lg-btn:focus-visible,
.filter-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

/* ---------- Поля ввода: единый вид ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="color"]):not([type="file"]),
select,
textarea,
.form-input,
.form-select,
.form-textarea {
  font-family: var(--ds-font);
  font-size: 15px;
  line-height: 1.35;
  color: var(--ds-ink);
  padding: 9px 12px;
  border-radius: var(--ds-radius-sm);
  box-sizing: border-box;
}

/* Стандартные поля форм — одинаковой высоты (компактные поля-счётчики
   внутри таблиц/корзины не растягиваем). */
.form-input,
.form-select,
.form-textarea {
  min-height: 42px;
}

textarea,
.form-textarea {
  min-height: 84px;
  resize: vertical;
}

.form-label,
label {
  line-height: 1.35;
}

/* ---------- Карточки и модальные окна ---------- */
.card { border-radius: 16px; }
.modal { border-radius: 16px; }

/* ---------- Шапка страницы (header.php) ---------- */
.ipg-header-card {
  margin-bottom: 20px !important;
  padding: 0 !important;
  overflow: hidden;
  border-radius: 16px !important;
  border-top: 4px solid #2563eb;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.04);
}

.ipg-head-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 22px;
  background: #fff;
  border-bottom: 1px solid var(--ds-line);
}

.ipg-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.ipg-brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 10px -2px rgba(79, 70, 229, 0.4);
  flex-shrink: 0;
}

.ipg-brand-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--ds-ink);
  text-transform: uppercase;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.ipg-head-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.ipg-guar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
  padding: 16px 24px;
  background: #f8fafc;
}

.ipg-guar-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ipg-guar-title {
  font-size: 16px;
  font-weight: 800;
  color: #1e293b;
}

.ipg-guar-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ipg-guar-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.ipg-vin-input {
  min-width: 220px;
  text-transform: uppercase;
}

/* ---------- Галерея: аккуратные карточки и корзина ---------- */
@media (max-width: 700px) {
  /* Освобождаем место справа под иконку удаления, чтобы она
     не наезжала на плашку «Не проверено» / текст карточки */
  .group-item {
    padding-right: 56px !important;
  }
  .group-actions {
    top: 10px !important;
    right: 10px !important;
  }
  .group-del-btn {
    font-size: 20px !important;
    line-height: 1 !important;
    padding: 6px !important;
  }
  .group-warranty {
    width: 100% !important;
  }
  .group-item-title {
    font-size: 17px !important;
    line-height: 1.3 !important;
  }
  /* Плавающая кнопка «+» не должна прилипать к краям и перекрывать контент */
  #photoArea {
    padding-bottom: 96px !important;
  }
}

#fabAddFault {
  right: calc(16px + env(safe-area-inset-right)) !important;
  bottom: calc(16px + env(safe-area-inset-bottom)) !important;
}

/* ---------- Просмотрщик фото: зум и перетаскивание ---------- */
#photoViewer .viewer-body {
  overflow: hidden;
}

#photoViewer .viewer-body img {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

/* ---------- Поиск работ: корзина не перекрывает контент ---------- */
.works-page .container {
  padding-bottom: 104px;
}

.cart-panel {
  height: 100dvh !important;
}

.cart-head {
  padding-top: calc(16px + env(safe-area-inset-top)) !important;
}

.cart-foot {
  padding-bottom: calc(18px + env(safe-area-inset-bottom)) !important;
}

@media (max-width: 700px) {
  .cart-toggle {
    right: 12px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    padding: 10px 14px !important;
    font-size: 13px !important;
  }
  .cart-panel {
    width: 100vw !important;
  }
}

/* ---------- Мобильная унификация кнопок и полей ---------- */
@media (max-width: 700px) {
  /* Обычные кнопки — на всю ширину и одного размера.
     Кнопки с явным inline-размером (крупные CTA в модалках) сохраняют
     свой акцент, а компактные иконки в редакторе остаются в строку. */
  .btn:not(.photo-action-btn):not(.vc-tab) {
    width: 100%;
    max-width: 100%;
    min-height: 46px;
    padding: 11px 14px;
    font-size: 15px;
    white-space: normal;
    text-align: center;
    margin-left: 0;
    margin-right: 0;
  }
  .btn-small {
    min-height: 42px;
    padding: 10px 12px !important;
    font-size: 14px !important;
  }
  .btn-row .btn,
  .ipg-head-actions .btn {
    flex: 1 1 100%;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="color"]):not([type="file"]),
  select,
  textarea,
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px; /* iOS: без авто-зума при фокусе */
  }
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 46px;
  }

  /* На странице галереи карточки на мобильном идут во всю ширину —
     шапку выравниваем по тому же принципу. */
  .gallery-page .ipg-header-card {
    border-radius: 0 !important;
    margin: 8px 0 !important;
  }

  /* Шапка: логотип/заголовок и кнопки друг под другом, одинаковой ширины */
  .ipg-head-top {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px;
    gap: 14px;
  }
  .ipg-brand-title {
    font-size: 16px;
  }
  .ipg-head-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 8px;
  }
  .ipg-guar-row {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px;
    gap: 12px;
  }
  .ipg-guar-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .ipg-vin-input {
    width: 100%;
    min-width: 0;
  }
}

/* ---------- Инструменты списка (сортировка/фильтры) ---------- */
@media (max-width: 700px) {
  .photos-toolbar > div {
    width: 100%;
    margin-right: 0 !important;
    padding-right: 0 !important;
    border-right: 0 !important;
  }
  .photos-toolbar > div .btn {
    flex: 1 1 0;
  }
  .photos-toolbar {
    width: 100%;
  }
}

/* ---------- История ТС: фильтры-«чипы» ---------- */
.filter-btn {
  border-radius: 999px;
  min-height: 38px;
}

/* ---------- Генератор писем ---------- */
.lg-btn {
  border-radius: var(--ds-radius-sm);
}

@media (max-width: 700px) {
  .lg-toolbar {
    gap: 8px;
  }
  .lg-toolbar .lg-btn {
    flex: 1 1 100%;
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
  .lg-autosave {
    margin-left: 0;
    width: 100%;
    text-align: center;
  }
}

/* ---------- Таблицы (передача смены) ---------- */
@media (max-width: 700px) {
  .excel-table {
    font-size: 12.5px;
  }
  .excel-table th,
  .excel-table td {
    padding: 6px;
  }
}

/* ---------- Мелочи для единообразия ---------- */
.badge {
  line-height: 1.35;
}

/* Уважаем системную настройку «меньше движения» */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .lg-btn,
  .filter-btn,
  .card-settings-toggle,
  .mobile-gallery-toggle,
  .viewer-btn,
  .cart-add,
  .btn-print,
  .cart-clear,
  .type-option,
  .tab,
  .vc-tab {
    transition: none !important;
  }
  .btn:hover,
  .lg-btn:hover,
  .filter-btn:hover,
  .card-settings-toggle:hover,
  .mobile-gallery-toggle:hover,
  .viewer-btn:hover,
  .cart-add:hover,
  .btn-print:hover,
  .cart-clear:hover,
  .type-option:hover,
  .tab:hover,
  .vc-tab:hover {
    transform: none !important;
  }
}
