/* Application form (index.php) and finish page (finish.php) - mobile-first, on top of Bootstrap 5.3 */

@font-face {
    font-family: 'Montserrat';
    font-weight: 400;
    font-display: swap;
    src: url("../../fonts/montserrat/Montserrat-Regular.ttf");
}
@font-face {
    font-family: 'Montserrat';
    font-weight: 600;
    font-display: swap;
    src: url("../../fonts/montserrat/Montserrat-SemiBold.ttf");
}
/* Lao text only (unicode-range): Montserrat has no Lao glyphs */
@font-face {
    font-family: 'Phetsarath OT';
    font-display: swap;
    src: url("../../fonts/psrot/Phetsarath-OT.woff") format("woff");
    unicode-range: U+0E80-0EFF;
}
@font-face {
    font-family: 'emboss';
    font-display: swap;
    src: url("../../fonts/emboss/OCRAStd.otf");
}
@font-face {
    font-family: 'danshand';
    font-display: swap;
    src: url("../../fonts/dans/DansHandWriting.ttf");
}

:root {
    --mc-red: #eb001b;
    --mc-orange: #f79e1b;
    --brand: #bb1111;
    --bs-font-sans-serif: 'Montserrat', 'Phetsarath OT', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Lao', sans-serif;
    --bs-primary: var(--brand);
    --bs-primary-rgb: 187, 17, 17;
    --bs-link-color: var(--brand);
}

body {
    background: #f2f2f2;
    min-height: 100vh;
}

/* ---------- header ---------- */
/* Banner photo under a brand-colour scrim: the photo is light and busy, so white text needs the
   darker left side. Height comes from padding + content only (no fixed height), so it grows with
   wrapped text and the logo is never cropped. The url is relative to this file, so it works in a
   sub-folder (XAMPP /mywayweb/) as well as at the web root (= /images/master_myway_banner.jpg). */
.apply-header {
    --header-scrim: linear-gradient(to right, rgba(140, 0, 16, .92) 0%, rgba(235, 0, 27, .82) 55%, rgba(247, 158, 27, .70) 100%);
    background-color: var(--mc-red);            /* shown until / if the image does not load */
    background-image: var(--header-scrim), url("../../images/master_myway_banner.jpg");
    background-size: cover, cover;
    background-position: center center, center center;
    background-repeat: no-repeat, no-repeat;
    color: #fff;
    padding: 12px 0 64px;
}
.apply-header-inner {
    max-width: 760px;
}
.apply-header img {
    flex-shrink: 0;                             /* the logo keeps its size; the text wraps instead */
    width: 44px;
    height: 44px;
    background: #fff;
    border-radius: 50%;
}
.apply-header h1 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.apply-header small {
    display: block;
    opacity: .95;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

/* EN | ລາວ switch (libs/i18n.php i18n_toggle(), assets/js/i18n.js) */
.lang-toggle {
    display: inline-flex;
    flex-shrink: 0;
    align-self: flex-start;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, .75);
    border-radius: 999px;
    background: rgba(0, 0, 0, .18);
}
.lang-toggle button {
    min-width: 44px;
    min-height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
    line-height: 1;
}
.lang-toggle button[aria-pressed="true"] {
    background: #fff;
    color: var(--brand);
}
.lang-toggle button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.apply-main {
    margin-top: -52px;
    max-width: 760px;
    padding-bottom: 96px; /* room for the sticky nav */
}
.apply-card {
    border: 0;
    border-radius: 16px;
}

/* ---------- stepper ---------- */
.stepper {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
    counter-reset: step;
}
.stepper li {
    flex: 1;
    position: relative;
    text-align: center;
    font-size: .7rem;
    text-transform: uppercase;
    color: #8a8a8a;
    counter-increment: step;
}
.stepper li::before {
    content: counter(step);
    display: block;
    width: 30px;
    height: 30px;
    line-height: 26px;
    margin: 0 auto 4px;
    border: 2px solid #d8d6d6;
    border-radius: 50%;
    background: #fff;
    font-weight: 600;
    position: relative;
    z-index: 1;
}
.stepper li + li::after {
    content: '';
    position: absolute;
    top: 14px;
    left: -50%;
    width: 100%;
    height: 2px;
    background: #d8d6d6;
}
.stepper li.active,
.stepper li.done {
    color: var(--brand);
}
.stepper li.active::before {
    border-color: var(--brand);
}
.stepper li.done::before {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}
.stepper li.active::after,
.stepper li.done::after {
    background: var(--brand);
}

