/*
 * Блок «Шаблоны покупок» на lists.html (#templates). Сценарий —
 * scripts/templates-live.js.
 *
 * Телефон, экран списка, карточки товаров, нижняя панель, плашка
 * персонажа и вспышка касания — готовая вёрстка journey-live.css
 * (блок «Один обычный вечер» на главной, классы jl-*). Пуш, бейдж
 * «Семья» и плашка автора — классы ntl-* из notes-live.css.
 * Здесь только виджеты шаблонов, в нативных pt экрана 393×852:
 *   .tpl-suggest  — _buildFloatingTemplateSuggestion
 *                   (lib/screens/list_page/list_page_template_suggestion_ui.dart)
 *   .tpl-blocking — AppBlockingProgressOverlay (lib/widgets/app_blocking_progress_overlay.dart)
 *   .tpl-popup    — showTemplateCreatedDialog на AppPopupDialog
 *                   (lib/widgets/template_created_dialog.dart, app_popup_dialog.dart)
 *   .tpl-picker   — _TemplatePickerSheet + ListTile(templatePickerMode)
 *                   (template_add_to_list_sheet_picker.dart, lists_page/list_tile.dart)
 *
 * Состояние — на корне .tpl-live: data-mode="list|template" и классы
 * is-suggest, is-creating, is-created, is-push, is-picker.
 * Разметка по умолчанию — кадр «Добавить из шаблона» (no-JS, reduced-motion).
 */

/* ---------- Раскладка блока: телефон слева, шаги справа ---------- */

.tpl-layout {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: clamp(32px, 5vw, 72px);
  margin-top: 48px;
}

.tpl-live {
  --jl-s: 0.6;
  padding: 28px 44px 52px;
}

.tpl-live .jl-chip {
  min-width: 236px;
}

.tpl-layout .lists-template-steps {
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: 560px;
  margin-top: 0;
}

.tpl-layout .lists-template-steps li::after {
  display: none;
}

.tpl-step {
  overflow: hidden;
  transition:
    opacity 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.tpl-step small {
  font-size: 12px;
}

/* Полоска прогресса шага — как .journey-step-progress на главной */
.tpl-step-progress {
  position: absolute;
  right: 18px;
  bottom: 0;
  left: 18px;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(47, 107, 255, 0.1);
}

.tpl-step-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand-blue);
}

.tpl-live-wrap.is-running .tpl-step {
  opacity: 0.6;
}

.tpl-live-wrap.is-running .tpl-step.is-active {
  border-color: rgba(47, 107, 255, 0.28);
  box-shadow: 0 16px 34px rgba(26, 36, 67, 0.09);
  opacity: 1;
}

/* ---------- Экран списка: режим шаблона ---------- */

/* Вторая кнопка панели: «Шаблон» в списке, «В список» в шаблоне
   (BottomActionKind.templateAdd, list_page_bottom_bar_ui.dart) */
.tpl-live .tpl-ic-template,
.tpl-live[data-mode="template"] .tpl-ic-list {
  display: none;
}

.tpl-live[data-mode="template"] .tpl-ic-template {
  display: block;
}

.tpl-live [data-tpl-title],
.tpl-live [data-tpl-clock] {
  transition: opacity 0.2s ease;
}

.tpl-live .is-swap {
  opacity: 0;
}

.tpl-live .jl-tab,
.tpl-live .tpl-primary,
.tpl-live .tpl-action,
.tpl-live .tpl-reminder-card {
  transition: transform 0.12s ease;
}

.tpl-live .is-pressed {
  transform: scale(0.95);
}

/* Общие элементы AppPopupDialog */
.tpl-glass {
  border: 1.2px solid rgba(255, 255, 255, 0.82);
  background: linear-gradient(180deg, rgba(254, 255, 255, 0.98), rgba(234, 242, 255, 0.96));
  box-shadow: 0 18px 38px rgba(11, 61, 155, 0.22);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  color: #071735;
}

