/* =========================================================================
   HPayment — UI de pagamento. CSS moderno puro (sem Bootstrap/jQuery).
   Visual CLARO no estilo do checkout HBook (decisão da gerência), com o
   card 3D + logos das bandeiras mantidos como diferencial visual.
   Recursos novos: custom properties, container queries, :has(), nesting,
   color-mix, 3D transforms, View Transitions.
   100% CSP-clean: nenhum estilo inline; tema do hotel via <style nonce>.
   ========================================================================= */

/* Tema CLARO no estilo do checkout HBook (gerência pediu manter o visual antigo).
   O card 3D e os logos permanecem como diferencial. */
:root {
    --hotel-primary: #1f4e8c;          /* sobrescrito pelo tema do hotel via <style nonce> */
    --hotel-primary-contrast: #ffffff;

    --bg: #f2f3f5;                      /* fundo cinza claro do HBook */
    --surface: #ffffff;
    --surface-2: #edeff2;              /* campos cinza claro (estilo Index_V2) */
    --border: #dfe3e8;
    --text: #333333;                   /* cinza escuro do HBook */
    --muted: #8a909a;
    --error: #c0392b;
    --success: #1e8e5a;
    --radius: 8px;
    --radius-lg: 10px;
    --shadow: 0 2px 12px rgb(0 0 0 / .08);  /* sombra suave, discreta */
    --ring: color-mix(in srgb, var(--hotel-primary) 28%, transparent);
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);             /* fundo claro sólido, como o HBook */
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- Header (limpo, claro — estilo HBook) ---------- */
.hpay-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px clamp(16px, 4vw, 36px);
    background: var(--surface);
    border-top: 4px solid var(--hotel-primary, #1f4e8c);   /* acento da marca do hotel (estilo HBook) */
    border-bottom: 1px solid var(--border);

    .hpay-header__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
    .hpay-header__name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .hpay-header__logobox { display: inline-flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; flex: 0 0 auto; }
    .hpay-header__logo { max-height: 36px; max-width: 130px; display: block; }
}

.hpay-header__secure {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--success) 14%, transparent);
    color: var(--success);
    font-size: .8rem;
    font-weight: 600;

    .hpay-header__lock { color: currentColor; }
}

/* ---------- Hero (galeria de capa do hotel — paridade com o checkout HBook) ---------- */
/* Banda de fotos rotativas logo abaixo do header. As fotos são <img> (CDN), o crossfade
   vem de uma animação CSS emitida com nonce no _Layout (CSP-clean, sem JS). */
.hpay-hero {
    position: relative;
    width: auto;
    max-width: 480px;                       /* mesma largura do card (.hpay-form-only) */
    height: clamp(120px, 32vw, 150px);      /* faixa baixa, proporcional ao formulário */
    margin: clamp(14px, 3vw, 22px) auto 0;  /* centralizada, como o card */
    overflow: hidden;
    border-radius: var(--radius-lg);        /* mesmas bordas do card */
    background: var(--surface-2);           /* fundo enquanto a 1ª foto carrega */
    box-shadow: var(--shadow);
    isolation: isolate;
}
/* No mobile, mesma folga lateral do formulário (padding do .hpay-main). */
@media (max-width: 540px) {
    .hpay-hero { margin-inline: 16px; }
}
.hpay-hero__slide {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;                     /* a animação (nonce) revela cada foto na sua vez */
    z-index: 0;
    will-change: opacity;
}
/* Uma única foto: sem rotação, fica sempre visível. */
.hpay-hero--static .hpay-hero__slide { opacity: 1; }
.hpay-hero__scrim {
    position: absolute;
    inset: 0;
    z-index: 1;
    /* leve profundidade no topo/base (banner contido, sem fundir na página) */
    background: linear-gradient(180deg, rgb(0 0 0 / .10) 0%, transparent 35%, transparent 70%, rgb(0 0 0 / .14) 100%);
}

