/* ==========================================================================
   Giftribute Greeting Card v4 — Front-end Styles
   Banner: dark chocolate + gold  |  Modal: brand primary/secondary
   v4 fixes:
     1. Banner button → brand primary rgb(176,128,130)
     2. Dear [name], shown as topmost line + 18px gap before message
     3. Preview card bigger (height-first, fills panel)
     4. min-height:0 on content div → long messages scroll, not hidden
     5. Mobile overlay: 68px top padding clears browser chrome
   ========================================================================== */

:root {
  --ggc-primary:        rgb(176, 128, 130);
  --ggc-primary-dark:   rgb(140, 94, 96);
  --ggc-primary-light:  rgb(220, 186, 188);
  --ggc-primary-faint:  rgba(176, 128, 130, 0.13);
  --ggc-secondary:      rgb(195, 147, 91);
  --ggc-secondary-dark: rgb(155, 110, 58);
  --ggc-text:           #3a1e20;
  --ggc-text-mid:       #6a4a4c;
  --ggc-text-soft:      #9a7a7c;
  --ggc-bg:             #fdf8f8;
  --ggc-border:         #e8d0d2;
  --ggc-white:          #ffffff;
  /* Banner uses original dark-chocolate palette */
  --ggc-banner-bg1:     #3a2e22;
  --ggc-banner-bg2:     #5a4030;
  --ggc-banner-gold:    #e6b85a;
}

/* --------------------------------------------------------------------------
   BANNER
   -------------------------------------------------------------------------- */
.ggc3-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  margin: 20px 0 8px;
  background: linear-gradient(135deg, var(--ggc-banner-bg1) 0%, var(--ggc-banner-bg2) 100%);
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(58, 46, 34, 0.18);
  transition: box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
}

.ggc3-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(176,128,130,0.07) 0%, transparent 60%);
  pointer-events: none;
}

@keyframes ggc3-shake {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-6px); }
  30%     { transform: translateX(6px); }
  45%     { transform: translateX(-4px); }
  60%     { transform: translateX(4px); }
  75%     { transform: translateX(-2px); }
  90%     { transform: translateX(2px); }
}