.tpl-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 18px;
  background: linear-gradient(135deg, #3d82f6, #0753e6);
  box-shadow: 0 7px 14px rgba(7, 83, 230, 0.2);
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.tpl-text-btn {
  display: grid;
  min-height: 46px;
  place-items: center;
  color: #123e9d;
  font-size: 15px;
  font-weight: 600;
}

/* ---------- «Сохранить этот список как шаблон?» ---------- */

.tpl-suggest {
  position: absolute;
  z-index: 10;
  top: 124px;
  right: 16px;
  left: 16px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px) scale(0.97);
  transition:
    opacity 0.3s ease,
    transform 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tpl-live.is-suggest .tpl-suggest {
  opacity: 1;
  transform: none;
}

.tpl-suggest-card {
  padding: 26px 24px 18px;
  border-radius: 34px;
  text-align: center;
}

.tpl-suggest-title {
  display: block;
  font-size: 25px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.6px;
}

.tpl-suggest-body {
  margin: 13px 0 22px;
  color: #526a9b;
  font-size: 14px;
  line-height: 1.42;
}

/* Круглая кнопка-стрелка над карточкой — указывает на меню списка */
.tpl-suggest-arrow {
  position: absolute;
  z-index: 1;
  top: -32px;
  right: 1px;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(10, 132, 255, 0.23);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 7px 18px rgba(22, 32, 48, 0.12);
  color: #007aff;
}

.tpl-live.is-suggest .tpl-suggest-arrow {
  animation: tpl-arrow 1.1s ease-in-out infinite alternate;
}

.tpl-suggest-arrow svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

@keyframes tpl-arrow {
  from { transform: translateY(4px); }
  to { transform: translateY(-4px); }
}

/* ---------- AppBlockingProgressOverlay «Создаём шаблон» ---------- */

.tpl-blocking {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0 26px;
  background: rgba(26, 52, 113, 0.4);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.tpl-live.is-creating .tpl-blocking {
  opacity: 1;
}

.tpl-blocking-card {
  width: 100%;
  max-width: 340px;
  padding: 26px 24px 24px;
  border-radius: 30px;
  text-align: center;
}

.tpl-blocking-card b {
  display: block;
  margin-top: 18px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.16;
}

.tpl-blocking-card p {
  margin: 10px 0 0;
  color: #526a9b;
  font-size: 14px;
  line-height: 1.4;
}

/* CupertinoActivityIndicator(radius: 15) */
.tpl-spinner {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  margin: 0 auto;
}

.tpl-spinner i {
  position: absolute;
  top: 0;
  left: 13.2px;
  width: 3.6px;
  height: 8.4px;
  border-radius: 2px;
  background: #8e8e93;
  transform-origin: 1.8px 15px;
  animation: tpl-spin 1s linear infinite;
}

@keyframes tpl-spin {
  from { opacity: 1; }
  to { opacity: 0.22; }
}

/* ---------- showTemplateCreatedDialog ---------- */

.tpl-dialog {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 20px;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.tpl-live.is-created .tpl-dialog {
  opacity: 1;
}

.tpl-popup {
  width: 100%;
  padding: 28px 24px 20px;
  border-radius: 34px;
  text-align: center;
  transform: scale(1.06);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tpl-live.is-created .tpl-popup {
  transform: none;
}

.tpl-popup-title {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.6px;
}

.tpl-popup-body {
  margin: 16px 0;
  font-size: 16px;
  line-height: 1.42;
}

.tpl-reminder-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 17px;
  gap: 12px;
  align-items: start;
  margin-bottom: 24px;
  padding: 14px;
  border: 1px solid #cfe0ff;
  border-radius: 16px;
  background: #f1f6ff;
  text-align: left;
}

.tpl-reminder-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #ddeaff;
  color: #0753e6;
}

.tpl-reminder-icon svg {
  width: 20px;
  height: 20px;
}

.tpl-live .tl-fill {
  fill: currentColor;
  stroke: none;
}

.tpl-reminder-text b,
.tpl-reminder-text small,
.tpl-reminder-text em {
  display: block;
}

.tpl-reminder-text b {
  font-size: 15px;
  font-weight: 700;
}

.tpl-reminder-text small {
  margin-top: 4px;
  color: #526a9b;
  font-size: 13px;
  line-height: 1.3;
}

.tpl-reminder-text em {
  margin-top: 8px;
  color: #0753e6;
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
}

.tpl-reminder-chevron {
  width: 17px;
  height: 17px;
  margin-top: 9px;
  color: #0753e6;
  stroke-width: 2.6;
}

/* ---------- Пуш напоминания шаблона (.ntl-push из notes-live.css) ---------- */

.tpl-live .tpl-push {
  position: absolute;
  z-index: 14;
  top: 12px;
  right: 10px;
  left: 10px;
  margin: 0;
  padding: 13px 15px;
}

.tpl-live.is-push .tpl-push {
  opacity: 1;
  transform: none;
}

.tpl-push > span > b {
  white-space: normal;
}

/* ---------- «Добавить из шаблона» ---------- */

.tpl-picker {
  position: absolute;
  z-index: 11;
  inset: 0;
  background: linear-gradient(180deg, #dfeaff 0%, #eff4ff 50%, #d6e4ff 100%);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.12);
  transform: translateX(104%);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tpl-live.is-picker .tpl-picker {
  transform: none;
}

.tpl-picker-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 44px;
  padding: 0 10px 0 6px;
  color: #007aff;
  font-size: 17px;
}

.tpl-picker-nav span {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}

.tpl-picker-nav span:last-child {
  justify-content: flex-end;
}

.tpl-picker-nav svg {
  width: 26px;
  height: 26px;
  stroke-width: 2.4;
}

.tpl-picker-nav strong {
  color: #000000;
  font-size: 17px;
  font-weight: 600;
}

.tpl-picker-body {
  display: grid;
  gap: 12px;
  padding: 20px 16px 28px;
}

/* CupertinoSlidingSegmentedControl */
.tpl-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border-radius: 9px;
  background: rgba(118, 118, 128, 0.12);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.tpl-segment span {
  padding: 6px 0;
  border-radius: 7px;
}

.tpl-segment .is-on {
  background: #ffffff;
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.12),
    0 3px 1px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

.tpl-picker-hint {
  margin: 0;
  color: rgba(60, 60, 67, 0.6);
  font-size: 13px;
}

/* ListTile шаблона: collectionSurfaceDecoration(template: true) */
.tpl-tile {
  margin: 1.5px 0;
  padding: 12px 12px 16px;
  border: 0.9px solid rgba(212, 106, 90, 0.28);
  border-radius: 22px;
  background: linear-gradient(135deg, #fffafa, #fff0f0);
  box-shadow:
    0 5px 16px rgba(0, 0, 0, 0.055),
    0 1px 4px rgba(0, 0, 0, 0.02);
}

.tpl-tile-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tpl-tile-main {
  min-width: 0;
  padding: 4px;
}

.tpl-tile-title {
  display: block;
  overflow: hidden;
  font-size: 17px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-tile-main .ntl-people {
  margin-top: 4px;
}

.tpl-tile-dates,
.tpl-tile-count {
  display: block;
  color: rgba(60, 60, 67, 0.6);
  font-size: 12px;
}

.tpl-tile-dates {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-tile-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* ListTileTemplateChip */
.tpl-chip-template {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 0.8px solid rgba(212, 106, 90, 0.24);
  border-radius: 999px;
  background: rgba(212, 106, 90, 0.12);
  color: #d46a5a;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* ListTileMetaChip */
.tpl-meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 0.8px solid rgba(216, 218, 222, 0.74);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.74), rgba(237, 239, 242, 0.8));
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
  color: #66707c;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.tpl-meta-chip svg {
  width: 13px;
  height: 13px;
  color: #7e8794;
  stroke-width: 2;
}

.tpl-meta-chip.is-blue {
  color: #245eaa;
}

.tpl-meta-chip.is-blue svg {
  color: #2f80ed;
}

.tpl-tile-side {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 6px;
}

.tpl-tile-chevron {
  width: 32px;
  height: 32px;
  padding: 6px;
  color: #2f80ed;
  stroke-width: 2.4;
}

.tpl-tile-desc {
  display: grid;
  width: 38px;
  height: 20px;
  margin: 12px 0;
  place-items: center;
  border: 0.8px solid rgba(216, 218, 222, 0.72);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  color: #b8bec7;
}

.tpl-tile-desc svg {
  width: 12px;
  height: 12px;
}

.tpl-tile-count {
  margin-top: 8px;
}

/* _TemplatePickerActionButton */
.tpl-tile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.tpl-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 9px 10px;
  border: 0.8px solid #e0e3e6;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #f7f8f9);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
  color: #386b8b;
  font-size: 12px;
  font-weight: 600;
}

.tpl-action svg {
  width: 15px;
  height: 15px;
  color: #5694bc;
  stroke-width: 2.4;
}

/* ---------- Адаптив ---------- */

@media (max-width: 1180px) {
  .tpl-live {
    --jl-s: 0.54;
    padding: 24px 32px 48px;
  }
}

@media (max-width: 980px) {
  .tpl-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    margin-top: 36px;
  }

  .tpl-live {
    justify-self: center;
    --jl-s: 0.58;
  }

  .tpl-layout .lists-template-steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: none;
  }
}

@media (max-width: 680px) {
  .tpl-layout {
    margin-top: 30px;
  }

  .tpl-live {
    justify-self: stretch;
    --jl-s: 0.6;
    margin: 0 -8px;
    padding: 18px 8px 40px;
    border-radius: 24px;
  }

  .tpl-live .jl-chip {
    min-width: 0;
  }

  .tpl-layout .lists-template-steps {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .tpl-live {
    --jl-s: 0.54;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tpl-live *,
  .tpl-live *::before,
  .tpl-live *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Подсказка взглядом на карточку напоминания в диалоге */
.tpl-reminder-card {
  transition:
    transform 0.12s ease,
    box-shadow 0.4s ease;
}

.tpl-reminder-card.is-flash {
  box-shadow: 0 4px 22px 1px rgba(7, 83, 230, 0.24);
}