/* ---------- Layout ---------- */
.hpay-main {
    max-width: 1040px;
    margin-inline: auto;
    padding: clamp(20px, 4vw, 40px);
    container-type: inline-size;
}

.hpay-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 24px;
    align-items: start;
    animation: hpay-rise .5s cubic-bezier(.2, .7, .2, 1) both;
}

@container (max-width: 760px) {
    .hpay-grid { grid-template-columns: 1fr; }
    .hpay-summary-col { order: -1; }
}

@keyframes hpay-rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

.hpay-form-col, .hpay-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(20px, 3vw, 28px);
    box-shadow: var(--shadow);
}

.hpay-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 18px; }
.hpay-return-note { font-size: .82rem; color: #5b6472; line-height: 1.5; margin: -8px 0 18px; }

/* ---------- Card preview 3D ---------- */
.hpay-card-preview {
    perspective: 1200px;
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1.586;
    margin: 0 auto 24px;
}

.hpay-card-preview__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .6s cubic-bezier(.2, .8, .2, 1);
}
.hpay-card-preview.is-flipped .hpay-card-preview__inner { transform: rotateY(180deg); }

.hpay-card-preview__front, .hpay-card-preview__back {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    backface-visibility: hidden;
    overflow: hidden;
    color: #fff;
    box-shadow: 0 18px 40px -16px rgb(0 0 0 / .55);
    background:
        radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--hotel-primary) 85%, white) 0%, transparent 45%),
        linear-gradient(135deg, var(--hotel-primary), color-mix(in srgb, var(--hotel-primary) 55%, #0b1020));
}
.hpay-card-preview__front::after {
    /* brilho diagonal sutil */
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 40%, rgb(255 255 255 / .14) 50%, transparent 60%);
}
.hpay-card-preview__back { transform: rotateY(180deg); }

.hpay-card-preview__front {
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: 18px 20px;
}