.ggc3-banner.ggc3-shake      { animation: ggc3-shake 0.55s ease; box-shadow: 0 0 0 3px rgba(231,76,60,0.4); }
.ggc3-banner.ggc3-error-state { background: linear-gradient(135deg, #6e2020 0%, #8b3030 100%); }
.ggc3-banner.ggc3-saved-state { background: linear-gradient(135deg, #1a4a2e 0%, #2d6b44 100%); }

.ggc3-banner-icon { font-size: 24px; line-height: 1; flex-shrink: 0; }
.ggc3-banner-content { flex: 1; min-width: 0; }
.ggc3-banner-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }

.ggc3-free-badge {
  background: var(--ggc-banner-gold);
  color: var(--ggc-banner-bg1);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
}

.ggc3-banner-title {
  font-size: 14px !important;
  font-weight: 600 !important;
  color: #fff !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  font-family: 'Lato', sans-serif !important;
}

.ggc3-status-text  { font-size: 12px; color: rgba(220,186,188,0.85); font-family: 'Lato', sans-serif; }
.ggc3-status-saved { font-size: 12px; color: #7bed9f; font-family: 'Lato', sans-serif; }

/* ── "Personalise Card" / "Edit Card" button ────────────────────────────
   Accented gold colour matching the giftribute brand.                   */
:root {
  --ggc-btn-bg:       rgb(195, 147, 91);
  --ggc-btn-bg-hover: rgb(169, 127, 79);
}

.ggc3-btn-open {
  display: inline-flex !important;
  align-items: center !important;
  gap: 7px !important;
  background: var(--ggc-btn-bg) !important;
  color: #fff !important;
  border: none !important;
  padding: 9px 16px !important;
  border-radius: 6px !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  font-family: 'Lato', sans-serif !important;
  letter-spacing: 0.01em !important;
  line-height: 1 !important;
  text-decoration: none !important;
  transition: background 0.2s ease, transform 0.15s ease !important;
}

.ggc3-btn-open:hover {
  background: var(--ggc-btn-bg-hover) !important;
  color: #fff !important;
  transform: translateY(-1px);
}
.ggc3-btn-open:active { transform: translateY(0); }

/* Opt-out */
.ggc3-opt-out-row { margin: 6px 0 4px; }

.ggc3-opt-out-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #7a6a55;
  user-select: none;
}

.ggc3-opt-out-cb {
  width: 15px !important;
  height: 15px !important;
  accent-color: var(--ggc-primary);
  flex-shrink: 0;
}

/* Banner error */
.ggc3-banner-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  padding: 10px 14px;
  background: #fef3f2;
  border: 1px solid #f5c6c2;
  border-radius: 8px;
  font-size: 13px;
  color: #922b21;
  line-height: 1.5;
}

.ggc3-banner-error svg { flex-shrink: 0; margin-top: 1px; }

/* --------------------------------------------------------------------------
   OVERLAY
   -------------------------------------------------------------------------- */
.ggc3-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 10, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  animation: ggc3-fade-in 0.18s ease;
}

@keyframes ggc3-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* --------------------------------------------------------------------------
   MODAL
   -------------------------------------------------------------------------- */
.ggc3-modal {
  background: var(--ggc-white);
  border-radius: 16px;
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  box-shadow: 0 32px 80px rgba(100,60,60,0.22), 0 4px 24px rgba(0,0,0,0.14);
  /* position:relative is required so the absolute close button is positioned
     relative to the modal, not the viewport */
  position: relative;
  animation: ggc3-slide-up 0.28s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes ggc3-slide-up {
  from { transform: translateY(22px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* --------------------------------------------------------------------------
   CLOSE BUTTON — circular, always top-right of the modal box.
   All !important guards are needed to beat .button.alt theme rules which
   often inject display:block, width:100%, float:left, etc.
   -------------------------------------------------------------------------- */
.ggc3-modal-close {
  /* Lock to top-right of .ggc3-modal (which has position:relative) */
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  /* Fixed circular shape */
  width: 38px !important;
  height: 38px !important;
  min-width: 38px !important;
  max-width: 38px !important;
  border-radius: 50% !important;
  /* Gold colour identical to the other buttons */
  background: var(--ggc-btn-bg) !important;
  color: #fff !important;
  border: none !important;
  /* Layout */
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  float: none !important;
  text-align: center !important;
  /* Stacking: above both panels on desktop and mobile */
  z-index: 100 !important;
  cursor: pointer !important;
  line-height: 1 !important;
  transition: background 0.15s, transform 0.12s !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.20) !important;
}

.ggc3-modal-close:hover  {
  background: var(--ggc-btn-bg-hover) !important;
  transform: scale(1.08);
}
.ggc3-modal-close:active { transform: scale(0.94); }

/* --------------------------------------------------------------------------
   LEFT PANEL — Portrait card preview (written/inside side only)
   v4: wider panel, tighter padding → bigger card
   -------------------------------------------------------------------------- */
.ggc3-modal-preview-panel {
  width: 50%;
  flex-shrink: 0;
  background: linear-gradient(160deg, var(--ggc-primary-dark) 0%, var(--ggc-primary) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 12px 18px;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

.ggc3-modal-preview-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.09) 0%, transparent 60%);
  pointer-events: none;
}

.ggc3-preview-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.50);
  margin: 0 0 10px;
  padding: 0;
  font-family: 'Lato', sans-serif;
  flex-shrink: 0;
  position: relative;
}

/* ============================================================
   PREVIEW CARD — A7 portrait (74 × 105)
   v4 fixes:
   • Height-first sizing (fills panel height)
   • overflow: hidden clips card to border-radius
   • min-height:0 on content → scroll fix (see below)
   ============================================================ */
.ggc3-preview-card {
  /* Height-first: takes most of the panel height */
  height: clamp(260px, calc(92vh - 120px), 560px);
  width: auto;
  aspect-ratio: 74 / 105;
  max-width: 100%;
  flex-shrink: 0;

  background: #fffcfc;
  border-radius: 8px;
  box-shadow:
    0 0 0 1px rgba(195,147,91,0.22),
    0 10px 50px rgba(0,0,0,0.34),
    inset 0 0 0 1px rgba(255,255,255,0.5);

  display: flex;
  flex-direction: column;
  padding: 20px 20px 14px;
  box-sizing: border-box;
  position: relative;

  /* Clip to rounded corners WITHOUT creating a scroll container.
     overflow: clip avoids the Safari mobile flex+scroll interaction bug. */
  overflow: clip;
}

/* Inner decorative border */
.ggc3-preview-card::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(195,147,91,0.18);
  border-radius: 4px;
  pointer-events: none;
  z-index: 0;
}

/* Corner branding — absolute, no layout impact */
.ggc3-pc-corner-logo {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  z-index: 2;
  pointer-events: none;
}

.ggc3-pc-corner-brand { font-family: 'Dancing Script', cursive; font-size: 11px; font-weight: 700; color: var(--ggc-primary); opacity: 0.58; line-height: 1; }
.ggc3-pc-corner-heart { font-size: 9px; color: var(--ggc-secondary); opacity: 0.52; text-align: right; }

