/* MentaLoyalty — global custom styles.
 * Tailwind handles 99% of styling; this stylesheet covers the bits Tailwind
 * cannot express ergonomically: glassmorphism, the 3D card perspective,
 * the ambient background blobs, and the custom scrollbar.
 */

:root {
    --brand-primary: #7DCCC1;
    --brand-secondary: #4FA896;
    --brand-font-body: "Geologica Brand", "Geologica", system-ui, sans-serif;
    --brand-font-heading: "Geologica Brand", "Geologica", system-ui, sans-serif;
    /* Pre-derived tints so children don't need color-mix calls everywhere. */
    --brand-soft-bg: color-mix(in srgb, var(--brand-primary) 14%, transparent);
    --brand-soft-border: color-mix(in srgb, var(--brand-primary) 32%, transparent);
    --brand-strong-bg: color-mix(in srgb, var(--brand-primary) 28%, transparent);
    --brand-readable: color-mix(in srgb, var(--brand-primary) 22%, #f8fafc 78%);
    --brand-glow: color-mix(in srgb, var(--brand-primary) 45%, transparent);
}

body {
    background-color: #0f172a;
    color: #f8fafc;
    font-family: var(--brand-font-body, "Geologica Brand", system-ui, sans-serif);
}

@font-face {
    font-family: "Geologica Brand";
    src: url("../brands/fonts/Geologica-Variable.2926daa6f6c9.ttf") format("truetype");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Artegra Brand";
    src: url("../brands/fonts/ArtegraSansCondensed-SemiBold.ade1a3c02b2d.otf") format("opentype");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

h1, h2, h3, .brand-heading {
    font-family: var(--brand-font-heading, var(--brand-font-body));
}

::selection {
    background-color: var(--brand-primary);
    color: white;
}

/* ------------------------------------------------------------------ */
/* Brand-aware helpers — used in place of Tailwind static brand-XXX   */
/* utilities so the whole UI re-tints when the active brand changes.  */
/* ------------------------------------------------------------------ */

.text-brand        { color: var(--brand-readable); }
.text-brand-deep   { color: var(--brand-primary); }
.bg-brand-soft     { background-color: var(--brand-soft-bg); }
.bg-brand-strong   { background-color: var(--brand-strong-bg); }
.border-brand-soft { border-color: var(--brand-soft-border); }
.ring-brand        { box-shadow: 0 0 0 1px var(--brand-soft-border); }

.btn-brand {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    color: white;
    box-shadow: 0 12px 28px -12px var(--brand-glow);
}

.btn-brand:hover {
    filter: brightness(1.08);
}

.btn-brand-ghost {
    background-color: var(--brand-soft-bg);
    color: var(--brand-readable);
    border: 1px solid var(--brand-soft-border);
}

.btn-brand-ghost:hover {
    background-color: var(--brand-strong-bg);
}

.input-brand:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 1px var(--brand-primary);
}

/* Smooth re-tint of brand-aware surfaces between switches. The actual
 * brand-color CSS variables are toggled instantly by the server-rendered
 * <style> block, but any element that pulls from them gets a soft fade. */
.btn-brand,
.btn-brand-ghost,
.text-brand,
.text-brand-deep,
.bg-brand-soft,
.bg-brand-strong,
.border-brand-soft,
.blob,
.loyalty-card-bg {
    transition:
        background-color 600ms ease,
        color 600ms ease,
        border-color 600ms ease,
        box-shadow 600ms ease,
        background 600ms ease;
}

/* ------------------------------------------------------------------ */
/* Glassmorphism                                                       */
/* ------------------------------------------------------------------ */

.glass {
    background: rgba(30, 41, 59, 0.70);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.glass-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.10);
}

/* Store portal — KPI card labels & section headings (white, not muted grey) */
.card-stat-label {
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #ffffff;
}

.card-stat-label-sm {
    font-size: 0.625rem;
    line-height: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #ffffff;
}

.section-kicker {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #ffffff;
    margin-bottom: 0.75rem;
}

/* ------------------------------------------------------------------ */
/* 3D card                                                             */
/* ------------------------------------------------------------------ */

.perspective-1000 {
    perspective: 1000px;
    touch-action: none;
}

.preserve-3d {
    transform-style: preserve-3d;
}

.translate-z-10 {
    transform: translateZ(50px);
}

