/*
 * KGPreloader — shared full-page loading overlay, matching the Figma
 * "LOADING (Option 2)" frame: solid blue backdrop, centered logo, a
 * "Travel More, Worry Less" badge, a bold headline with a red accent dot,
 * a subtitle, and a status/progress-bar/wait footer row.
 *
 * Deliberately uses LITERAL hex values instead of the base2.html
 * `--kg-color-*` custom properties: this stylesheet is also loaded on
 * standalone pages (staff_signin.html, t/flutter_test_form.html,
 * t/payment_status.html) that do NOT define those tokens, so depending on
 * them would leave the overlay unstyled there.
 *
 *   primary       #01529C
 *   primary-dark  #013f79
 *   primary-light #2194FF
 *   accent        #FD0002
 *   white         #FFFFFF
 *
 * Visibility is controlled ONLY via the .kg-preloader-visible class
 * (added/removed by static/js/kg-preloader.js, which is UNCHANGED by this
 * redesign — #kgPreloader and #kgPreloaderText keep the exact ids/contract
 * every KGPreloader.show([message])/hide() caller already depends on). Do
 * NOT toggle this with inline style.display or Bootstrap's .d-flex/.d-none
 * utilities — those utility classes are `!important` in this codebase and
 * are already known to permanently defeat naive class-toggle/inline-style
 * show/hide logic elsewhere, so this component keeps its toggle fully
 * self-contained here.
 *
 * IMPORTANT — this new overlay's logo uses .kg-preloader-brand-logo, NOT
 * the older .kg-preloader-logo/.kg-preloader-ring/.kg-preloader-ring-wrap
 * names below. Those three are kept, unchanged, because
 * templates/super/dashboard.html's OWN separate "#preloader_all" flight-
 * search loading modal (a different component entirely, not this global
 * overlay) still uses them — redefining those class names here would have
 * silently reskinned/broken that unrelated modal too.
 */

.kg-preloader-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: radial-gradient(circle at 50% 38%, #0c5aa9 0%, #01529C 55%, #013f79 100%);
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.kg-preloader-overlay.kg-preloader-visible {
    display: flex;
}

/* ── Breathing background glow — the soft radial highlight behind the
   headline. The base .kg-preloader-overlay gradient above is a static
   fill; this separate layer sits on top of it (screen blend, so it only
   ever brightens, never darkens/tints) and is the piece that actually
   pulses — scaling and brightening outward, then relaxing back, on a
   loop, so the center of the screen reads as a slowly "breathing" light
   source rather than a flat, static circle. Same general timing/easing
   character as .kg-preloader-rings' kgRingPulse below, just slower and
   subtler since this is a background wash, not a foreground ring. ── */
.kg-preloader-glow {
    position: absolute;
    top: 38%;
    left: 50%;
    width: clamp(640px, 55vw, 1050px);
    height: clamp(640px, 55vw, 1050px);
    transform: translate(-50%, -50%) scale(.92);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(130, 195, 255, 0.55) 0%, rgba(33, 148, 255, 0.22) 45%, rgba(33, 148, 255, 0) 72%);
    mix-blend-mode: screen;
    pointer-events: none;
    z-index: 0;
    animation: kgGlowBreathe 5.2s cubic-bezier(.45, 0, .55, 1) infinite;
    will-change: transform, opacity;
}

@keyframes kgGlowBreathe {
    0%, 100% { opacity: .55; transform: translate(-50%, -50%) scale(.92); }
    50%      { opacity: .95; transform: translate(-50%, -50%) scale(1.1); }
}

/* ── Faint concentric rings behind the headline, purely decorative ── */
.kg-preloader-rings {
    position: absolute;
    top: 42%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 0;
}

/* Reverted the earlier "liquid glass" attempt (radial-gradient fill +
   glow box-shadow) — it made the rings read as bright, lit-up blobs
   instead of blending with the backdrop. Back to an outline only, same
   tone family as the background (plain white at low opacity, no fill,
   no glow), just a noticeably thicker stroke and a bigger, clearer pulse
   so the motion itself is bold without the ring looking lit up. */
.kg-preloader-rings span {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.24);
    transform: translate(-50%, -50%) scale(.8);
    animation: kgRingPulse 3.4s cubic-bezier(.45, 0, .55, 1) infinite;
    will-change: transform, opacity;
}

.kg-preloader-rings span:nth-child(1) { width: clamp(300px, 26vw, 480px); height: clamp(300px, 26vw, 480px); animation-delay: 0s; }
.kg-preloader-rings span:nth-child(2) { width: clamp(440px, 38vw, 700px); height: clamp(440px, 38vw, 700px); animation-delay: .75s; }
.kg-preloader-rings span:nth-child(3) { width: clamp(580px, 50vw, 920px); height: clamp(580px, 50vw, 920px); animation-delay: 1.5s; }

/* A strong, clearly visible breathe: each ring grows outward and brightens,
   then shrinks back and fades, on a loop — staggered per ring above so the
   motion reads as rippling outward rather than three rings pulsing in
   lockstep. */