/* ── Scrollable content: Dear + Message ─────────────────────────────────
   v4 KEY FIX: min-height:0 lets the flex child shrink below content size
   so overflow-y:auto activates → long messages scroll inside the card   */
.ggc3-pc-content {
  flex: 1;
  min-height: 0;        /* ← THE fix: allows this flex child to shrink & scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 4px 6px 2px;
  position: relative;
  z-index: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(195,147,91,0.3) transparent;
}

.ggc3-pc-content::-webkit-scrollbar { width: 3px; }
.ggc3-pc-content::-webkit-scrollbar-track { background: transparent; }
.ggc3-pc-content::-webkit-scrollbar-thumb { background: rgba(195,147,91,0.35); border-radius: 2px; }

/* "Dear [Name]," — topmost line, HIDDEN until To is filled (JS shows it)
   v4: margin-bottom: 18px = one clear line gap before the message      */
.ggc3-pc-dear {
  font-family: 'Dancing Script', cursive;
  font-size: 15px;
  font-weight: 700;
  color: var(--ggc-text);
  line-height: 1.4;
  margin: 0 0 18px;     /* the "one Enter" spacing */
  padding: 0;
  display: none;         /* shown by JS when To field is filled */
}

/* Message — no height limit; parent .ggc3-pc-content scrolls */
.ggc3-pc-message {
  font-family: 'Dancing Script', cursive;
  font-size: 14px;
  font-weight: 600;
  color: var(--ggc-text);
  line-height: 1.72;
  text-align: left;
  word-break: break-word;
  white-space: pre-wrap;
  margin: 0;
  padding: 0;
}

.ggc3-pc-placeholder { color: var(--ggc-primary-light); font-style: italic; font-weight: 400; font-size: 11px; }

/* From — pinned to card bottom */
.ggc3-pc-from-wrap { flex-shrink: 0; padding-top: 8px; position: relative; z-index: 1; }

.ggc3-pc-from { font-family: 'Dancing Script', cursive; font-size: 13px; color: var(--ggc-secondary-dark); text-align: right; min-height: 16px; line-height: 1.4; }

.ggc3-preview-hint { font-size: 11px; color: rgba(255,255,255,0.38); margin: 10px 0 0; padding: 0; font-style: italic; text-align: center; font-family: 'Lato', sans-serif; flex-shrink: 0; position: relative; }

/* --------------------------------------------------------------------------
   RIGHT PANEL — Form
   -------------------------------------------------------------------------- */
.ggc3-modal-form-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 30px 28px;
  box-sizing: border-box;
  background: var(--ggc-bg);
  /* Visible scrollbar so users know they can scroll */
  scrollbar-width: auto;
  scrollbar-color: var(--ggc-primary-light) rgba(232,208,210,0.35);
}

.ggc3-modal-form-panel::-webkit-scrollbar { width: 5px; }
.ggc3-modal-form-panel::-webkit-scrollbar-track { background: rgba(232,208,210,0.35); }
.ggc3-modal-form-panel::-webkit-scrollbar-thumb { background: var(--ggc-primary-light); border-radius: 3px; }

.ggc3-modal-header { margin-bottom: 18px; }

.ggc3-modal-title {
  font-size: 20px !important;
  font-weight: 700 !important;
  color: var(--ggc-text) !important;
  margin: 0 0 6px !important;
  padding: 0 50px 0 0 !important; /* clear X button */
  border: none !important;
  font-family: 'Lato', sans-serif !important;
  line-height: 1.25 !important;
}

.ggc3-modal-subtitle { font-size: 13px; color: var(--ggc-text-soft); margin: 0; line-height: 1.5; }

.ggc3-field { margin-bottom: 15px; }

.ggc3-field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--ggc-primary-dark);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.ggc3-optional { font-size: 10px; color: var(--ggc-text-soft); font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 4px; }
.ggc3-required { color: #c0392b; margin-left: 2px; }

.ggc3-to-from-row { display: flex; gap: 12px; }
.ggc3-field-half  { flex: 1; min-width: 0; }

.ggc3-select-wrap { position: relative; }

.ggc3-select-wrap::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ggc-text-soft);
  pointer-events: none;
}

.ggc3-select { width: 100%; padding: 10px 32px 10px 12px; border: 1.5px solid var(--ggc-border); border-radius: 8px; font-size: 13.5px; color: var(--ggc-text); background: var(--ggc-white); appearance: none; cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; font-family: 'Lato', sans-serif; }
.ggc3-select:focus { outline: none; border-color: var(--ggc-primary); box-shadow: 0 0 0 3px var(--ggc-primary-faint); }

