/**
 * popup-styles.css
 * Έκδοση διορθωμένη για αφίσες 1536×1024 (αναλογία 3:2)
 *
 * Βασική διόρθωση:
 * Οι κάρτες είναι 3:2 και όχι 4:3, οπότε το popup δεν κόβεται
 * αριστερά/δεξιά ή πάνω/κάτω.
 */

#loan-popup-root {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none; /* το root δεν μπλοκάρει κλικ όταν είναι κλειστό */
}

#loan-popup-root * {
  box-sizing: border-box;
}

.lp-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 20px 88px;
  overflow: auto;
  background: rgba(10, 10, 30, 0.6);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none; /* κλειστό = δεν δέχεται κλικ */
}

.lp-overlay.lp-visible {
  opacity: 1;
  pointer-events: auto; /* ανοιχτό = δέχεται κλικ */
}

/* ---- Κάρτα ---- */
.lp-card {
  position: relative;
  width: min(900px, calc(100vw - 40px));
  aspect-ratio: 3 / 2; /* Οι εικόνες popup είναι 1536×1024 */
  flex: 0 0 auto;
  overflow: visible;
  border-radius: 22px;
  background-size: cover;
  background-position: center top;
  background-color: #1a1a2e;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  transform-origin: center top;
  transform: scale(0.85) translateY(24px);
  transition: transform 0.32s cubic-bezier(0.34,1.56,0.64,1);
}

.lp-visible .lp-card {
  transform: scale(1) translateY(0);
}

/* Σπάνια / Χρυσά */
.lp-rare .lp-card {
  box-shadow: 0 0 0 4px #a78bfa, 0 20px 60px rgba(0,0,0,.5);
}

.lp-golden .lp-card {
  box-shadow: 0 0 0 5px #fbbf24, 0 0 40px 10px rgba(251,191,36,.6);
  animation: lp-glow 1.8s ease-in-out infinite alternate;
}

