/* What: базовые стили. Why: тёмная тема, центрирование. */
@font-face {
  font-family: 'OCR-B';
  src: url('https://cdn.jsdelivr.net/gh/raisty/OCR-B@1.1/dist/OCR-B.ttf') format('truetype');
  font-display: block;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
  min-height: 100vh;
}

.page {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}

.form-section {
  padding: 1.5rem;
  background: #1a1a1a;
  border-radius: 12px;
  border: 1px solid #333;
  position: sticky;
  top: 2rem;
}
.form-section h1 { font-size: 1.3rem; margin-bottom: 1.2rem; color: #fff; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.form-group { margin-bottom: 0.8rem; }
.form-group label { display: block; font-size: 0.8rem; color: #aaa; margin-bottom: 0.2rem; }
.source-document-section {
  margin-top: 1.2rem;
  padding: 1rem 0 0.35rem;
  border-top: 1px solid #555;
}
.source-document-section h2 {
  margin-bottom: 0.35rem;
  color: #c0a050;
  font-size: 0.95rem;
}
.source-document-section p {
  margin-bottom: 0.9rem;
  color: #888;
  font-size: 0.75rem;
  line-height: 1.35;
}
.declaration-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 0.2rem;
  color: #aaa;
  font-size: 0.75rem;
  line-height: 1.35;
  cursor: pointer;
}
.declaration-checkbox input { margin-top: 0.15rem; accent-color: #c0a050; }
.source-document-section .form-group label {
  min-height: 2.4em;
  display: flex;
  align-items: flex-end;
}
.form-group input, .form-group select {
  width: 100%; padding: 0.5rem 0.7rem; background: #111;
  border: 1px solid #444; border-radius: 6px; color: #fff; font-size: 0.9rem;
}
.form-group select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23c0a050' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 14px 14px;
}
.form-group select option { background: #1a1a1a; color: #fff; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: #c0a050; }
.native-select { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.custom-select { position: relative; width: 100%; }
.custom-select-trigger {
  width: 100%; min-height: 38px; padding: 0.5rem 2.2rem 0.5rem 0.7rem;
  display: flex; align-items: center; justify-content: space-between;
  background: #111; border: 1px solid #444; border-radius: 6px;
  color: #fff; font: inherit; font-size: 0.9rem; text-align: left; cursor: pointer;
}
.custom-select-trigger:hover, .custom-select.open .custom-select-trigger,
.custom-select-trigger:focus-visible { border-color: #c0a050; outline: none; }
.custom-select-chevron {
  position: absolute; right: 0.75rem; width: 9px; height: 9px;
  border-right: 2px solid #c0a050; border-bottom: 2px solid #c0a050;
  transform: translateY(-3px) rotate(45deg); transition: transform .15s ease;
}
.custom-select.open .custom-select-chevron { transform: translateY(2px) rotate(225deg); }
.custom-select-menu {
  position: absolute; z-index: 20; top: calc(100% + 5px); left: 0; right: 0;
  display: none; padding: 0.3rem; background: #1a1a1a;
  border: 1px solid #555; border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.45);
}
.searchable-select .custom-select-search {
  display: block;
  width: 100%;
  min-height: 38px;
  padding: 0.5rem 0.7rem;
  background: #111;
  border: 1px solid #444;
  border-radius: 6px;
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
}
.searchable-select .custom-select-search:focus { outline: none; border-color: #c0a050; }
.searchable-input-wrap { position: relative; }
.searchable-input-wrap .custom-select-chevron {
  right: 0.9rem;
  top: 50%;
  pointer-events: none;
}
.searchable-select.open .custom-select-chevron { transform: translateY(2px) rotate(225deg); }
.searchable-select .custom-select-menu { max-height: 220px; overflow-y: auto; }
.searchable-select .custom-select-option { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.custom-select-empty { padding: 0.55rem 0.65rem; color: #888; font-size: 0.82rem; }
.custom-select.open .custom-select-menu { display: grid; gap: 2px; }
.custom-select-option {
  width: 100%; padding: 0.55rem 0.65rem; background: transparent;
  border: 1px solid transparent; border-radius: 5px; color: #ddd;
  font: inherit; font-size: 0.9rem; text-align: left; cursor: pointer;
}
.custom-select-option:hover, .custom-select-option[aria-selected="true"] {
  background: #c0a050; color: #000; border-color: #d4b460;
}
.file-picker {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.25rem 0.45rem;
  background: #111;
  border: 1px solid #444;
  border-radius: 6px;
}
.file-picker:focus-within { border-color: #c0a050; }
.file-picker-button {
  flex: 0 0 auto;
  padding: 0.35rem 0.65rem;
  background: #292929;
  border: 1px solid #666;
  border-radius: 4px;
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
}
.file-picker-button:hover { background: #363636; border-color: #c0a050; }
.file-picker-name {
  min-width: 0;
  overflow: hidden;
  color: #aaa;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* What: изолирует редактор портрета от остальных блоков страницы. Why: редактор не должен менять общий дизайн ID-карты. */
.photo-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, .78);
}
.photo-editor-modal[hidden] { display: none; }
.photo-editor-dialog {
  width: min(680px, 100%);
  max-height: min(94vh, 900px);
  overflow: auto;
  padding: 1.1rem;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 12px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .55);
}
.photo-editor-header h2 { color: #fff; font-size: 1.15rem; }
.photo-editor-header p {
  margin-top: .35rem;
  color: #aaa;
  font-size: .78rem;
  line-height: 1.35;
}
.photo-editor-stage {
  position: relative;
  width: min(420px, calc(100% - 90px));
  flex: 0 1 420px;
  aspect-ratio: 35 / 45;
  margin: 1rem 0;
  overflow: hidden;
  background: #111;
  border: 2px solid #d4b460;
}
.photo-editor-stage .cropper-container,
.photo-editor-stage .cropper-wrap-box,
.photo-editor-stage .cropper-canvas,
.photo-editor-stage .cropper-drag-box,
.photo-editor-stage .cropper-modal,
.photo-editor-stage .cropper-view-box { width: 100%; height: 100%; }
.photo-editor-stage .cropper-crop-box { opacity: 0; }
.photo-editor-stage .cropper-face { background: transparent; }
.photo-editor-face-guide,
.photo-editor-shoulder-guide {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  border: 2px dashed rgba(255, 255, 255, .8);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .08);
}
.photo-editor-face-guide {
  top: 8%;
  left: 18%;
  width: 64%;
  height: 70%;
  border-radius: 50%;
}
.photo-editor-shoulder-guide {
  left: 3%;
  bottom: 4%;
  width: 94%;
  height: 30%;
  border-radius: 48% 48% 20% 20%;
  border-top-color: rgba(212, 180, 96, .95);
}
.photo-editor-controls,
.photo-editor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .45rem;
}
.photo-editor-stage-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
}
.photo-editor-pan-horizontal,
.photo-editor-pan-vertical {
  display: flex;
  gap: .45rem;
}
.photo-editor-pan-vertical { flex-direction: column; }
.photo-editor-pan-horizontal { justify-content: center; margin-bottom: .55rem; }
.photo-editor-pan-controls button {
  min-width: 76px;
  padding: .45rem .65rem;
  color: #eee;
  background: #292929;
  border: 1px solid #666;
  border-radius: 5px;
  cursor: pointer;
}
.photo-editor-pan-controls button:hover { border-color: #d4b460; }
.photo-editor-controls button,
.photo-editor-actions button {
  padding: .45rem .65rem;
  color: #eee;
  background: #292929;
  border: 1px solid #666;
  border-radius: 5px;
  cursor: pointer;
}
.photo-editor-controls button:hover,
.photo-editor-actions button:hover { border-color: #d4b460; }
.photo-editor-controls button:disabled,
.photo-editor-actions button:disabled { cursor: wait; opacity: .55; }
.photo-processing-status {
  min-height: 1.35rem;
  margin: .8rem 0;
  color: #d4b460;
  font-size: .8rem;
  text-align: center;
}
.photo-processing-status.error { color: #ff8d8d; }
.photo-processing-status.success { color: #8fe19b; }
.photo-editor-result-wrap { text-align: center; }
.photo-editor-result-wrap img {
  width: 112px;
  height: 144px;
  object-fit: contain;
  margin: 0 auto .8rem;
  background-image: url('assets/id-world-map-background.png');
  background-size: cover;
  border: 1px solid #777;
}
.photo-editor-actions { justify-content: flex-end; }
.photo-editor-actions button:last-child { color: #111; background: #d4b460; border-color: #e5ca7e; }

#submit-button {
  width: 100%; padding: 0.7rem; margin-top: 0.3rem;
  background: #c0a050; color: #000; border: none; border-radius: 6px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.submit-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #555;
}
.submit-section #submit-button { margin-top: 0; }
#submit-button:hover { background: #d4b460; }
#submit-button:disabled { background: #555; color: #888; cursor: not-allowed; }

.status-message { margin-top: 0.8rem; padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.85rem; }
.status-message.success { background: #1a3a1a; border: 1px solid #3a7a3a; color: #6c6; }
.status-message.error { background: #3a1a1a; border: 1px solid #7a3a3a; color: #d66; }
.hidden { display: none !important; }
.payment-panel { margin-top: 18px; padding: 16px; border: 1px solid #d7dbe3; border-radius: 10px; background: #f7f9fc; }
.payment-panel h3, .payment-panel p { margin-top: 0; }
.payment-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.preview-section {
  padding: 1.5rem; background: #1a1a1a; border-radius: 12px; border: 1px solid #333;
}
.preview-section h2 { font-size: 1.1rem; margin-bottom: 1rem; color: #fff; }

.preview-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.2rem; }
.tab-btn {
  padding: 0.4rem 1rem; background: #222; border: 1px solid #444;
  border-radius: 6px; color: #aaa; cursor: pointer; font-size: 0.85rem;
}
.tab-btn.active { background: #c0a050; color: #000; border-color: #c0a050; }

.preview-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.preview-card-item { display: flex; flex-direction: column; align-items: center; gap: 0.45rem; }
.preview-card-label { margin: 0; color: #c0a050; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }

/* ===================================================================
   ID-1 CARD — ICAO 9303 TD1, landscape
   85.6 × 53.98 мм → пропорции 1.586:1
   Используем px: 514 × 324
   =================================================================== */
.card {
  width: 514px;
  height: 324px;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
}
.card::before {
  display: none;
}
.card::after {
  content: 'SOVEREIGN  •  SOVEREIGN  •  SOVEREIGN  •  SOVEREIGN';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  pointer-events: none;
  z-index: 9;
  color: rgba(26,26,106,.35);
  font: 5px/1 'Courier New', monospace;
  letter-spacing: 1.2px;
  white-space: nowrap;
  overflow: hidden;
}

/* Temporary preview state: keep the security layer definitions for later re-enabling. */
.card::after,
.security-feature-microtext {
  display: none;
}

/* === FRONT SIDE ===
   Zone I: Header — full width, top, max 11mm (~66px)
   Zone V: Photo — left edge, 35×45mm (~210×270px)
   Zone II: Personal data — right of photo, upper
   Zone III: Document data — right of photo, middle
   Zone IV: Signature — right of photo, lower
*/
.card-front {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  grid-template-rows: 54px 270px;
  grid-template-areas:
    "header header"
    "photo  data";
  background-image: url('assets/id-world-map-background.png');
  background-size: cover;
  background-position: center;
}

/* Zone I: Header — full width top */
.zone-i {
  grid-area: header;
  background: transparent;
  color: #c0a050;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}
.zone-i-doc { font-size: 18px; font-weight: 800; letter-spacing: 2.2px; color: #e0bd62; text-shadow: -1px 0 #000, 1px 0 #000, 0 -1px #000, 0 1px #000; text-transform: uppercase; }

/* Zone V: Photo — left edge, full remaining height */
.zone-v {
  grid-area: photo;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  padding: 4px 6px 5px;
  position: relative;
  z-index: 1;
}
.card-photo {
  width: 170px;
  height: 219px;
  background: transparent;
  border: none;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder { color: #999; font-size: 14px; }
.zone-v-signature { width: 170px; }
.zone-v-signature .field-label { display: block; margin-bottom: 1px; text-align: center; }
.zone-v-signature .signature-area { height: 27px; border-radius: 2px; }
.zone-v-signature .sig-placeholder { font-size: 8px; }
.zone-v-signature .signature-area img { max-height: 24px; }

/* Zone data: II + III + IV — right column */
.zone-data {
  grid-area: data;
  display: flex;
  flex-direction: column;
  padding: 10px 20px 10px 0;
  position: relative;
  z-index: 1;
  min-width: 0;
}
.zone-document-meta {
  display: grid;
  grid-template-columns: .7fr 1.35fr .9fr;
  gap: 8px;
  padding-bottom: 3px;
  min-width: 0;
}
.zone-document-meta .field,
.zone-document-meta .field-value,
.zone-ii,
.zone-ii .field,
.zone-ii .field-value { min-width: 0; }

/* Zone II: Personal data — upper portion */
.zone-ii {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: 2px;
  flex: 1;
}

/* Zone III: Document data — middle portion */
.zone-iii {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 3px 0;
}

.signature-area {
  height: 48px;
  background: transparent;
  border: none;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.signature-area img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sig-placeholder { color: #bbb; font-size: 12px; font-style: italic; }

/* Field layout */
.field { display: flex; flex-direction: column; }
.zone-ii .field,
.zone-iii .field {
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
  min-height: 27px;
}
.field-label {
  font-size: 8px;
  font-weight: 600;
  color: #000;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  line-height: 1.2;
}
.field-value {
  font-size: 13px;
  font-weight: 700;
  color: #5b2a86;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === BACK SIDE === */
.card-back {
  background-image: url('assets/id-world-map-background.png');
  background-size: cover;
  background-position: center;
  display: flex;
  flex-direction: column;
}

/* Общий фон обеих сторон карты. Why: карта должна находиться под всеми зонами, фото и данными. */
.card-front,
.card-back {
  background-image: url('assets/id-world-map-background.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #f3f3f1;
}

/* Zone VI: Optional data — upper portion */
.zone-vi {
  flex: 1;
  position: relative;
  padding: 18px 24px;
  overflow: hidden;
  z-index: 1;
}
.zone-vi-authority { font-size: 12px; color: #555; }
.zone-vi-fields {
  width: 365px;
  display: grid;
  grid-template-columns: 90px 1fr;
  grid-template-areas:
    "eye issued"
    "height place"
    ". authority"
    "status global"
    ". .";
  gap: 8px 10px;
  margin-top: 12px;
}
.zone-vi-eye { grid-area: eye; }
.zone-vi-height { grid-area: height; }
.zone-vi-issued-by { grid-area: issued; }
.zone-vi-place { grid-area: place; }
.zone-vi-authority-code { grid-area: authority; }
.zone-vi-global-field { grid-area: global; }
.zone-vi-status { grid-area: status; }
.zone-vi-fields .field-value { font-size: 9px; }
.zone-vi-basis {
  width: calc(100% - 100px);
  margin-top: 12px;
  margin-left: 100px;
  display: flex;
  flex-direction: column;
}
.zone-vi-basis .field-label {
  display: block;
}
.zone-vi-basis .field-value {
  font-size: 9px;
  white-space: pre;
  overflow: hidden;
  display: block;
  height: 21.6px;
  text-overflow: clip;
  line-height: 1.2;
}
.zone-vi-declaration {
  width: calc(100% - 100px);
  margin-top: 8px;
  margin-left: 100px;
  display: flex;
  flex-direction: column;
}
.zone-vi-declaration .field-value {
  font-size: 9px;
  color: #2f7d32;
  white-space: normal;
  line-height: 1.2;
}
.zone-vi-qr { position: absolute; left: 24px; bottom: 16px; width: 72px; height: 72px; background: #fff; }
.zone-vi-qr img { width: 72px; height: 72px; }
.zone-vi-small-photo {
  position: absolute;
  top: 18px;
  right: 24px;
  width: 90px;
  height: 120px;
  background: transparent;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.zone-vi-small-photo img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder-sm { color: #999; font-size: 10px; }
.security-feature { position: absolute; z-index: 2; }
.security-feature-hologram {
  left: 118px; bottom: 26px; width: 82px; height: 34px; border: 1px solid rgba(26,26,106,.45);
  border-radius: 50%; display: grid; place-items: center; transform: rotate(-12deg);
  color: rgba(26,26,106,.62); font: 700 8px/1 'Arial', sans-serif; letter-spacing: 1px;
  background: linear-gradient(120deg, rgba(90,180,220,.3), rgba(245,210,90,.35), rgba(190,100,210,.25));
}
.security-feature-microtext { left: 118px; bottom: 12px; color: rgba(26,26,106,.55); font: 5px/1 'Courier New', monospace; letter-spacing: .5px; }

/* Temporary preview state: keep the hologram definition for later use. */
.security-feature-hologram {
  display: none;
}

/* Zone VII: MRZ — bottom, ~90px height */
.zone-vii {
  height: 90px;
  min-height: 90px;
  flex: 0 0 90px;
  background: #fff;
  border-top: 2px solid #ccc;
  padding: 12px 30px;
  display: flex;
  align-items: center;
}
.mrz-lines {
  font-family: 'OCR-B', 'OCRB', monospace;
  width: 100%;
  font-size: 15.24px;
  line-height: 22px;
  color: #000;
}
.mrz-line {
  display: grid;
  grid-template-columns: repeat(30, minmax(0, 1fr));
  width: 100%;
  margin: 0;
}
.mrz-char {
  display: block;
  width: 100%;
  text-align: center;
  white-space: pre;
}

/* === EXPORT BUTTONS === */
.export-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.export-btn {
  padding: 0.4rem 0.8rem; background: #222; border: 1px solid #444;
  border-radius: 6px; color: #c0a050; cursor: pointer; font-size: 0.8rem;
}
.export-btn:hover { background: #333; }

/* === RESPONSIVE === */
@media (max-width: 1100px) {
  .page { grid-template-columns: 1fr; }
  .form-section { position: static; }
  .card { width: 100%; max-width: 514px; height: auto; aspect-ratio: 514 / 324; }
}