.ggc3-textarea { width: 100%; box-sizing: border-box; padding: 11px 13px; border: 1.5px solid var(--ggc-border); border-radius: 8px; font-size: 14px; font-family: 'Lato', sans-serif; color: var(--ggc-text); background: var(--ggc-white); resize: vertical; min-height: 95px; transition: border-color 0.2s, box-shadow 0.2s; line-height: 1.6; }
.ggc3-textarea:focus { outline: none; border-color: var(--ggc-primary); box-shadow: 0 0 0 3px var(--ggc-primary-faint); }
.ggc3-textarea::placeholder { color: #bea8aa; font-style: italic; }

.ggc3-char-row { display: flex; justify-content: space-between; margin-top: 5px; font-size: 11.5px; color: var(--ggc-text-soft); }
.ggc3-char-counter { font-variant-numeric: tabular-nums; transition: color 0.2s; }
.ggc3-char-counter.ggc3-warn  { color: #e67e22; font-weight: 600; }
.ggc3-char-counter.ggc3-limit { color: #c0392b; font-weight: 700; }

.ggc3-input { width: 100%; box-sizing: border-box; padding: 10px 13px; border: 1.5px solid var(--ggc-border); border-radius: 8px; font-size: 13.5px; color: var(--ggc-text); background: var(--ggc-white); font-family: 'Lato', sans-serif; transition: border-color 0.2s, box-shadow 0.2s; }
.ggc3-input:focus { outline: none; border-color: var(--ggc-primary); box-shadow: 0 0 0 3px var(--ggc-primary-faint); }
.ggc3-input::placeholder { color: #bea8aa; }

.ggc3-modal-actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; flex-wrap: wrap; }

/* "Save My Card Message" — gold accent, same palette as the other buttons */
.ggc3-btn-save {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  background: var(--ggc-btn-bg) !important;
  color: #fff !important;
  border: none !important;
  padding: 12px 24px !important;
  border-radius: 8px !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  font-family: 'Lato', sans-serif !important;
  line-height: 1 !important;
  transition: background 0.2s ease, transform 0.15s ease !important;
}

.ggc3-btn-save:hover {
  background: var(--ggc-btn-bg-hover) !important;
  color: #fff !important;
  transform: translateY(-1px);
}
.ggc3-btn-save:active { transform: translateY(0); }

.ggc3-modal-footer-note { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ggc-text-soft); margin-top: 14px; line-height: 1.4; padding: 0; }

/* --------------------------------------------------------------------------
   MOBILE — popup clear of browser chrome; preview fixed, form scrolls
   -------------------------------------------------------------------------- */
@media (max-width: 680px) {

  /* Overlay: large top padding clears Safari/Chrome address bar */
  .ggc3-overlay {
    align-items: flex-start;
    padding: 68px 12px 16px;
  }

  /* Modal: stack vertically, constrained to remaining screen height */
  .ggc3-modal {
    flex-direction: column;
    max-height: calc(100vh - 84px);
    border-radius: 14px;
    overflow: hidden;
  }

  /* ── Preview panel: taller on mobile so more card content is visible ── */
  .ggc3-modal-preview-panel {
    width: 100%;
    flex-shrink: 0;
    height: 270px;           /* increased from 220px — shows ~3 extra lines */
    padding: 10px 16px 8px;
    justify-content: center;
    overflow: hidden;
  }

  .ggc3-preview-label {
    margin-bottom: 6px;
    font-size: 9px;
  }

  /* ── Card: height fills panel minus label; width auto via aspect-ratio */
  .ggc3-preview-card {
    height: calc(100% - 30px);  /* ~240px — wide enough to show 8-10 lines */
    width: auto;
    aspect-ratio: 74 / 105;
    max-width: none;
    padding: 10px 12px 8px;
  }

  .ggc3-preview-hint { display: none; }

  /* ── Form panel: fills remaining height, scrolls with visible bar ──── */
  .ggc3-modal-form-panel {
    flex: 1;
    min-height: 0;
    overflow-y: scroll;           /* always show scrollbar on mobile      */
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px 28px;
    scrollbar-width: auto;
    scrollbar-color: var(--ggc-primary-light) rgba(232,208,210,0.35);
  }

  .ggc3-to-from-row { flex-direction: column; gap: 0; }

  /* Banner adjustments */
  .ggc3-banner { flex-wrap: wrap; gap: 10px; }
  .ggc3-btn-open { width: 100% !important; justify-content: center !important; }
}

@media (max-width: 400px) {
  .ggc3-overlay { padding: 58px 10px 14px; }
  .ggc3-modal-title { font-size: 17px !important; }
  .ggc3-btn-save { padding: 10px 18px; font-size: 13px; }
  .ggc3-modal-form-panel { padding: 14px 12px 24px; }
  .ggc3-preview-card { height: 140px !important; }
}