@keyframes lp-glow {
  from { box-shadow: 0 0 0 5px #fbbf24, 0 0 30px 6px rgba(251,191,36,.5); }
  to   { box-shadow: 0 0 0 5px #fde68a, 0 0 55px 16px rgba(251,191,36,.85); }
}

/* Εσωτερικό clip — κρατά το background και τα πεδία μέσα στις γωνίες */
.lp-card-inner {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  overflow: hidden;
  background-size: cover;
  background-position: center top;
  background-color: #1a1a2e;
}

.lp-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #e11d48;
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 3px 10px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.lp-close:hover {
  background: #be123c;
  transform: scale(1.1);
}

/* ============================================================
   OVERLAY FIELDS — κείμενο πάνω στα άδεια πλαίσια της εικόνας
   Οι τιμές top/left/width είναι βαθμονομημένες για το
   layout της Πειρατικής Αποστολής και των ίδιων templates.
   ============================================================ */
.lp-fields {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.lp-field {
  position: absolute;
  font-family: "Comic Sans MS","Baloo 2","Varela Round",system-ui,sans-serif;
  font-weight: 700;
  color: #1a1a2e;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Όνομα μαθητή */
.lp-field-name {
  top: 48%;
  left: 28%;
  width: 58%;
  font-size: clamp(13px, 1.8vw, 17px);
  color: #1a1a2e;
}

/* Τίτλος βιβλίου */
.lp-field-book {
  top: 60%;
  left: 28%;
  width: 48%;
  font-size: clamp(12px, 1.6vw, 15px);
  white-space: normal;
  line-height: 1.15;
}

/* Ημερομηνία */
.lp-field-date {
  top: 71%;
  left: 28%;
  width: 48%;
  font-size: clamp(12px, 1.6vw, 15px);
}

/* Achievement */
.lp-field-achievement {
  top: 81%;
  left: 28%;
  width: 55%;
  font-size: clamp(12px, 1.6vw, 15px);
  color: #b45309;
  white-space: normal;
  line-height: 1.2;
}

/* Ατάκα βιβλίου */
.lp-field-quote {
  top: 93%;
  left: 23%;
  width: 58%;
  font-size: clamp(11px, 1.4vw, 13px);
  font-weight: 600;
  color: #374151;
  white-space: normal;
  line-height: 1.2;
}

/* ============================================================
   ΕΞΩΦΥΛΛΟ ΒΙΒΛΙΟΥ — τοποθετείται στο κενό πλαίσιο δεξιά
   ============================================================ */
.lp-book-cover {
  position: absolute;
  top: 53%;
  left: 72%;
  width: 20%;
  height: 40%;
  object-fit: cover;
  object-position: center top;
  border-radius: 6px;
  pointer-events: none;
}

/* ============================================================
   FALLBACK — γυάλινο κουτί όταν δεν υπάρχει εικόνα ακόμα
   ============================================================ */
.lp-fallback {
  position: absolute;
  bottom: 56px;
  left: 14px;
  right: 14px;
  padding: 16px 18px 14px;
  border-radius: 32px 32px 24px 24px;
  background: rgba(255,255,255,0.88);
  border: 4px solid rgba(255,255,255,0.7);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  font-family: "Comic Sans MS","Baloo 2","Varela Round",system-ui,sans-serif;
  text-align: center;
}

.lp-fb-greeting {
  font-size: .9rem;
  font-weight: 700;
  color: #6d28d9;
  margin-bottom: 4px;
}

.lp-fb-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: #1f2937;
  margin-bottom: 6px;
}

.lp-fb-book {
  font-size: .95rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 4px;
}

.lp-fb-date {
  font-size: .8rem;
  color: #9ca3af;
  margin-bottom: 6px;
}

.lp-fb-achievement {
  font-size: .9rem;
  color: #b45309;
  font-weight: 700;
  background: #fef3c7;
  border: 2px dashed #f59e0b;
  border-radius: 10px;
  padding: 4px 10px;
  margin: 6px 0;
}

.lp-fb-quote {
  font-style: italic;
  font-size: .88rem;
  color: #4b5563;
}

/* ---- CTA Κουμπί — κάτω από την κάρτα ---- */
.lp-cta {
  position: absolute;
  bottom: -52px;
  left: 0;
  right: 0;
  padding: 13px 18px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg,#f97316,#ec4899);
  box-shadow: 0 5px 0 rgba(0,0,0,.15);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  z-index: 4;
}

.lp-cta:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
}

/* ---- Tablet ---- */
@media (min-width:481px) and (max-width:1024px) {
  .lp-overlay {
    padding: 20px 18px 84px;
  }

  .lp-card {
    width: min(820px, calc(100vw - 36px));
    /* aspect-ratio 3/2 κληρονομείται */
  }
}

/* ---- Mobile ---- */
@media (max-width:480px) {
  .lp-overlay {
    padding: 14px 8px 76px;
  }

  .lp-card {
    width: calc(100vw - 16px);
    /* aspect-ratio 3/2 κληρονομείται */
  }

  .lp-close {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .lp-cta {
    bottom: -48px;
    padding: 12px 14px;
    font-size: .9rem;
  }

  .lp-field {
    font-size: clamp(9px, 2vw, 12px);
  }
}

/* ============================================================
   ΚΟΥΜΠΙΑ ΛΗΨΗΣ / ΕΚΤΥΠΩΣΗΣ ΓΙΑ ΤΗΝ ΚΑΡΤΑ ΔΑΝΕΙΣΜΟΥ
   ============================================================ */
.lp-overlay {
  padding-bottom: 124px !important;
}

.lp-actions {
  position: absolute;
  left: 50%;
  bottom: -66px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 56px));
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  z-index: 20;
  pointer-events: auto;
  font-family: "Comic Sans MS", "Baloo 2", "Varela Round", system-ui, sans-serif;
}

.lp-action {
  appearance: none;
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 11px 18px;
  color: #ffffff;
  font-size: clamp(13px, 1.4vw, 16px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .22), 0 10px 24px rgba(0, 0, 0, .22);
  transition: transform .1s ease, box-shadow .1s ease, filter .1s ease;
  white-space: nowrap;
}

.lp-action:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.lp-action:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .22), 0 5px 16px rgba(0, 0, 0, .22);
}

.lp-action:disabled {
  cursor: wait;
  opacity: .75;
  filter: grayscale(.2);
}

.lp-download {
  background: linear-gradient(135deg, #10b981, #059669);
}

.lp-print {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
}

.lp-action-close {
  background: linear-gradient(135deg, #f97316, #ec4899);
}

/* Ακυρώνει παλιό styling αν έχει μείνει cached κάποια .lp-cta */
.lp-actions .lp-cta,
.lp-actions .lp-action-close {
  position: static !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
}

@media (max-width: 640px) {
  .lp-overlay {
    padding: 14px 8px 172px !important;
  }

  .lp-actions {
    bottom: -144px;
    width: calc(100vw - 28px);
    flex-direction: column;
    gap: 8px;
  }

  .lp-action {
    width: 100%;
    min-height: 40px;
    padding: 10px 14px;
    font-size: 13px;
  }
}

@media print {
  @page {
    size: landscape;
    margin: 8mm;
  }

  body.lp-printing-card * {
    visibility: hidden !important;
  }

  body.lp-printing-card #loan-popup-root,
  body.lp-printing-card #loan-popup-root * {
    visibility: visible !important;
  }

  body.lp-printing-card #loan-popup-root {
    position: static !important;
  }

  body.lp-printing-card .lp-overlay {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #ffffff !important;
    opacity: 1 !important;
  }

  body.lp-printing-card .lp-card {
    width: min(27cm, 96vw) !important;
    max-height: 18cm !important;
    transform: none !important;
    box-shadow: none !important;
    animation: none !important;
    border-radius: 0 !important;
  }

  body.lp-printing-card .lp-card-inner {
    border-radius: 0 !important;
  }

  body.lp-printing-card .lp-close,
  body.lp-printing-card .lp-actions {
    display: none !important;
  }
}