.card-corner-btn {
    transform: translateZ(60px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.card-corner-btn:active {
    transform: translateZ(60px) scale(0.94);
}

.card-corner-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.85);
    outline-offset: 2px;
}

.translate-z-bg {
    transform: translateZ(-20px);
}

.card-flip {
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.card-flip.is-flipped {
    transform: rotateY(180deg);
}

.card-face-back {
    transform: rotateY(180deg);
    backface-visibility: hidden;
    -webkit-backfaceVisibility: hidden;
}

.card-face-front {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ------------------------------------------------------------------ */
/* Brand-themed loyalty card                                           */
/* ------------------------------------------------------------------ */

.loyalty-card-bg {
    background:
        radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--brand-primary) 92%, white 8%) 0%, transparent 55%),
        radial-gradient(circle at 80% 75%, color-mix(in srgb, var(--brand-secondary) 80%, black 20%) 0%, transparent 60%),
        linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    box-shadow: 0 25px 50px -12px color-mix(in srgb, var(--brand-primary) 45%, transparent);
}

.loyalty-card-logo img {
    filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.45));
}

.loyalty-card-bg[data-brand="menta"] {
    background:
        radial-gradient(circle at 18% 22%, rgba(125, 204, 193, 0.38) 0%, transparent 52%),
        radial-gradient(circle at 82% 78%, rgba(79, 168, 150, 0.22) 0%, transparent 58%),
        linear-gradient(145deg, #050505 0%, #0a0a0a 42%, #111827 100%);
    border: 1px solid rgba(125, 204, 193, 0.28);
    box-shadow:
        0 25px 50px -12px rgba(125, 204, 193, 0.35),
        inset 0 1px 0 rgba(125, 204, 193, 0.12);
}

.loyalty-card-bg[data-brand="menta"]::after {
    content: "";
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(125, 204, 193, 0.85) 50%,
        transparent
    );
    pointer-events: none;
}

.loyalty-card-bg[data-brand="hankypanky"] {
    background:
        radial-gradient(circle at 22% 18%, rgba(51, 102, 255, 0.55) 0%, transparent 50%),
        radial-gradient(circle at 78% 82%, rgba(0, 27, 222, 0.65) 0%, transparent 55%),
        linear-gradient(135deg, #001bde 0%, #0028a8 48%, #000818 100%);
    border: 1px solid rgba(51, 102, 255, 0.35);
    box-shadow:
        0 25px 50px -12px rgba(0, 27, 222, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.loyalty-card-bg[data-brand="hankypanky"] .loyalty-card-logo img {
    filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.55)) brightness(1.05);
}

/* ------------------------------------------------------------------ */
/* Auth pages — dual-brand ambient backdrop                            */
/* ------------------------------------------------------------------ */

.auth-scene {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    overflow: hidden;
    isolation: isolate;
    min-height: 100%;
    width: 100%;
}

/* Auth pages: side gradients only — no bottom band, full viewport height. */
body:has(.auth-scene) .blob {
    display: none;
}

body:has(.auth-scene) main,
body:has(.auth-scene) .page-fade {
    min-height: 100%;
}

.auth-scene::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background-color: #050505;
    background-image:
        radial-gradient(ellipse 88% 120% at 0% 50%, var(--auth-glow-menta, rgba(125, 204, 193, 0.34)) 0%, transparent 58%),
        radial-gradient(ellipse 60% 90% at 100% 45%, rgba(79, 168, 150, 0.12) 0%, transparent 55%);
}

