/* =========================================================
GLOBAL & RESET RULES & THEME VARIABLES
========================================================= */
:root {
    /* Fallback theme colors */
    --primary-color: #6260FF;
    --secondary-color: #6E66FF;
    --background-color: #161E29;

    /* Computed theme variables */
    --header-bg: var(--primary-color);
    --chat-bg: var(--background-color);
    --launcher-bg: linear-gradient(180deg, var(--primary-color) 0%, var(--secondary-color) 65%);
    --text-on-primary: white;
    --text-on-surface: white;
    --message-bubble-user: var(--secondary-color);
    --message-bubble-bot: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.2);
}

/* Light theme detection - when surface is light, adjust colors */
@supports (color: color-contrast(white vs black)) {
    :root {
        --text-on-surface: color-contrast(var(--background-color) vs white, black);
        --text-on-primary: color-contrast(var(--primary-color) vs white, black);
    }
}

/* Manual light theme adjustments */
.theme-light {
    --text-on-surface: #1a1a1a;
    --message-bubble-bot: rgba(0, 0, 0, 0.05);
    --input-bg: rgba(0, 0, 0, 0.05);
    --border-color: rgba(0, 0, 0, 0.1);
    --launcher-bg: linear-gradient(180deg, var(--primary-color) 0%, var(--secondary-color) 65%);
}

.embed-variant #minimizeChat,
.embed-variant #closeChat,
.embed-variant #chatToggle {
    display: none !important;
}

* {
    box-sizing: border-box;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    /* Use surface as base; add subtle gradient tint with primary */
    background:
        radial-gradient(60% 80% at 50% 0%, color-mix(in srgb, var(--primary-color) 8%, transparent) 0%, transparent 70%),
        linear-gradient(180deg, color-mix(in srgb, var(--primary-color) 6%, transparent) 0%, transparent 40%),
        var(--background-color);
    backdrop-filter: blur(8px);
    z-index: 9999;
    animation: fadeIn 0.24s ease;
}

/* Loading dots use primary/secondary alternation */
.loading-spinner {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.loading-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: loadingBounce 1.4s ease-in-out infinite both;
    background: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 20%, transparent);
}

.loading-dot:nth-child(2) {
    background: var(--secondary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--secondary-color) 20%, transparent);
    animation-delay: -0.16s;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

/* Text color adapts to surface */
.loading-text {
    /* try to respect theme; fallback for browsers without color-contrast() */
    color: var(--text-on-surface, #fff);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .2px;
    opacity: .9;
}

/* Simple fade-in */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#launcherView,
#launcherView #launcher-greeting {
    color: var(--text-on-surface) !important;
}

#launcherView #launcher-title {
    color: var(--text-on-primary) !important;
}

/* Dot pulse */
@keyframes loadingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.6;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Visibility control - hide all content until theme is ready */
/* Hide launcher and widget by default to prevent default color flash */
#launcherView {
    visibility: hidden;
}

body.launcher-ready #launcherView {
    visibility: visible;
}

body.launcher-ready #loadingOverlay {
    display: none;
}

/* Also hide the widget container until bootstrap is ready (prevents default-theme flash). */
body:not(.launcher-ready) .widget-container {
    visibility: hidden;
}

body.launcher-ready .widget-container {
    visibility: visible;
}

/* Hide body content by default - only show after theme is confirmed */
/* This prevents any flash of default colors on page load */
body:not(.launcher-ready) {
    overflow: hidden;
}

/* Ensure loading overlay always covers everything and uses theme colors */
#loadingOverlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    /* Higher z-index to ensure it's always on top */
}

/* =========================================================
LAYOUT: EMBED LAUNCHER VIEW
========================================================= */
.embed-launcher {
    display: block;
    width: 100%;
    height: 100vh;
    background: var(--launcher-bg);
    padding: 24px 16px 16px;
    color: var(--text-on-surface);
}

.embed-launcher .cta-btn {
    display: inline-flex;
    /* horizontal layout */
    align-items: center;
    /* vertical centering */
    justify-content: center;
    gap: 8px;
    /* space between text and icon */
    line-height: 1;
    /* prevent extra vertical space */
    white-space: nowrap;
    /* avoid wrapping */
}