.step-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* ---------- form controls ---------- */
.form-control,
.form-select {
    min-height: 48px;          /* comfortable touch targets */
    font-size: 16px;           /* prevents iOS zoom on focus */
}
.form-control:focus,
.form-select:focus {
    border-color: var(--mc-orange);
    box-shadow: 0 0 0 .2rem rgba(247, 158, 27, .25);
}
.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}
.form-label {
    font-weight: 600;
    margin-bottom: .3rem;
}

/* gender: two large radio buttons with ♂ / ♀ (Bootstrap .btn-check keeps native radio behaviour) */
.gender-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 420px;
}
.gender-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 56px;
    border: 1px solid #ced4da;
    border-radius: 12px;
    background: #fff;
    color: #333;
    font-weight: 600;
}
.gender-option:hover {
    border-color: #adb5bd;
    background: #fafafa;
}
.gender-symbol {
    font-family: 'Segoe UI Symbol', 'DejaVu Sans', 'Noto Sans Symbols', sans-serif;
    font-size: 1.6rem;
    font-weight: 400;
    line-height: 1;
}
.gender-symbol-male { color: #1d6fb8; }
.gender-symbol-female { color: #c2185b; }
.btn-check:checked + .gender-option {
    border: 2px solid var(--brand);
    background: #fff5f5;
    color: var(--brand);
}
.btn-check:focus-visible + .gender-option {
    box-shadow: 0 0 0 .2rem rgba(247, 158, 27, .35);
}
/* "English characters only" note; turns red for a moment when a character was removed (apply.js) */
.en-only-note {
    margin-top: .25rem;
    transition: color .2s;
}
.form-label + .en-only-note {
    margin-top: -.15rem;
}
.en-only-note.is-flagged {
    color: var(--bs-form-invalid-color, #dc3545);
    font-weight: 600;
}
.counter {
    font-weight: 400;
    color: #8a8a8a;
}

/* ---------- sticky navigation ---------- */
.apply-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    background: #fff;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .08);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.apply-nav .inner {
    max-width: 728px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
}
.btn-brand {
    background: linear-gradient(to left, var(--mc-orange), var(--mc-red));
    border: 0;
    color: #fff;
    font-weight: 600;
    min-height: 48px;
}
.btn-brand:hover,
.btn-brand:focus,
.btn-brand:disabled {
    color: #fff;
    filter: brightness(.95);
}
/* Bootstrap's compiled button colours don't follow --bs-primary: map them to the brand red */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: #9f0e0e;
    --bs-btn-hover-border-color: #9f0e0e;
    --bs-btn-active-bg: #870c0c;
    --bs-btn-active-border-color: #870c0c;
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: 187, 17, 17;
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #9f0e0e;
    --bs-btn-active-border-color: #9f0e0e;
    --bs-btn-disabled-color: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: 187, 17, 17;
}

/* ---------- card designer ---------- */
.card-preview {
    container-type: inline-size;   /* 1cqw = 1% of card width */
    position: relative;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    /* CR80 / ISO 7810 ID-1: 85.60 x 53.98 mm, corner radius 3.18 mm (= 3.715% of the width).
       The print file is 2000x1262 px (~593 dpi), within 0.1% of this ratio. */
    aspect-ratio: 85.6 / 53.98;
    background: #fff;
    border-radius: 3.715cqw;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
    user-select: none;
}
.card-photo {
    position: absolute;
    inset: 0 0 auto 0;
    height: 64.9%;                  /* 819 / 1262: the photo area */
    background: repeating-linear-gradient(45deg, #f6f6f6 0 10px, #eee 10px 20px);
}
.card-photo > img {
    display: block;
    max-width: 100%;               /* required by Cropper.js */
}
.photo-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    color: #666;
    font-size: clamp(13px, 3.4cqw, 17px);
    font-weight: 600;
    z-index: 30;                    /* above the frame so it can be tapped */
}
.photo-empty svg {
    width: 9cqw;
    height: 9cqw;
}
.has-photo .photo-empty {
    display: none;
}

/* decorations drawn by the server (img_crop_to_file.php / form_save.php) - not touchable */
.card-layer {
    position: absolute;
    pointer-events: none;
    z-index: 10;
}
.card-frame {
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
}
.card-logo        { left: 2.25%; top: 3.57%;  width: 10%; }   /* bcellogo 45,45 200x200 */
.card-contactless { left: 88.5%; top: 30.5%;  width: 10%; }   /* 1770,385 200x200 */
.card-prepaid     { left: 75%;   top: 7.92%;  width: 22.3%; } /* 1500,100 446x75 */
.card-label {
    /* matches form_save.php: imagettftext(365pt, x=120, baseline y=1210) on a 2000x1262 card,
       derived from the DansHandWriting metrics (ascent .8em, descent .2em) */
    left: 6%;
    top: 65.13%;
    font-family: danshand, cursive;
    font-size: 24.25cqw;
    line-height: 1;
    color: #777;
    white-space: nowrap;
    z-index: 11;
}
.card-expire,
.card-emboss {
    font-family: emboss, monospace;
    font-weight: bold;
    color: #514e2c;
    opacity: .85;
    line-height: 1;
    text-shadow: -1px -1px 1px #fff, 1px 1px 1px rgba(0, 0, 0, .4);
    white-space: nowrap;
    z-index: 21;
}
.card-expire { left: 43.6%; top: 74.6%; font-size: 4.2cqw; }
.card-emboss { left: 8.6%;  top: 83.5%; font-size: 3.7cqw; text-transform: uppercase; }

/* Cropper.js: the crop box is the whole photo area - hide its chrome */
.card-photo .cropper-view-box {
    outline: 0;
    box-shadow: none;
}
.card-photo .cropper-face {
    background: transparent;
}
.card-photo .cropper-container {
    touch-action: none;
}

.photo-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}
.photo-tools .btn {
    min-width: 48px;
    min-height: 44px;
}
.photo-tools svg {
    width: 20px;
    height: 20px;
    vertical-align: -4px;
}

