/**
 * Footer dock — glass pill navigation (matches search bar + header chips).
 */

#footer {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: var(--ttms-z-footer-controls, 55);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.55rem;
    padding: 0 max(0.65rem, env(safe-area-inset-right, 0)) max(0.85rem, env(safe-area-inset-bottom, 0)) max(0.65rem, env(safe-area-inset-left, 0));
    pointer-events: none;
    box-sizing: border-box;
}

/* Settings popover above dock */
#footerSettings {
    --footer-settings-accent: color-mix(in srgb, var(--selected-button-color3, #fcd000) 55%, #fff);
    position: relative;
    width: min(100%, 22rem);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(0.75rem) scale(0.98);
    transition:
        opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.32s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.28s;
}

#footerSettings.hide {
    display: flex !important;
    width: min(100%, 22rem) !important;
    height: auto !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(0.75rem) scale(0.98);
}

#footerSettings:not(.hide) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.footer-settings-popover {
    width: 100%;
    border-radius: 1.1rem;
    border: 1px solid color-mix(in srgb, var(--footer-settings-accent) 38%, rgba(255, 255, 255, 0.16));
    background: linear-gradient(
        165deg,
        color-mix(in srgb, var(--footer-bg-color, #111) 68%, rgba(255, 255, 255, 0.12)) 0%,
        color-mix(in srgb, var(--footer-bg-color, #111) 88%, rgba(0, 0, 0, 0.35)) 100%
    );
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow:
        0 14px 34px rgba(0, 0, 0, 0.38),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.footer-settings-popover__header {
    padding: 0.7rem 1rem 0.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.footer-settings-popover__title {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--footer-text-color, #fff) 72%, transparent);
}

.footer-settings-popover__body {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.65rem;
}

.footer-settings-popover__btn,
#footerSettings .btn.settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.65rem;
    width: 100%;
    min-height: 2.85rem;
    margin: 0;
    padding: 0.65rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 0.85rem;
    background: linear-gradient(
        160deg,
        rgba(255, 255, 255, 0.12) 0%,
        rgba(255, 255, 255, 0.05) 100%
    );
    color: var(--footer-text-color, #fff);
    text-decoration: none;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition:
        transform 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.footer-settings-popover__btn:hover,
#footerSettings .btn.settings-btn:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--footer-settings-accent) 45%, rgba(255, 255, 255, 0.22));
    background: linear-gradient(
        160deg,
        rgba(255, 255, 255, 0.18) 0%,
        rgba(255, 255, 255, 0.08) 100%
    );
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.footer-settings-popover__btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: var(--footer-settings-accent);
    flex-shrink: 0;
}

.footer-settings-popover__btn-label {
    line-height: 1.2;
}

.footer-settings-popover__btn--logout {
    border-color: color-mix(in srgb, #e74c3c 35%, rgba(255, 255, 255, 0.14));
}

.footer-settings-popover__btn--logout .footer-settings-popover__btn-icon {
    color: color-mix(in srgb, #ff8a80 88%, var(--footer-settings-accent));
}

.footer-settings-popover__btn--logout:hover {
    border-color: color-mix(in srgb, #e74c3c 55%, rgba(255, 255, 255, 0.22));
}

/* Bottom action dock */
#footerBtns.footer-dock {
    --footer-dock-accent: color-mix(in srgb, var(--selected-button-color3, #fcd000) 55%, #fff);
    position: relative;
    width: min(100%, 26rem);
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    background-image: none !important;
    opacity: 0;
    pointer-events: none;
    transform: translateY(0.5rem);
    transition:
        opacity 0.45s ease,
        transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

#footerBtns.footer-dock.visible {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateY(0);
}

#footerBtns.footer-dock.grad2::before {
    content: '';
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    height: calc(6.5rem + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
    z-index: -1;
}

#footerBtns.footer-dock.grad1::before {
    height: calc(8.5rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(
        180deg,
        transparent 0%,
        color-mix(in srgb, var(--footer-bg-color, #000) 28%, transparent) 35%,
        color-mix(in srgb, var(--footer-bg-color, #000) 88%, transparent) 100%
    );
}

.footer-dock__bar {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
    min-height: 3.65rem;
    padding: 0.4rem 0.45rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--footer-dock-accent) 34%, rgba(255, 255, 255, 0.14));
    background: linear-gradient(
        165deg,
        color-mix(in srgb, var(--footer-bg-color, #111) 70%, rgba(255, 255, 255, 0.12)) 0%,
        color-mix(in srgb, var(--footer-bg-color, #111) 90%, rgba(0, 0, 0, 0.35)) 100%
    );
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.36),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.footer-dock__action {
    position: relative;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-width: 0;
    width: auto !important;
    max-width: none !important;
    padding: 0.35rem 0.2rem 0.28rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: color-mix(in srgb, var(--footer-text-color, #fff) 88%, transparent);
    text-decoration: none;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        background 0.2s ease,
        color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.footer-dock__action:hover,
.footer-dock__action:focus-visible {
    color: var(--footer-text-color, #fff);
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

.footer-dock__action:active {
    transform: scale(0.96);
}

.footer-dock__action:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.55);
    outline-offset: 1px;
}

.footer-dock__icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: background 0.2s ease, transform 0.2s ease;
}

.footer-dock__action:hover .footer-dock__icon-wrap,
.footer-dock__action:focus-visible .footer-dock__icon-wrap {
    background: rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

.footer-dock__icon,
#footerBtns .footer-dock__icon {
    width: 1.35rem !important;
    height: 1.35rem !important;
    max-width: 1.35rem !important;
    max-height: 1.35rem !important;
    display: block;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
    transition: transform 0.2s ease;
}

.footer-dock__label {
    font-size: 0.58rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.02em;
    opacity: 0.82;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.footer-dock__action:hover .footer-dock__label,
.footer-dock__action:focus-visible .footer-dock__label {
    opacity: 1;
}

.footer-dock__badge,
#cartcount {
    position: absolute;
    top: -0.15rem;
    right: -0.1rem;
    z-index: 2;
    min-width: 1.15rem;
    height: 1.15rem;
    padding: 0 0.28rem;
    border-radius: 999px;
    border: 1.5px solid rgba(255, 255, 255, 0.85);
    background: linear-gradient(135deg, #e53935, #c62828);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    line-height: 1.15rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.footer-dock__badge.hide,
#cartcount.hide {
    display: none !important;
    width: auto !important;
    height: auto !important;
}

/* Active settings tab */
#footerSettings:not(.hide) ~ #footerBtns .footer-dock__action--settings {
    color: var(--footer-text-color, #fff);
    background: rgba(255, 255, 255, 0.1);
}

#footerSettings:not(.hide) ~ #footerBtns .footer-dock__action--settings .footer-dock__icon-wrap {
    background: color-mix(in srgb, var(--footer-dock-accent) 28%, rgba(255, 255, 255, 0.12));
    border: 1px solid color-mix(in srgb, var(--footer-dock-accent) 45%, transparent);
}

#footerSettings:not(.hide) ~ #footerBtns .footer-dock__action--settings .footer-dock__label {
    opacity: 1;
}

/* Expanded dock when cart/settings open (legacy JS classes) */
#footerBtns.bigfont .footer-dock__icon,
#footerBtns.bigfont .footer-dock__icon-wrap {
    transform: none;
}

#footerBtns.bigfont .footer-dock__icon,
#footerBtns.bigfont .footer-dock__icon {
    width: 1.5rem !important;
    height: 1.5rem !important;
    max-width: 1.5rem !important;
    max-height: 1.5rem !important;
}

#footerBtns.smallfont .footer-dock__label {
    font-size: 0.46rem;
}

/* Cart open — keep badge visible but hide dock (cart.css) */
.cartopen #cartcount {
    position: absolute !important;
    top: -0.15rem !important;
    right: -0.1rem !important;
    rotate: none !important;
    transform: none !important;
}

@media (max-width: 768px) {
    #footer {
        padding-inline: 0.5rem;
        padding-bottom: 0.65rem;
    }

    .footer-dock__bar {
        min-height: 3.35rem;
        padding: 0.32rem 1rem;
        gap: 0.2rem;
    }

    .footer-dock__icon-wrap {
        width: 2rem;
        height: 2rem;
    }

    .footer-dock__label {
        font-size: 0.52rem;
    }
}

@media (max-width: 380px) {
    .footer-dock__label {
        display: none;
    }

    .footer-dock__bar {
        min-height: 3rem;
    }

    .footer-dock__action {
        padding-block: 0.42rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #footerSettings,
    #footerBtns.footer-dock,
    .footer-dock__action,
    .footer-dock__icon-wrap,
    .footer-settings-popover__btn {
        transition: none;
    }
}