@keyframes kgRingPulse {
    0%   { opacity: 0;   transform: translate(-50%, -50%) scale(.76); }
    40%  { opacity: .85; transform: translate(-50%, -50%) scale(1); }
    75%  { opacity: .4;  transform: translate(-50%, -50%) scale(1.16); }
    100% { opacity: 0;   transform: translate(-50%, -50%) scale(1.24); }
}

/* ── Content column ── */
.kg-preloader-inner {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1600px;
    padding: clamp(32px, 7vw, 96px) 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.kg-preloader-brand-logo {
    height: clamp(34px, 3.4vw, 52px);
    width: auto;
    object-fit: contain;
    margin-bottom: clamp(22px, 3.2vw, 48px);
}

/* ── Legacy: dashboard.html's separate "#preloader_all" flight-search
   loading modal — untouched, kept exactly as it was before this redesign. ── */
.kg-preloader-ring-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kg-preloader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(#2194FF, #01529C, #FD0002, #2194FF);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 4px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 4px));
    animation: kgOrbitSpin 1.1s linear infinite;
}

@keyframes kgOrbitSpin {
    to {
        transform: rotate(360deg);
    }
}

.kg-preloader-logo {
    position: relative;
    z-index: 1;
    width: 56px;
    height: 56px;
    background: #FFFFFF;
    border-radius: 50%;
    padding: 10px;
    object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
    .kg-preloader-ring {
        animation: none;
    }
}

@media (max-width: 380px) {
    .kg-preloader-ring-wrap {
        width: 80px;
        height: 80px;
    }

    .kg-preloader-logo {
        width: 48px;
        height: 48px;
        padding: 8px;
    }
}

/* ── Badge: TWO separate touching chips (icon circle + text pill), not one
   merged pill — matches the Figma reference exactly. Same border/fill
   treatment on both so they read as one family, just two shapes. ── */
.kg-preloader-badge-row {
    display: inline-flex;
    align-items: center;
    gap: clamp(8px, .8vw, 14px);
    margin-bottom: clamp(22px, 3.2vw, 48px);
}

.kg-preloader-badge-icon,
.kg-preloader-badge-text {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: rgba(255, 255, 255, 0.92);
}

.kg-preloader-badge-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(32px, 3vw, 46px);
    height: clamp(32px, 3vw, 46px);
    flex-shrink: 0;
    border-radius: 50%;
}

.kg-preloader-badge-icon i { font-size: clamp(15px, 1.4vw, 21px); color: #FFFFFF; }

.kg-preloader-badge-text {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: clamp(7px, .7vw, 12px) clamp(18px, 1.6vw, 28px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(11px, 1vw, 15px);
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    white-space: nowrap;
}

.kg-preloader-headline {
    margin: 0 0 clamp(14px, 2.4vw, 40px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(28px, 5.12vw, 100px);
    font-weight: 800;
    line-height: 1.2;
    color: #FFFFFF;
    letter-spacing: -0.2px;
}

.kg-preloader-dot {
    display: inline-block;
    width: .22em;
    height: .22em;
    margin-left: .16em;
    border-radius: 2px;
    background: #FD0002;
    vertical-align: baseline;
    transform: translateY(-0.06em);
}

.kg-preloader-subtitle {
    margin: 0 0 clamp(64px, 11vw, 190px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(15px, 1.5vw, 22px);
    font-weight: 400;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.72);
    /* Narrow enough to force the Figma-matching 2-line wrap ("...stays," /
       "and experiences...") at normal desktop widths (verified live at
       1440x900 and 1920x1080) — a wider cap (previously min(90%, 640px))
       let the line fit on one row once the headline/proportion pass grew
       the font size. */
    max-width: min(80%, 460px);
}

/* ── Footer: two stacked rows, matching Figma —
   row 1 (.kg-preloader-footer-captions): the status text and "Please
   Wait" caption, inset so their extent roughly matches the bar beneath
   them, NOT the full icon-to-icon width of row 2.
   row 2 (.kg-preloader-footer-track): status ring at the far left edge,
   the segmented bar filling the middle, wait/pin icon at the far right
   edge — the icons here sit slightly further outward than the caption
   row above them.
   The inset is driven by the same --kg-pf-icon/--kg-pf-gap custom
   properties the track row's icon size/gap use, so the two rows stay
   visually aligned across viewport sizes instead of relying on
   hand-tuned, easily-drifting pixel values. ── */
.kg-preloader-footer {
    --kg-pf-icon: clamp(14px, 1.3vw, 19px);
    --kg-pf-gap: clamp(12px, 1.4vw, 20px);
    width: 100%;
    /* Widened from the original 780px (up toward .kg-preloader-inner's own
       1600px cap) so a long, real status message (~100+ chars, e.g. a
       flight search's route+date string) has enough room per line to wrap
       across just 2-3 lines instead of many narrow ones. Verified live at
       1440x900/1920x1080 with the worst-case dashboard.html message. */
    max-width: 1180px;
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 1.2vw, 16px);
}

.kg-preloader-footer-captions {
    display: flex;
    /* flex-start, not center: the status text can now grow to several
       lines (long route/date messages), while "Please Wait" always stays
       a single line — top-aligning both reads correctly whether the
       status text is one line or several, whereas center would visibly
       drift "Please Wait" downward as the status text grows taller. */
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-inline: calc(var(--kg-pf-icon) + var(--kg-pf-gap));
}

.kg-preloader-footer-track {
    display: flex;
    align-items: center;
    gap: var(--kg-pf-gap);
}

.kg-preloader-status-text,
.kg-preloader-wait {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(11px, 1vw, 15px);
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.78);
}

/* "Please Wait" is always short and must stay a single line, and must
   never be squeezed by the status text growing next to it. */
.kg-preloader-wait {
    flex-shrink: 0;
    white-space: nowrap;
}

.kg-preloader-wait-icon { font-size: clamp(14px, 1.2vw, 18px); color: rgba(255, 255, 255, 0.78); flex-shrink: 0; }

.kg-preloader-status-ring {
    position: relative;
    width: var(--kg-pf-icon);
    height: var(--kg-pf-icon);
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
}

.kg-preloader-status-ring::before {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: #FFFFFF;
    animation: kgStatusPulse 1.4s ease-in-out infinite;
}

@keyframes kgStatusPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .35; transform: scale(.7); }
}