.hpay-pc-top { display: flex; align-items: center; justify-content: space-between; }
.hpay-pc-chip {
    width: 42px; height: 32px; border-radius: 6px;
    background: linear-gradient(135deg, #f6d365, #d4af37);
    position: relative;
}
.hpay-pc-chip::before {
    content: ""; position: absolute; inset: 6px 4px;
    background-image: linear-gradient(90deg, rgb(0 0 0 / .25) 1px, transparent 1px),
                      linear-gradient(0deg, rgb(0 0 0 / .2) 1px, transparent 1px);
    background-size: 8px 8px;
    border-radius: 3px;
}
.hpay-pc-brand { font-weight: 800; font-size: .95rem; letter-spacing: .04em; text-transform: uppercase; min-height: 1em; opacity: .95; }
.hpay-pc-number {
    font-family: var(--mono);
    font-size: clamp(1.05rem, 4.5cqi, 1.4rem);
    letter-spacing: .08em;
    align-self: center;
    text-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
.hpay-pc-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.hpay-pc-label { font-size: .55rem; text-transform: uppercase; letter-spacing: .12em; opacity: .7; display: block; margin-bottom: 2px; }
.hpay-pc-holder { font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hpay-pc-exp { font-family: var(--mono); font-size: .82rem; }

.hpay-pc-stripe { height: 38px; background: #0b0e14; margin-top: 18px; }
.hpay-pc-sign { margin: 16px 20px; display: flex; align-items: center; gap: 10px; }
.hpay-pc-sign-band { flex: 1; height: 30px; background: repeating-linear-gradient(135deg, #fff, #fff 6px, #eee 6px, #eee 12px); border-radius: 4px; }
.hpay-pc-cvv { font-family: var(--mono); color: #111; background: #fff; padding: 4px 10px; border-radius: 4px; min-width: 54px; text-align: center; }

/* ---------- Fields ---------- */
.hpay-field { margin-bottom: 16px; }
.hpay-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; color: var(--muted); }

.hpay-input, .hpay-select {
    width: 100%;
    padding: 12px 13px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color .18s, box-shadow .18s, background .18s;
}
.hpay-input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.hpay-input:focus, .hpay-select:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--hotel-primary);
    box-shadow: 0 0 0 4px var(--ring);
}
.hpay-input.is-valid { border-color: var(--success); }
.hpay-input.is-invalid { border-color: var(--error); background: color-mix(in srgb, var(--error) 7%, var(--surface)); }

#hpay-card-number { font-family: var(--mono); letter-spacing: .06em; }

.hpay-row { display: flex; gap: 14px; }
.hpay-field--expiry { flex: 1; }
.hpay-field--cvv { width: 120px; }
.hpay-expiry { display: flex; gap: 8px; }
.hpay-expiry .hpay-select { flex: 1; }

.hpay-detected-brand { display: inline-block; margin-top: 7px; font-size: .78rem; font-weight: 700; color: var(--hotel-primary); }
.hpay-error { display: block; margin-top: 6px; font-size: .78rem; color: var(--error); min-height: 1em; }

/* ---------- Brands ---------- */
.hpay-brands { display: flex; flex-wrap: wrap; gap: 7px; list-style: none; padding: 0; margin: 0 0 18px; }
.hpay-brand-chip {
    font-size: .68rem; font-weight: 700; letter-spacing: .03em;
    padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
    color: var(--muted); transition: all .18s ease;
}
.hpay-brand-chip.is-active {
    border-color: var(--hotel-primary); color: var(--hotel-primary);
    background: color-mix(in srgb, var(--hotel-primary) 10%, transparent);
    transform: translateY(-1px) scale(1.04);
}
.hpay-brand-chip.is-dim { opacity: .3; filter: grayscale(1); }

/* Logos (SVG) das bandeiras nos chips e no cartão 3D */
.hpay-brand-chip .brand-logo { width: 42px; height: 26px; display: block; border-radius: 4px; }
.hpay-brand-chip:has(.brand-logo) {
    padding: 0; border: none; background: transparent;
    box-shadow: 0 1px 3px rgb(0 0 0 / .15); border-radius: 5px;
}
.hpay-brand-chip.is-active:has(.brand-logo) { transform: translateY(-2px) scale(1.06); box-shadow: 0 4px 10px -2px rgb(0 0 0 / .35); }
.hpay-pc-brand .brand-logo { width: 48px; height: 30px; border-radius: 4px; box-shadow: 0 1px 4px rgb(0 0 0 / .3); }

/* ---------- Installments ---------- */
.hpay-installments { display: flex; flex-direction: column; gap: 7px; }
.hpay-installment {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer; font-size: .9rem; transition: border-color .15s, background .15s;
}
.hpay-installment:has(input:checked) {
    border-color: var(--hotel-primary);
    background: color-mix(in srgb, var(--hotel-primary) 8%, transparent);
}
.hpay-installment input { accent-color: var(--hotel-primary); }

/* ---------- Actions ---------- */
.hpay-actions { display: flex; gap: 12px; margin-top: 22px; }
.hpay-btn {
    flex: 1; padding: 13px 16px; font-size: 1rem; font-weight: 700; font-family: inherit;
    border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
    transition: transform .12s, filter .15s, box-shadow .15s; text-decoration: none; text-align: center;
}
.hpay-btn:active { transform: translateY(1px); }
.hpay-btn:disabled { opacity: .5; cursor: not-allowed; }
.hpay-btn--primary {
    color: var(--hotel-primary-contrast);
    background: var(--hotel-primary);
    box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--hotel-primary) 60%, transparent);
}
.hpay-btn--primary:not(:disabled):hover { filter: brightness(1.06); box-shadow: 0 4px 12px -3px color-mix(in srgb, var(--hotel-primary) 55%, transparent); }
.hpay-btn--ghost { flex: 0 0 110px; background: transparent; border-color: var(--border); color: var(--text); }
.hpay-btn--ghost:hover { background: var(--surface-2); }

/* ---------- Summary ---------- */
.hpay-summary__hotel { font-size: 1.1rem; font-weight: 700; margin: 0 0 2px; letter-spacing: -.01em; }
.hpay-summary__room { color: var(--text); font-size: .92rem; font-weight: 600; margin: 0 0 8px; }
.hpay-summary__meta { color: var(--muted); font-size: .82rem; line-height: 1.5; margin: 0 0 16px; }

.hpay-summary__dates { display: flex; gap: 20px; margin: 0 0 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.hpay-summary__dates dt { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hpay-summary__dates dd { margin: 3px 0 0; font-weight: 700; }
.hpay-summary__dates small { display: block; color: var(--muted); font-size: .72rem; margin-top: 1px; }

.hpay-summary__lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.hpay-summary__line { display: flex; justify-content: space-between; font-size: .88rem; }
.hpay-summary__line--muted { color: var(--muted); }
.hpay-summary__line--discount { color: var(--success); font-weight: 600; }

.hpay-summary__total {
    display: flex; justify-content: space-between; align-items: baseline;
    padding-top: 14px; border-top: 1px solid var(--border);
}
.hpay-summary__total strong { font-size: 1.5rem; letter-spacing: -.02em; color: var(--hotel-primary); }

.hpay-summary__due {
    margin-top: 14px; padding: 12px 14px;
    background: color-mix(in srgb, var(--hotel-primary) 7%, transparent);
    border: 1px solid color-mix(in srgb, var(--hotel-primary) 18%, transparent);
    border-radius: 12px;
}
.hpay-summary__due-row { display: flex; justify-content: space-between; align-items: baseline; }
.hpay-summary__due-row strong { font-size: 1.1rem; color: var(--hotel-primary); }
.hpay-summary__installment { margin: 4px 0 0; font-size: .76rem; color: var(--muted); }

.hpay-summary__policy {
    display: flex; align-items: flex-start; gap: 8px;
    margin-top: 14px; font-size: .8rem; color: var(--success); line-height: 1.4;
}
.hpay-summary__policy svg { flex: 0 0 auto; margin-top: 1px; }

/* ---------- Alert ---------- */
.hpay-alert { border-radius: 11px; padding: 12px 14px; margin-bottom: 16px; font-size: .86rem; }
.hpay-alert--error { background: color-mix(in srgb, var(--error) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--error) 35%, transparent); color: var(--error); }
.hpay-alert ul { margin: 0; padding-left: 18px; }

/* ---------- Result ---------- */
.hpay-result {
    max-width: 460px; margin: 48px auto;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 40px 30px; text-align: center;
    box-shadow: var(--shadow);
    animation: hpay-rise .5s cubic-bezier(.2, .7, .2, 1) both;
}
.hpay-result__icon {
    width: 68px; height: 68px; display: grid; place-items: center; margin: 0 auto 18px;
    border-radius: 50%; font-size: 1.9rem; font-weight: 800;
}
.hpay-result--success .hpay-result__icon { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.hpay-result--error .hpay-result__icon { background: color-mix(in srgb, var(--error) 14%, transparent); color: var(--error); }
.hpay-result__title { font-size: 1.35rem; margin: 0 0 8px; letter-spacing: -.02em; }
.hpay-result__msg { color: var(--text); margin: 0 0 6px; }
.hpay-result__hint { color: var(--muted); font-size: .88rem; margin: 0; }
.hpay-actions--center { justify-content: center; margin-top: 24px; }
.hpay-actions--center .hpay-btn { flex: 0 1 auto; padding-inline: 22px; }

/* ---------- Footer ---------- */
.hpay-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 28px; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
    /* Sem movimento: não roda o slideshow; mostra só a 1ª foto de capa. */
    .hpay-hero__slide { animation: none !important; opacity: 0; }
    .hpay-hero__slide:first-child { opacity: 1; }
}

/* ---------- Tela só-formulário (sem resumo) ---------- */
/* O HPayment mostra só o cartão; o resumo da reserva fica no checkout do HBook. */
.hpay-form-only { max-width: 480px; margin: 0 auto; }

/* ---------- View Transitions (RNF-UX-02) ---------- */
@view-transition { navigation: auto; }
