/* Шрифт Euclid Circular A подключается через assets/fonts.css (base64). */
:root {
  --blue: #0065ff;
  --blue-600: #005fcc;
  --ink: #0d1b2a;
  --muted: #6b7785;
  --line: #e3e8ef;
  --bg: #f4f6fa;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Euclid Circular A", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: 80px; /* место под приклеенную нижнюю панель */
}

/* ---- Приклеенная нижняя панель действий ---- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 18px rgba(13, 27, 42, .07);
}
.actionbar-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
}
.page-credit {
  max-width: 1400px; margin: 8px auto 0; padding: 18px 24px 8px;
  border-top: 1px solid var(--line);
  text-align: center; font-size: 12px; color: #b6bfca; user-select: none;
}
.page-credit a { color: #a2acba; text-decoration: underline; text-underline-offset: 2px; }
.page-credit a:hover { color: var(--blue); }
.ab-btn {
  border: 1px solid var(--blue); background: #eef4ff; color: var(--blue);
  padding: 12px 22px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 9px;
}
.ab-btn svg { width: 18px; height: 18px; flex: none; }
.ab-btn { white-space: nowrap; }
.ab-short { display: none; } /* короткая мобильная подпись — включается в @media */
.ab-btn:hover { background: #e0ecff; }
.ab-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.ab-primary:hover { background: var(--blue-600); }
.ab-ghost { background: #fff; }
.ab-btn.is-done { background: var(--blue); color: #fff; border-color: var(--blue); }
.ab-btn:disabled { opacity: .5; cursor: default; }

/* ---- Шапка ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 32px; width: auto; display: block; }
.brand-title { font-weight: 600; font-size: 18px; }
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.tab {
  border: 0; background: transparent; padding: 9px 18px; border-radius: 9px;
  font: inherit; font-weight: 500; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.tab svg { width: 16px; height: 16px; flex: none; }
.tab.is-active { background: #fff; color: var(--blue); box-shadow: 0 1px 4px rgba(13,27,42,.08); }

/* Сегмент-переключатель (дочка/сын) */
.seg { display: inline-flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.seg-btn {
  border: 0; background: transparent; padding: 8px 22px; border-radius: 7px;
  font: inherit; font-weight: 500; color: var(--muted); cursor: pointer;
}
.seg-btn.is-active { background: #fff; color: var(--blue); box-shadow: 0 1px 4px rgba(13,27,42,.08); }

/* ---- Раскладка ---- */
.layout {
  display: grid; grid-template-columns: 420px 1fr; gap: 20px;
  padding: 20px 24px; align-items: start; max-width: 1400px; margin: 0 auto;
}
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.is-hidden { display: none !important; }

/* Кнопка «Очистить все поля» — в правом верхнем углу, в своей полоске сверху,
   чтобы не налезать на первую строку формы (дату). */
.form-panel { position: relative; padding-top: 56px; }
.btn-reset {
  position: absolute; top: 14px; right: 14px; z-index: 3;
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-reset svg { width: 17px; height: 17px; }
.btn-reset:hover { background: #fff5f5; border-color: #f0b4b4; color: #e23b3b; }
.form-title {
  position: absolute; top: 20px; left: 20px; right: 60px; margin: 0;
  font-size: 16px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Поля ---- */
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="date"] {
  width: 100%; padding: 11px 13px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input[type="text"]:focus, input[type="date"]:focus { outline: none; border-color: var(--blue); }
.date-row { display: flex; align-items: center; gap: 12px; }
.date-row input[type="date"] { flex: 0 0 auto; width: auto; }
/* Стиппер даты: ‹ дата ›  — текст по центру, стрелки в кругляшках по бокам */
.date-stepper { flex: 1; display: flex; align-items: center; gap: 8px; }
.date-preview { flex: 1; text-align: center; font-weight: 600; color: var(--blue); }
.date-arrow {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--blue); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.date-arrow svg { width: 16px; height: 16px; }
.date-arrow:hover { background: #eef4ff; border-color: var(--blue); }

/* Крестик очистки внутри текстового поля (справа) */
.field-clear { position: relative; display: block; }
.field-clear > input { padding-right: 36px; }
.clear-x {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border: 0; border-radius: 50%; padding: 0;
  background: var(--bg); color: var(--muted); cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.field-clear.has-value .clear-x { display: inline-flex; }
.clear-x svg { width: 13px; height: 13px; }
.clear-x:hover { background: #e7ebf2; color: var(--ink); }

/* ---- Карточка именинника ---- */
.person {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px;
  padding: 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px;
}
.person-fields { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.btn-remove {
  align-self: flex-start; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; padding: 0; text-decoration: underline;
}
.btn-remove:hover { color: #d23; }

/* ---- Дропзона фото ---- */
.dropzone-wrap { display: flex; flex-direction: column; gap: 8px; }
.form[data-form="newcomer"] > .dropzone-wrap { margin-bottom: 16px; }
.dropzone {
  width: 96px; height: 96px; border: 2px dashed var(--line); border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  text-align: center; cursor: pointer; overflow: hidden; background: #fafbfd; position: relative;
}
.dz-ico { display: flex; color: var(--muted); opacity: .6; }
.dz-ico svg { width: 22px; height: 22px; }
.form-panel .form[data-form="newcomer"] .dropzone { width: 140px; height: 140px; }
.dropzone.is-over { border-color: var(--blue); background: #eef4ff; }
.dropzone.has-photo { border-style: solid; border-color: var(--line); }
.dz-hint { font-size: 10px; line-height: 1.3; color: var(--muted); padding: 4px; }
.dz-hint-touch { display: none; } /* подсказка для тач — включается в @media */
.dropzone img { width: 100%; height: 100%; object-fit: cover; }
.photo-tools { display: flex; flex-direction: column; gap: 3px; }
.photo-tools .zoom { width: 100%; min-width: 0; margin: 0; }
.zoom-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Крестик удаления — бейдж в углу самой миниатюры */
.dz-remove {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px;
  border: 0; border-radius: 50%; background: rgba(13, 27, 42, .62); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer; padding: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
}
.dz-remove:hover { background: #e23b3b; }

/* ---- Кнопки ---- */
.btn-add {
  width: 100%; padding: 11px; border: 1px dashed var(--blue); background: #eef4ff;
  color: var(--blue); border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn-add:disabled { opacity: .4; cursor: default; }

/* ---- Блок поздравления ---- */
.congrats { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.congrats-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.congrats-head .field-label { margin-bottom: 0; }
.btn-icon {
  border: 0; background: var(--bg); width: 36px; height: 36px; border-radius: 9px;
  cursor: pointer; color: var(--blue);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: #e7ebf2; }
.congrats textarea {
  width: 100%; padding: 12px 13px; font: inherit; font-size: 14px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 10px; resize: vertical; color: var(--ink);
  box-sizing: border-box;
}
.congrats textarea:focus { outline: none; border-color: var(--blue); }
.btn-copy {
  margin-top: 8px; width: 100%; padding: 11px; border: 1px solid var(--blue);
  background: #eef4ff; color: var(--blue); border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn-copy:hover { background: #e0ecff; }
.btn-copy.is-done { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---- Превью ---- */
.preview-panel { display: flex; flex-direction: column; gap: 14px; }
.preview-stage {
  background: repeating-conic-gradient(#eef1f6 0% 25%, #f7f9fc 0% 50%) 50% / 24px 24px;
  border-radius: 12px; padding: 18px; display: flex; align-items: center; justify-content: center;
  min-height: 360px;
}
#preview {
  max-width: 100%; max-height: 70vh; border-radius: 6px; box-shadow: 0 6px 24px rgba(13,27,42,.18);
  cursor: grab;
}
#preview:active { cursor: grabbing; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); }
.btn-download {
  border: 0; background: var(--blue); color: #fff; padding: 12px 26px; border-radius: 10px;
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
}
.btn-download:hover { background: var(--blue-600); }
.btn-download:disabled { opacity: .5; cursor: default; }

/* Кнопки мобильного фуллскрина — на десктопе их нет (включаются в @media ниже). */
.preview-expand, .preview-close { display: none; }

/* ---- Плашка «Доступна новая версия — обновить» ---- */
#update-pill {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px; z-index: 60;
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 11px 18px;
  background: var(--blue); color: #fff; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; box-shadow: 0 6px 20px rgba(13, 27, 42, .22);
}
#update-pill svg { width: 16px; height: 16px; flex: none; }
#update-pill:hover { background: var(--blue-600); }

/* ============================================================
   МОБИЛЬНЫЙ ИНТЕРФЕЙС (≤ 900px) — не адаптив, а свой поток:
   • липкий мини-превью сверху (живой), тап → фуллскрин;
   • форма скроллится под ним, получая максимум высоты;
   • экспорт живёт в фуллскрин-оверлее (нижняя панель там же),
     поэтому фиксированной нижней панели в обычном режиме нет.
   Десктоп (≥ 901px) использует правила ВЫШЕ и не меняется.
   ============================================================ */
@media (max-width: 900px) {
  body {
    /* место под фиксированную нижнюю панель действий (она остаётся и на мобиле) */
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  /* Шапка: бренд сверху, вкладки — строкой с горизонтальным скроллом (3 типа) */
  .topbar {
    flex-direction: column; align-items: stretch; gap: 10px;
    padding: 12px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  /* 3 типа не влезают в строку → сетка 3-в-ряд, иконка над подписью (подпись переносится).
     Все три видны сразу, без скрытого горизонтального скролла. */
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tab {
    flex-direction: column; gap: 4px; white-space: normal; text-align: center;
    padding: 9px 4px; font-size: 12px; line-height: 1.15; min-height: 58px;
    justify-content: center;
  }
  .tab svg { width: 18px; height: 18px; }

  /* Одна колонка: превью сверху (липкое), форма под ним */
  .layout {
    grid-template-columns: 1fr; gap: 12px; padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .panel { padding: 16px; }
  .form-panel { padding-top: 56px; } /* верхняя полоска (заголовок + ластик) */

  /* ---- Липкий мини-превью (peek) ---- */
  /* sticky сам по себе — позиционированный предок для абсолютного чипа «Открыть» */
  .preview-panel { order: -1; position: sticky; top: 0; z-index: 20; padding: 8px; gap: 0; }
  .preview-stage { min-height: 0; padding: 6px; background-size: 14px 14px; }
  #preview {
    max-height: 88px; max-width: 100%; touch-action: none;
    box-shadow: 0 2px 8px rgba(13,27,42,.14); border-radius: 4px;
  }
  .preview-bar { display: none; } /* размер показываем только в фуллскрине */

  /* Чип «Открыть» поверх мини-превью — вся область превью тач-цель */
  .preview-expand {
    display: flex; align-items: flex-end; justify-content: flex-end;
    position: absolute; inset: 0; margin: 0; padding: 10px;
    border: 0; background: transparent; cursor: pointer; z-index: 2;
  }
  .preview-expand-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 11px; border-radius: 999px;
    background: rgba(13,27,42,.74); color: #fff;
    font: inherit; font-weight: 600; font-size: 12px;
    box-shadow: 0 2px 8px rgba(13,27,42,.2);
  }
  .preview-expand-chip svg { width: 14px; height: 14px; }

  /* Поля: 16px — iOS не зумит при фокусе; тач-цели крупнее */
  input[type="text"], input[type="date"], .congrats textarea { font-size: 16px; }
  input[type="text"], input[type="date"] { padding: 13px 14px; }
  .date-arrow { width: 44px; height: 44px; }
  .clear-x { width: 28px; height: 28px; }
  /* дата в одну строку: календарь занимает место, стрелки ‹ › прижаты справа.
     синий текст-превью дня на мобиле убираем — нативный инпут уже показывает дату */
  .date-row { flex-wrap: nowrap; gap: 10px; }
  .date-row input[type="date"] { flex: 1 1 auto; width: auto; min-width: 0; }
  .date-stepper { flex: 0 0 auto; gap: 8px; }
  .date-preview { display: none; }
  .field-clear > input { padding-right: 42px; }
  .btn-reset { width: 40px; height: 40px; }
  .btn-add { padding: 14px; }

  /* подсказка дропзоны — мобильный вариант (без перетаскивания/Ctrl+V) */
  .dz-hint-full { display: none; }
  .dz-hint-touch { display: block; }

  /* Нижняя панель действий остаётся видимой на мобиле (копирование в один тап, без фуллскрина).
     z-index выше оверлея — в фуллскрине та же панель доступна внизу. */
  .actionbar { z-index: 90; padding-bottom: env(safe-area-inset-bottom); }
  #update-pill { bottom: calc(84px + env(safe-area-inset-bottom)); font-size: 13px; }

  /* ============ ФУЛЛСКРИН-ПРОСМОТР (body.preview-open) ============ */
  body.preview-open { overflow: hidden; }
  body.preview-open .preview-panel {
    position: fixed; inset: 0; z-index: 80; order: 0;
    border: 0; border-radius: 0; padding: 0;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    background: #0d1b2a;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: calc(98px + env(safe-area-inset-bottom)); /* место под нижнюю панель */
  }
  body.preview-open .preview-stage {
    flex: 1 1 auto; width: 100%; min-height: 0;
    background: transparent; padding: 16px;
    animation: previewIn .22s cubic-bezier(.22,1,.36,1);
  }
  body.preview-open #preview {
    max-height: 100%; max-width: 100%;
    box-shadow: 0 14px 50px rgba(0,0,0,.5); border-radius: 8px;
  }
  body.preview-open .preview-bar {
    display: flex; justify-content: center; flex: none;
    padding: 0 16px 10px;
  }
  body.preview-open .hint { color: rgba(255,255,255,.66); font-size: 12px; }

  /* чип «Открыть» прячем — в фуллскрине canvas снова ловит жесты (пан/зум фото) */
  body.preview-open .preview-expand { display: none; }

  /* крестик закрытия */
  body.preview-open .preview-close {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; z-index: 82;
    top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
    width: 44px; height: 44px; border-radius: 50%; padding: 0; border: 0;
    background: rgba(255,255,255,.16); color: #fff; cursor: pointer;
  }
  body.preview-open .preview-close:hover { background: rgba(255,255,255,.26); }
  body.preview-open .preview-close svg { width: 20px; height: 20px; }

  /* нижняя панель: 3 кнопки в один ряд, иконка + короткая подпись (упрощённый вид) */
  .actionbar-inner {
    padding: 10px 14px; gap: 8px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .ab-btn {
    flex: 1 1 0; min-width: 0; gap: 6px; justify-content: center;
    white-space: nowrap; padding: 13px 8px; font-size: 13px; min-height: 48px;
  }
  .ab-full { display: none; }
  .ab-short { display: inline; }

  body.preview-open #update-pill { display: none; }
}

@keyframes previewIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}

@media (max-width: 380px) {
  .ab-btn { font-size: 12px; }
  .ab-btn svg { width: 16px; height: 16px; }
  .tab { font-size: 11px; padding: 8px 3px; }
}

@media (prefers-reduced-motion: reduce) {
  body.preview-open .preview-stage { animation: none; }
}