.auth-scene::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    opacity: 0.42;
    background:
        radial-gradient(ellipse 48% 92% at 0% 50%, var(--auth-primary-menta, #7DCCC1) 0%, transparent 54%);
    filter: blur(88px);
    pointer-events: none;
}

.auth-scene > * {
    position: relative;
    z-index: 1;
}

.auth-scene[data-auth-brand="menta"]::before {
    background-color: #050505;
    background-image:
        radial-gradient(ellipse 92% 120% at 0% 50%, var(--auth-glow-menta) 0%, transparent 62%),
        radial-gradient(ellipse 55% 85% at 100% 50%, rgba(79, 168, 150, 0.1) 0%, transparent 58%);
}

.auth-scene[data-auth-brand="hankypanky"]::before {
    background-color: #050505;
    background-image:
        radial-gradient(ellipse 92% 120% at 0% 50%, var(--auth-glow-menta, rgba(125, 204, 193, 0.34)) 0%, transparent 62%),
        radial-gradient(ellipse 55% 85% at 100% 50%, rgba(79, 168, 150, 0.1) 0%, transparent 58%);
}

.auth-card {
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        0 24px 48px -16px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.auth-brand-strip {
    padding: 0.35rem 0.5rem;
}

.auth-brand-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 0.85rem;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
}

.auth-brand-pill--menta {
    box-shadow: 0 0 24px -6px rgba(125, 204, 193, 0.35);
    border-color: rgba(125, 204, 193, 0.25);
}

.auth-brand-pill--hankypanky {
    box-shadow: 0 0 24px -6px rgba(0, 27, 222, 0.35);
    border-color: rgba(51, 102, 255, 0.28);
}

.auth-brand-divider {
    width: 1px;
    height: 2rem;
    background: linear-gradient(
        180deg,
        transparent,
        rgba(255, 255, 255, 0.22),
        transparent
    );
}

.store-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.store-role-badge--manager {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(251, 191, 36, 0.35);
}

.store-role-badge--cashier {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.25);
}

/* Tier-coloured chip used in the levels page. */
.tier-chip {
    background: color-mix(in srgb, var(--brand-primary) 18%, transparent);
    border: 1px solid color-mix(in srgb, var(--brand-primary) 38%, transparent);
    color: color-mix(in srgb, var(--brand-primary) 30%, #f8fafc 70%);
}

/* ------------------------------------------------------------------ */
/* Ambient animated blobs                                              */
/* ------------------------------------------------------------------ */

.blob {
    position: absolute;
    filter: blur(80px);
    z-index: 0;
    opacity: 0.4;
    animation: blob-drift 18s infinite alternate ease-in-out;
}

.blob--primary   { background-color: var(--brand-primary); }
.blob--secondary { background-color: var(--brand-secondary); }

@keyframes blob-drift {
    0%   { transform: translate(0, 0)        scale(1); }
    50%  { transform: translate(100px, 50px)  scale(1.15); }
    100% { transform: translate(-60px, 90px)  scale(0.85); }
}

/* ------------------------------------------------------------------ */
/* Scrollbar                                                           */
/* ------------------------------------------------------------------ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ------------------------------------------------------------------ */
/* Form polish                                                         */
/* ------------------------------------------------------------------ */

input[type="checkbox"] {
    accent-color: var(--brand-primary);
}

.errorlist {
    color: #f87171;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.messages-toast {
    animation: fade-in-up 0.4s ease-out;
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ */
/* Scan-to-pay mode — the 3D card lifts out of its grid slot, scales  */
/* up, flips to QR, a red laser-style beam slides over the QR and a   */
/* faux 1D barcode shimmers below. Driven by static/js/card.js.        */
/* ------------------------------------------------------------------ */

#scan-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 45%,
            color-mix(in srgb, var(--brand-primary) 35%, transparent) 0%,
            rgba(0, 0, 0, 0.85) 65%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: opacity 380ms ease;
}

#scan-backdrop.is-active {
    opacity: 1;
    pointer-events: auto;
}

.scan-backdrop-hint {
    position: absolute;
    left: 50%;
    bottom: 6%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 280ms ease 320ms;
}

#scan-backdrop.is-active .scan-backdrop-hint { opacity: 1; }

/* Hide scan-only chrome by default — visible only while .is-scan-mode is on. */
.scan-headline,
.scan-beam,
.scan-barcode {
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
}

#card-container.is-scan-mode .scan-headline,
#card-container.is-scan-mode .scan-beam,
#card-container.is-scan-mode .scan-barcode {
    opacity: 1;
}

.scan-headline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition-delay: 140ms;
}

.scan-headline-dot {
    width: 8px; height: 8px;
    border-radius: 999px;
    background: #f87171;
    box-shadow: 0 0 12px rgba(248, 113, 113, 0.8);
    animation: scan-pulse 1.1s ease-in-out infinite;
}

@keyframes scan-pulse {
    0%, 100% { transform: scale(1);   opacity: 1;   }
    50%      { transform: scale(1.4); opacity: 0.5; }
}

