/* ============================================
   Генератор справок — стили
   ============================================ */
@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Marck Script";
  src: url("../fonts/MarckScript-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #f4f6fa;
  --paper: #ffffff;
  --ink: #1a2233;
  --ink-soft: #4a5468;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --border: #e2e8f0;
  --hand-blue: #1a3a8a;
  --shadow: 0 8px 24px rgba(15, 23, 42, .08);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, .12);
  --radius: 14px;
  --radius-sm: 8px;
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-base);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ============== Шапка ============== */
.topbar {
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 60%, #3b82f6 100%);
  color: #fff;
  padding: 18px 0;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand__icon { font-size: 32px; line-height: 1; }
.brand__title { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.brand__sub { font-size: 12.5px; opacity: .85; margin: 2px 0 0; }

.tabs { display: flex; gap: 6px; background: rgba(255,255,255,.12); padding: 5px; border-radius: 12px; }
.tab {
  background: transparent;
  color: rgba(255,255,255,.85);
  border: 0;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s;
}
.tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.tab--active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

/* ============== Лейаут ============== */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 28px;
  padding: 28px 24px;
  align-items: start;
}

/* ============== Форма ============== */
.form {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.form__row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fafbfc;
  transition: all .15s;
  width: 100%;
  color: var(--ink);
}
.field input:focus {
  outline: 0;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.form__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.btn {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--ghost { background: #f1f5f9; color: var(--ink); }
.btn--ghost:hover { background: #e2e8f0; }

.hint {
  margin: 12px 0 0;
  padding: 9px 11px;
  background: #f0f9ff;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 12px;
  color: #075985;
  line-height: 1.4;
}

.form__row--hidden { display: none; }

/* ============== Превью ============== */
.preview {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Скан-бланк + рукопись сверху */
.cert-frame {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid #e5e7eb;
  width: 100%;
}
.cert-frame--hidden { display: none; }

.cert-bg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none; /* кликаем по .hand */
}

/* Overlay с рукописными полями */
.cert-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none; /* кликабельны только .hand */
}
.hand {
  position: absolute;
  font-family: "Caveat", "Marck Script", "Bradley Hand", cursive;
  color: var(--hand-blue);
  font-weight: 500;
  letter-spacing: .2px;
  line-height: 1;
  padding: 0;
  margin: 0;
  outline: 0;
  white-space: nowrap;
  pointer-events: auto;
  cursor: text;
  border-bottom: 1px dashed transparent;
  transition: background .15s;
  transform-origin: left center;
}
.hand:hover {
  background: rgba(37, 99, 235, .08);
}
.hand:focus {
  background: rgba(37, 99, 235, .14);
  border-bottom-color: var(--primary);
  border-radius: 2px;
}

/* ============== Справка 1: Бодрость (600x415) ============== */
/* Размеры в % от ширины фрейма */
.hand--fio     { top: 25.5%; left: 4%;  font-size: 4.2cqw; }   /* ФИО - 25.8% y, x=30% */
.hand--birth   { top: 25.5%; left: 65%; font-size: 3.6cqw; }   /* Дата рождения - x=66.5% */
.hand--period  { top: 30%;   left: 39%; font-size: 3.5cqw; }   /* Период - y=30.8% */
.hand--diag    { top: 39%;   left: 30%; font-size: 3.4cqw; }   /* Диагноз - y=42% */
.hand--issued  { top: 55.5%; left: 27%; font-size: 3.4cqw; }   /* Дата выдачи - y=57% */
.hand--post    { top: 79%;   left: 42%; font-size: 3.2cqw; }   /* Должность врача - низ */
.hand--doctor  { top: 79%;   left: 65%; font-size: 3.4cqw; }   /* Врач - низ */

.cert-frame[data-cert="t1"] {
  container-type: inline-size;
}

/* ============== Справка 2: 095/у (705x999) ============== */
.cert-frame[data-cert="t2"] {
  container-type: inline-size;
}
.hand--fio2      { top: 21.0%; left: 38%; font-size: 2.7cqw; }
.hand--birth2    { top: 23.5%; left: 38%; font-size: 2.4cqw; }
.hand--work      { top: 28.0%; left: 50%; font-size: 2.5cqw; }
.hand--contact   { top: 32.0%; left: 75%; font-size: 2.5cqw; }
.hand--period2   { top: 36.0%; left: 38%; font-size: 2.5cqw; }
.hand--diag2     { top: 56.5%; left: 13%; font-size: 2.5cqw; }
.hand--doctor2   { top: 86.5%; left: 12%; font-size: 2.5cqw; }
.hand--doctorFull2 { top: 88.0%; left: 30%; font-size: 2.3cqw; }
.hand--head2     { top: 86.5%; left: 60%; font-size: 2.5cqw; }
.hand--issued2   { top: 91.0%; left: 60%; font-size: 2.5cqw; }

/* ============== Подвал ============== */
.footer {
  padding: 32px 24px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}

/* ============== Адаптив ============== */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .form { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .form__row { grid-template-columns: 1fr; }
  .topbar__inner { flex-direction: column; align-items: stretch; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 9px 8px; font-size: 13px; }
}

/* ============== Печать ============== */
@media print {
  body { background: #fff; }
  .topbar, .form, .footer, .form__actions, .hint { display: none !important; }
  .layout { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .preview { gap: 0; }
  .cert-frame {
    box-shadow: none;
    border: 0;
    border-radius: 0;
    margin: 0;
    page-break-after: always;
  }
  .cert-frame:last-child { page-break-after: auto; }
  .hand { background: transparent !important; border: 0 !important; }
  @page { size: A4; margin: 10mm; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