/* Normalize icon size and baseline */
.embed-launcher .cta-btn svg {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    /* align to text middle */
    transform: translateY(1px);
}

/* ---------------------------
    Hero Card
--------------------------- */
.embed-launcher .hero-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    padding: 16px;
    margin-top: 16px;
    color: #1a1a1a;
}

.theme-light .embed-launcher .hero-card {
    background: rgba(255, 255, 255, 0.9);
}

/* ---------------------------
    CTA Button
--------------------------- */
.embed-launcher .cta-btn {
    display: block;
    width: 100%;
    height: 48px;
    background: var(--secondary-color, #0d5bd7);
    color: var(--text-on-primary, #ffffff);
    border: 0;
    border-radius: 10px;
    font-weight: 700;
    transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, color 150ms ease;
    will-change: transform;
    cursor: pointer;
}

.embed-launcher .cta-btn:hover,
.embed-launcher .cta-btn:focus-visible {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    background: color-mix(in srgb, var(--secondary-color), black 15%);
}

/* =========================================================
HEADER (Fixed, Shared)
========================================================= */
.parent-header {
    position: fixed;
    top: 10px;
    left: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
    /* allow inputs under header except buttons */
}

/* ---------------------------
    Header Buttons
--------------------------- */
.parent-header .btn-icon {
    pointer-events: auto;
    background: #ffffff;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}


/* =========================================================
TILE GRID & BUTTONS
========================================================= */
.tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    --tile-gap: 14px;
    gap: var(--tile-gap);
    margin-top: 16px;
}

/* ---------------------------
    Tile Button Base
--------------------------- */
.tile-btn {
    height: 120px;
    border: 0;
    border-radius: 16px;
    color: #fff;
    font-weight: 700;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, color 150ms ease;
    will-change: transform;
}

.tile-btn span {
    margin-top: 6px;
}

/* ---------------------------
    WhatsApp Tile
--------------------------- */
.tile-wa {
    background: #25d366;
}

.tile-wa:hover,
.tile-wa:focus-visible {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    background: color-mix(in srgb, #25d366, black 25%);
}

/* ---------------------------
    Telegram Tile
--------------------------- */
.tile-tg {
    /* Telegram brand */
    background: #2AABEE;
}

.tile-tg:hover,
.tile-tg:focus-visible {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    background: color-mix(in srgb, #2AABEE, black 25%);
}

/* ---------------------------
    Line Tile
--------------------------- */
.tile-line {
    /* LINE brand */
    background: #00C300;

    /* Center the LINE tile between WA and TG without changing its size */
    grid-column: 1 / -1;
    /* span both columns */
    justify-self: center;
    /* center it horizontally */
    width: calc((100% - var(--tile-gap)) / 2);
    /* keep same width as one column */
}

.tile-line:hover,
.tile-line:focus-visible {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    background: color-mix(in srgb, #00C300, black 25%);
}

/* ---------------------------
    Link text behavior
--------------------------- */
.tile-btn,
.tile-btn:link,
.tile-btn:visited,
.tile-btn:hover,
.tile-btn:focus,
.tile-btn:active {
    text-decoration: none !important;
    color: #fff;
}

/* =========================================================
LAYOUT: EMBED WIDGET VIEW
========================================================= */

/* ---------------------------
    Header Back Button
--------------------------- */
.header-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 4px;
    cursor: pointer;
    color: var(--text-on-primary);
    transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.header-back:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.theme-light .header-back:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.header-back svg {
    width: 20px;
    height: 20px;
}

.header-back:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* =========================================================
DATE FLOATING INDICATOR (Sticky, Centered)
========================================================= */
.date-floating-indicator {
    position: sticky;
    top: 10px;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
    margin-bottom: 12px;
}

.date-floating-indicator-label {
    padding: 6px 20px;
    border-radius: 999px;
    background: var(--date-chip-bg, rgba(255, 255, 255, 0.92));
    color: var(--date-chip-text, #2d2d2d);
    font-size: 12px;
    letter-spacing: 0.5px;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(20, 23, 28, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.05);
}