/* Laser scan beam — slides up and down over the QR while scanning. */
.scan-beam {
    position: absolute;
    left: -6%;
    right: -6%;
    top: 0;
    height: 3px;
    z-index: 20;
    background: linear-gradient(90deg,
        rgba(239, 68, 68, 0) 0%,
        rgba(239, 68, 68, 0.95) 50%,
        rgba(239, 68, 68, 0) 100%);
    box-shadow: 0 0 18px 4px rgba(239, 68, 68, 0.55);
    transform: translateY(0);
}

#card-container.is-scan-mode .scan-beam {
    animation: scan-beam 1.8s cubic-bezier(0.65, 0, 0.35, 1) infinite alternate;
}

@keyframes scan-beam {
    0%   { transform: translateY(0);     opacity: 0.4; }
    8%   { opacity: 1; }
    92%  { opacity: 1; }
    100% { transform: translateY(11rem); opacity: 0.4; }
}

/* In scan mode the card is portrait, so we can grow the QR + barcode for
 * easier cashier scanning. */
#card-container.is-scan-mode .scan-qr {
    width:  11rem;
    height: 11rem;
}

/* Faux 1D barcode rendered with repeating-linear-gradients. JS overrides
 * the gradient stops per member_code so each card has its own pattern. */
.scan-barcode {
    width: 11rem;
    height: 28px;
    background:
        repeating-linear-gradient(
            90deg,
            #0f172a 0 2px,
            transparent 2px 4px,
            #0f172a 4px 5px,
            transparent 5px 8px,
            #0f172a 8px 11px,
            transparent 11px 13px);
    border-radius: 4px;
    transition-delay: 200ms;
}

/* The loyalty card itself: when scan-mode is on, the container is pulled
 * into a fixed-position centred frame by JS (via inline left/top/width).
 * The CSS here just adds the polish: deeper shadow, glow, and disabling
 * the natural mouse-tilt while scanning. */
#card-container.is-scan-mode {
    cursor: default;
    filter: drop-shadow(0 30px 60px var(--brand-glow));
}

#card-container.is-scan-mode #loyalty-card {
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reusable transition for the page underlay so each navigation feels smooth */
.page-fade {
    animation: page-fade-in 0.35s ease-out;
}

@keyframes page-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ */
/* Magical brand-switch overlay                                        */
/* ------------------------------------------------------------------ */

#brand-switch-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    background:
        radial-gradient(circle at var(--switch-x, 50%) var(--switch-y, 50%),
            var(--switch-primary, #4F46E5) 0%,
            var(--switch-secondary, #7E22CE) 55%,
            #0f172a 100%);
    clip-path: circle(0% at var(--switch-x, 50%) var(--switch-y, 50%));
    transition: clip-path 700ms cubic-bezier(0.83, 0, 0.17, 1), opacity 220ms ease;
}

#brand-switch-overlay.is-expanding {
    opacity: 1;
    pointer-events: auto;
    clip-path: circle(160% at var(--switch-x, 50%) var(--switch-y, 50%));
}

#brand-switch-overlay.is-collapsing {
    opacity: 1;
    pointer-events: none;
    /* The overlay is rendered fully expanded at first paint when arriving
     * from a brand switch, then this class fades it back to invisible. */
    clip-path: circle(0% at var(--switch-x, 50%) var(--switch-y, 50%));
}

.brand-switch-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.6);
    text-align: center;
    color: white;
    opacity: 0;
    transition: opacity 320ms ease 180ms, transform 480ms cubic-bezier(0.34, 1.56, 0.64, 1) 180ms;
    pointer-events: none;
}

#brand-switch-overlay.is-expanding .brand-switch-card {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.brand-switch-emoji {
    font-size: 5rem;
    line-height: 1;
    margin-bottom: 0.75rem;
    filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.45));
    animation: brand-switch-pulse 1.2s ease-in-out infinite alternate;
}

.brand-switch-name {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.brand-switch-tagline {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    max-width: 28ch;
}

@keyframes brand-switch-pulse {
    from { transform: scale(1);    filter: drop-shadow(0 0 18px rgba(255,255,255,0.35)); }
    to   { transform: scale(1.08); filter: drop-shadow(0 0 32px rgba(255,255,255,0.7));  }
}

/* Inline pre-paint state — set by the inline <script> in <head>
 * when arriving from a brand switch. Renders the overlay fully covered
 * so there is no flash of the new brand colors before the iris collapses. */
#brand-switch-overlay.is-arriving {
    opacity: 1;
    clip-path: circle(160% at var(--switch-x, 50%) var(--switch-y, 50%));
}