/* ---------- done step ---------- */
.done-icon {
    width: 72px;
    height: 72px;
    color: #198754;
}

/* ---------- finish page (finish.php) ---------- */
.finish-main {
    margin-top: -52px;
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
}
.request-code-panel {
    background: #fff7ef;
    border: 1px solid #f8d9b0;
    border-radius: 12px;
    padding: 16px;
}
.request-qr {
    display: block;
    width: 136px;
    max-width: 50%;
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
    padding: 6px;
    background: #fff;
    border-radius: 8px;
    image-rendering: pixelated;     /* keep the QR modules sharp when scaled */
}
.request-code {
    font-family: ui-monospace, Consolas, 'Courier New', monospace;
    font-size: clamp(1.3rem, 6.5vw, 1.75rem);
    font-weight: 600;
    letter-spacing: .06em;
    color: #222;
}
/* the stored card (2000x1262) fills the CR80 preview box; height follows the width */
.card-preview-static .card-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.finish-actions .btn {
    min-height: 48px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #8a8a8a;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid #ddd;
}

@media (min-width: 768px) {
    body {
        background: #f2f2f2 url("../../images/bg-mastercard.png") center / cover fixed no-repeat;
    }
    .apply-header {
        /* wider screens: lighter on the right so more of the banner shows */
        --header-scrim: linear-gradient(to right, rgba(140, 0, 16, .90) 0%, rgba(235, 0, 27, .72) 45%, rgba(247, 158, 27, .45) 100%);
        padding: 20px 0 80px;
    }
    .apply-header img {
        width: 52px;
        height: 52px;
    }
    .finish-main {
        margin-top: -60px;
    }
    .apply-header h1 {
        font-size: 1.3rem;
    }
    .stepper li {
        font-size: .78rem;
    }
}