.kg-preloader-status-text {
    /* Some callers (e.g. templates/super/dashboard.html's flight/hotel
       search KGPreloader.show() calls) pass long, dynamically-built
       messages with full route/date details (100+ chars). This must
       always show in FULL — never truncated/ellipsized — so it grows to
       fill whatever space is left next to "Please Wait" in this row
       (flex-grow, with min-width:0 so it's actually allowed to shrink
       below its content's natural single-line width) and wraps onto as
       many lines as it needs rather than being clipped. Left-aligned so
       wrapped lines read naturally instead of each line individually
       centering under the inherited text-align:center from
       .kg-preloader-inner. */
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal;
    line-height: 1.5;
    text-align: left;
}

/* ── Segmented progress bar — real discrete boxes, filled one at a time by
   static/js/kg-preloader.js. show() creeps them in left-to-right at a
   roughly one-second-per-segment cadence, pauses briefly near-full, then
   resets to empty and loops indefinitely — nobody can know real %
   complete for an arbitrary request, so a long wait reads as still
   working rather than as a bar that stalled/froze near the end; hide()
   immediately finishes filling whatever is left, box by box, so the bar
   visibly completes in step with the page actually being ready, right
   before the overlay disappears. ── */
.kg-preloader-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    height: clamp(8px, .8vw, 12px);
    /* 26 segments with a 4px gap between each already need 100px just for
       the gaps — a 60px floor left nothing for the segments themselves
       (each rendered at 0px width) whenever a sibling squeezed this down
       to its minimum. Raised so every segment keeps a few visible pixels
       even in the worst case (long status text + narrow viewport). */
    min-width: 180px;
}

/* Little rectangles with curved (not fully round) edges — a small
   border-radius rather than a full pill/stadium shape, so each segment
   reads as a short dash even when it isn't much wider than it is tall,
   instead of looking like a row of dots. */
.kg-preloader-bar span {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.22);
    transition: background .22s ease, box-shadow .22s ease, transform .22s ease;
}

.kg-preloader-bar span.kg-seg-filled {
    background: #FFFFFF;
    box-shadow: 0 0 7px rgba(255, 255, 255, .65);
    transform: scaleY(1.15);
}

@media (prefers-reduced-motion: reduce) {
    .kg-preloader-glow,
    .kg-preloader-rings span,
    .kg-preloader-status-ring::before {
        animation: none;
    }
    .kg-preloader-bar span {
        transition: background .05s linear;
    }
}

@media (max-width: 640px) {
    .kg-preloader-rings { display: none; }
    .kg-preloader-glow { width: 420px; height: 420px; }
    .kg-preloader-inner { padding: 24px 20px; }
    .kg-preloader-subtitle { margin-bottom: 26px; }
    /* Stack rather than wrap: with the status text now allowed to grow to
       several lines, letting the two items wrap mid-row (the old
       flex-wrap approach) made "Please Wait" land unpredictably beside
       whichever line the status text's wrap happened to end on. Stacking
       them in a column keeps "Please Wait" cleanly below the full status
       message every time. */
    .kg-preloader-footer-captions { flex-direction: column; align-items: flex-start; gap: 4px; }
}

@media (max-width: 380px) {
    .kg-preloader-brand-logo { height: 28px; margin-bottom: 18px; }
    .kg-preloader-badge-icon { width: 28px; height: 28px; }
    .kg-preloader-badge-text { font-size: 10px; padding: 6px 14px; }
    .kg-preloader-subtitle { font-size: 13px; }
    .kg-preloader-status-text,
    .kg-preloader-wait { font-size: 10px; }
}
