/* ==========================================================================
   CAML desert motion — shared loaders, toggles, skeletons, empty states
   ========================================================================== */

/* --- Sandstorm loader (inline, sm, hero) --- */
.caml-sandstorm {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    overflow: hidden;
    flex-shrink: 0;
}

.caml-sandstorm--inline {
    width: 28px;
    height: 20px;
}

.caml-sandstorm--sm {
    width: 20px;
    height: 14px;
}

.caml-sandstorm--hero {
    position: absolute;
    inset: -6px;
    width: auto;
    height: auto;
    z-index: 0;
    pointer-events: none;
}

.caml-sandstorm i {
    position: absolute;
    display: block;
    border-radius: 50%;
    background: var(--desert-accent, #C97B4B);
    opacity: 0;
    animation: camlSandDrift 1.35s ease-in-out infinite;
}

.caml-sandstorm--inline i,
.caml-sandstorm--sm i {
    width: 3px;
    height: 3px;
}

.caml-sandstorm--hero i {
    width: 5px;
    height: 5px;
    background: #d4895c;
}

.caml-sandstorm i:nth-child(1) { left: 8%;  top: 55%; animation-delay: 0s; }
.caml-sandstorm i:nth-child(2) { left: 28%; top: 35%; animation-delay: 0.18s; width: 4px; height: 4px; }
.caml-sandstorm i:nth-child(3) { left: 48%; top: 60%; animation-delay: 0.36s; }
.caml-sandstorm i:nth-child(4) { left: 62%; top: 30%; animation-delay: 0.52s; }
.caml-sandstorm i:nth-child(5) { left: 78%; top: 50%; animation-delay: 0.7s; }
.caml-sandstorm i:nth-child(6) { left: 90%; top: 40%; animation-delay: 0.88s; }

@keyframes camlSandDrift {
    0%   { opacity: 0; transform: translateX(-6px) translateY(2px); }
    25%  { opacity: 0.85; }
    75%  { opacity: 0.5; }
    100% { opacity: 0; transform: translateX(10px) translateY(-3px); }
}

/* --- Loader blocks --- */
.caml-loader {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--desert-muted, #6b5c52);
    font-size: 0.875rem;
    font-weight: 500;
}

.caml-loader--centered {
    display: flex;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.caml-loader--full {
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 2rem 1rem;
    text-align: center;
}

/* Caravan on dune path (full / route analysis) */
.caml-caravan {
    width: min(200px, 70vw);
    height: 40px;
}

.caml-caravan-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.caml-caravan-track {
    fill: none;
    stroke: var(--desert-sand, #EED6C4);
    stroke-width: 3;
    stroke-linecap: round;
}

.caml-caravan-dot {
    fill: var(--desert-accent, #C97B4B);
    filter: drop-shadow(0 1px 2px rgba(139, 94, 60, 0.35));
}

/* Legacy spinner classes → sandstorm sizing */
.ri-spinner,
.ra-loading-spinner,
.cx-spinner {
    display: none !important;
}

.ri-bar-loading,
.ra-loading,
.cx-tl-loading,
.cx-expand-loading {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ri-bar-loading .caml-loader--full {
    flex-direction: row;
    padding: 0;
    gap: 10px;
}

.ri-bar-loading .caml-caravan {
    width: 88px;
    height: 32px;
}

.ri-bar-loading .caml-loader-text {
    font-size: 13px;
    color: #888;
}

.caml-loader-slot {
    display: inline-flex;
    align-items: center;
    min-width: 28px;
    min-height: 20px;
}

/* Tumbleweed asset (toggle + buttons) */
:root {
    --caml-tumbleweed-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cg fill='none' stroke='%238B6914' stroke-width='1.35' stroke-linecap='round'%3E%3Cellipse cx='16' cy='16' rx='9' ry='8' opacity='.3'/%3E%3Cpath d='M16 5v22M5 16h22M8 8l16 16M24 8L8 24'/%3E%3Cpath d='M10 7l12 4M22 10l-4 12M10 25l12-4M7 22l4-12'/%3E%3C/g%3E%3C/svg%3E");
}

/* --- Tumbleweed toggle (.caml-toggle + .auto-toggle) --- */
.caml-toggle,
.auto-toggle {
    position: relative !important;
    display: inline-block !important;
    width: 52px !important;
    height: 30px !important;
    flex-shrink: 0 !important;
    cursor: pointer !important;
}

.caml-toggle input,
.caml-toggle input[type="checkbox"],
.auto-toggle input,
.auto-toggle input[type="checkbox"] {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
    position: absolute !important;
    visibility: hidden !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.caml-toggle-slider,
.auto-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    border-radius: 30px;
    transition: background 0.4s ease, box-shadow 0.4s ease;
    background: linear-gradient(180deg, #ebe3d4 0%, #dcc9a8 55%, #d0b88a 100%);
    box-shadow: inset 0 1px 4px rgba(139, 94, 60, 0.14);
    overflow: visible;
}

.caml-toggle-slider::after,
.auto-toggle-slider::after {
    content: "";
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 5px;
    height: 3px;
    border-radius: 999px;
    background: rgba(139, 94, 60, 0.12);
    pointer-events: none;
}

.caml-toggle-slider::before,
.auto-toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: var(--caml-tumbleweed-svg) center / contain no-repeat;
    filter: drop-shadow(0 1px 2px rgba(139, 94, 60, 0.25));
    transition: transform 0.55s cubic-bezier(0.45, 0.05, 0.25, 1);
    transform: translateX(0) rotate(0deg);
}

.caml-toggle input:checked + .caml-toggle-slider,
.auto-toggle input:checked + .auto-toggle-slider {
    background: linear-gradient(180deg, #f5ead8 0%, #e8c89a 45%, #d4a574 100%);
    box-shadow: inset 0 0 10px rgba(201, 123, 75, 0.2);
}

.caml-toggle input:checked + .caml-toggle-slider::before,
.auto-toggle input:checked + .auto-toggle-slider::before {
    transform: translateX(24px) rotate(720deg);
}

.caml-toggle input:disabled + .caml-toggle-slider,
.auto-toggle input:disabled + .auto-toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.caml-toggle-sm,
.auto-toggle-sm {
    width: 42px !important;
    height: 26px !important;
}

.caml-toggle-sm .caml-toggle-slider::before,
.caml-toggle-sm .auto-toggle-slider::before,
.auto-toggle-sm .auto-toggle-slider::before {
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
}

.caml-toggle-sm input:checked + .caml-toggle-slider::before,
.auto-toggle-sm input:checked + .auto-toggle-slider::before {
    transform: translateX(18px) rotate(720deg);
}

/* Tumbleweed on busy buttons */
.caml-tumbleweed {
    display: inline-block;
    flex-shrink: 0;
    background: var(--caml-tumbleweed-svg) center / contain no-repeat;
    vertical-align: middle;
}

.caml-tumbleweed--btn {
    width: 20px;
    height: 20px;
    animation: camlTumbleRoll 0.7s linear infinite;
}

.caml-tumbleweed--overlay {
    width: 48px;
    height: 48px;
    animation: camlTumbleRoll 0.85s linear infinite;
    margin: 0 auto 8px;
}

@keyframes camlTumbleRoll {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.caml-btn-busy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    pointer-events: none;
}

.caml-btn-busy-label {
    white-space: nowrap;
}

.btn.caml-is-busy,
button.caml-is-busy,
a.btn.caml-is-busy {
    cursor: wait !important;
}

/* Busy on blue/green/red buttons — sand field so tumbleweed reads clearly */
.btn-primary.caml-is-busy,
.btn-success.caml-is-busy,
.btn-danger.caml-is-busy,
.btn-info.caml-is-busy,
.btn-warning.caml-is-busy,
button.caml-is-busy-contrast {
    background: linear-gradient(180deg, #fffef9 0%, #f8f1de 55%, #f0e4cc 100%) !important;
    border-color: #d4a574 !important;
    color: #8B5E3C !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 2px 10px rgba(139, 94, 60, 0.18) !important;
}

.btn-primary.caml-is-busy .caml-tumbleweed--btn,
.btn-success.caml-is-busy .caml-tumbleweed--btn,
.btn-danger.caml-is-busy .caml-tumbleweed--btn,
.btn-info.caml-is-busy .caml-tumbleweed--btn,
.btn-warning.caml-is-busy .caml-tumbleweed--btn,
button.caml-is-busy-contrast .caml-tumbleweed--btn {
    width: 22px;
    height: 22px;
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 4px rgba(201, 123, 75, 0.45));
}

.btn-primary.caml-is-busy .caml-btn-busy-label,
.btn-success.caml-is-busy .caml-btn-busy-label,
.btn-danger.caml-is-busy .caml-btn-busy-label,
.btn-info.caml-is-busy .caml-btn-busy-label,
.btn-warning.caml-is-busy .caml-btn-busy-label,
button.caml-is-busy-contrast .caml-btn-busy-label {
    color: #8B5E3C;
    font-weight: 600;
}

/* --- Route navigation desert scene --- */
html.route-shell-active body {
    background:
        radial-gradient(ellipse 120% 70% at 50% -15%, #fffef9 0%, #f8f1de 50%),
        linear-gradient(180deg, #f8f1de 0%, #f3ead4 100%) !important;
}

/* Overlay keeps real page DOM intact so browser Back restores content (bfcache). */
.caml-route-shell-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 15000;
    overflow-y: auto;
    padding: 72px 16px 24px;
    justify-content: center;
    align-items: flex-start;
    background:
        radial-gradient(ellipse 120% 70% at 50% -15%, #fffef9 0%, #f8f1de 50%),
        linear-gradient(180deg, #f8f1de 0%, #f3ead4 100%);
    pointer-events: none;
}

.caml-route-shell-overlay.show {
    display: flex;
    pointer-events: auto;
}

main.route-shell-main {
    background: transparent !important;
    border-radius: 0 !important;
    min-height: min(72vh, 640px);
    box-shadow: none !important;
    padding: 12px 16px 24px !important;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.route-shell-scene {
    position: relative;
    width: 100%;
    max-width: 720px;
    min-height: 320px;
    margin: 8px auto 0;
    padding: 28px 24px 120px;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid rgba(212, 165, 116, 0.45);
    background:
        linear-gradient(180deg, #e8f4fc 0%, #f5ead8 38%, #f0e0c4 62%, #e8d4b0 100%);
    box-shadow: 0 12px 40px rgba(139, 94, 60, 0.12);
    animation: routeShellIn 0.35s ease-out both;
}

@keyframes routeShellIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.route-shell-scene::before {
    content: "";
    position: absolute;
    top: 18px;
    right: 22%;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 220, 140, 0.55) 0%, rgba(255, 200, 100, 0.15) 55%, transparent 70%);
    animation: routeShellSunPulse 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes routeShellSunPulse {
    0%, 100% { opacity: 0.75; transform: scale(1); }
    50%      { opacity: 1; transform: scale(1.06); }
}

.route-shell-header {
    position: relative;
    z-index: 2;
    text-align: center;
    padding-top: 8px;
}

.route-shell-sandstorm {
    display: inline-flex;
    width: 36px;
    height: 24px;
    margin-bottom: 12px;
    position: relative;
}

.route-shell-eyebrow {
    margin: 0 0 6px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #a08060;
}

.route-shell-title {
    margin: 0 0 8px;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    color: #8B5E3C;
    line-height: 1.2;
}

.route-shell-sub {
    margin: 0;
    font-size: 0.9rem;
    color: #6b5c52;
    font-weight: 500;
}

.route-shell-dunes-wrap {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 42%;
    z-index: 1;
    pointer-events: none;
}

.route-shell-dune {
    position: absolute;
    bottom: 0;
    background: linear-gradient(180deg, #e8c89a 0%, #d4a574 100%);
    box-shadow: inset 0 -2px 8px rgba(139, 94, 60, 0.15);
}

.route-shell-dune.dune-back {
    left: -8%;
    width: 55%;
    height: 55%;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    opacity: 0.55;
    animation: routeDuneDrift 2.8s ease-in-out infinite alternate;
}

.route-shell-dune.dune-mid {
    right: -5%;
    width: 62%;
    height: 68%;
    border-radius: 48% 52% 0 0 / 90% 90% 0 0;
    background: linear-gradient(180deg, #f0d4a8 0%, #c97b4b 100%);
    opacity: 0.75;
    animation: routeDuneDrift 2.2s ease-in-out infinite alternate-reverse;
}

.route-shell-dune.dune-front {
    left: 10%;
    width: 80%;
    height: 38%;
    border-radius: 50% 50% 8px 8px / 80% 80% 12px 12px;
    background: linear-gradient(105deg, #ebe3d4 0%, #f5efe3 42%, #e8dfd0 55%, #f0e9dc 100%);
    background-size: 220% 100%;
    animation: camlDuneShimmer 1.4s ease-in-out infinite;
}

@keyframes routeDuneDrift {
    from { transform: translateX(0); }
    to   { transform: translateX(6px); }
}

.route-shell-trail {
    position: absolute;
    bottom: 28%;
    left: 12%;
    right: 12%;
    height: 34px;
    z-index: 2;
    pointer-events: none;
}

/* Faint dust stripe — wind path, not a rigid rail */
.route-shell-trail::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: calc(50% + 3px);
    height: 1px;
    border-radius: 999px;
    opacity: 0.35;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(139, 94, 60, 0.12) 18%,
        rgba(139, 94, 60, 0.18) 50%,
        rgba(139, 94, 60, 0.12) 82%,
        transparent 100%
    );
}

.route-shell-tumble {
    position: absolute;
    left: 0;
    top: 0;
    width: 24px;
    height: 24px;
    /* Irregular hops + spin like wind tumble */
    animation: routeTumbleWind 2.45s cubic-bezier(0.33, 0, 0.2, 1) infinite;
}

@keyframes routeTumbleWind {
    0% {
        left: 0;
        transform: translate3d(0, 0, 0) rotate(0deg);
    }
    /* hop 1 */
    9% {
        transform: translate3d(0, -18px, 0) rotate(165deg);
    }
    19% {
        left: 27%;
        transform: translate3d(0, 0, 0) rotate(380deg);
    }
    22% {
        transform: translate3d(0, 5px, 0) rotate(455deg);
    }
    25% {
        transform: translate3d(0, 0, 0) rotate(500deg);
    }
    /* hop 2 — slightly taller */
    34% {
        transform: translate3d(0, -21px, 0) rotate(695deg);
    }
    45% {
        left: 55%;
        transform: translate3d(0, 0, 0) rotate(920deg);
    }
    47% {
        transform: translate3d(0, 4px, 0) rotate(980deg);
    }
    50% {
        transform: translate3d(0, 0, 0) rotate(1020deg);
    }
    /* hop 3 — shorter gust */
    59% {
        transform: translate3d(0, -14px, 0) rotate(1175deg);
    }
    68% {
        left: 78%;
        transform: translate3d(0, 0, 0) rotate(1320deg);
    }
    71% {
        transform: translate3d(0, 3px, 0) rotate(1375deg);
    }
    /* final skip toward edge */
    80% {
        transform: translate3d(0, -12px, 0) rotate(1510deg);
    }
    90% {
        left: calc(100% - 24px);
        transform: translate3d(0, 0, 0) rotate(1680deg);
    }
    93% {
        transform: translate3d(0, 6px, 0) rotate(1715deg);
    }
    96% {
        transform: translate3d(0, -7px, 0) rotate(1770deg);
    }
    100% {
        left: calc(100% - 24px);
        transform: translate3d(0, 0, 0) rotate(1840deg);
    }
}
/* Legacy card (cached shells) — still themed */
.route-shell-card {
    max-width: 720px;
    margin: 8px auto;
    padding: 24px;
    border-radius: 20px;
    border: 1px solid rgba(212, 165, 116, 0.45);
    background: linear-gradient(180deg, #fffef9 0%, #f8f1de 100%);
    box-shadow: 0 8px 28px rgba(139, 94, 60, 0.1);
    animation: routeShellIn 0.35s ease-out both;
}

.route-shell-card .route-shell-title {
    color: #8B5E3C;
}

/* --- Dune skeleton shimmer (route shell + dashboard) --- */
.caml-dune-shimmer,
.route-shell-dune,
.dash-skel {
    position: relative;
    overflow: hidden;
    background: linear-gradient(105deg, #ebe3d4 0%, #f5efe3 42%, #e8dfd0 55%, #f0e9dc 100%) !important;
    background-size: 220% 100% !important;
    animation: camlDuneShimmer 1.4s ease-in-out infinite !important;
    color: transparent !important;
    border: none !important;
}

/* Skeleton bars inside legacy cached shells */
.route-shell-card .route-shell-dune,
.route-shell-card > .route-shell-dune {
    position: relative;
    height: 44px;
    margin-bottom: 12px;
    border-radius: 50% 50% 12px 12px / 40% 40% 12px 12px;
}

.route-shell-card .route-shell-dune.row-short { width: 40%; }
.route-shell-card .route-shell-dune.row-medium { width: 68%; }
.route-shell-card .route-shell-dune.row-tall { height: 56px; }

.route-shell-horizon {
    height: 3px;
    margin: 4px 0 18px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, rgba(201, 123, 75, 0.25), transparent);
    animation: camlHorizonPulse 2s ease-in-out infinite;
}

@keyframes camlDuneShimmer {
    0%   { background-position: 120% 0; }
    100% { background-position: -120% 0; }
}

@keyframes camlHorizonPulse {
    0%, 100% { opacity: 0.5; }
    50%      { opacity: 1; }
}

/* --- Empty states --- */
.caml-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2.5rem 1.5rem;
    gap: 0.75rem;
    border-radius: var(--radius-lg, 2rem);
    border: 2px dashed var(--desert-sand, #EED6C4);
    background: linear-gradient(180deg, rgba(255, 250, 243, 0.9) 0%, rgba(248, 241, 222, 0.5) 100%);
}

.caml-empty-art {
    width: 88px;
    height: 72px;
    opacity: 0.9;
}

.caml-empty-art svg {
    width: 100%;
    height: 100%;
}

.caml-empty-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--desert-accent-dark, #8B5E3C);
}

.caml-empty-msg {
    margin: 0;
    font-size: 0.9rem;
    color: var(--desert-muted, #6b5c52);
    max-width: 320px;
    line-height: 1.5;
}

.caml-empty-cta {
    margin-top: 0.35rem;
}

/* Cold start: sandstorm around logo */
.caml-cold-logo-stage {
    position: relative;
}

.caml-cold-logo-stage .caml-sandstorm--hero {
    inset: -12px;
}

.caml-cold-logo-ring {
    display: none !important;
}

.caml-cold-logo-glow {
    z-index: 0;
}

.caml-cold-logo-img,
.logo-img {
    position: relative;
    z-index: 1;
}

/*
 * Cold-splash progress only — never use bare .progress / .progress-bar here:
 * those are Bootstrap component classes and appear on real UI (e.g. feedback stat “in progress”).
 */
.caml-cold-progress {
    width: min(220px, 72vw);
    height: 4px;
    border-radius: 999px;
    background: rgba(238, 214, 196, 0.85);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(139, 94, 60, 0.08);
}

.caml-cold-progress > .caml-cold-progress-bar {
    height: 100%;
    width: 38%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--desert-accent-dark, #8B5E3C), var(--desert-accent, #C97B4B), #e8a078);
    animation: camlProgressMove 1.35s ease-in-out infinite;
}

@keyframes camlProgressMove {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(280%); }
}

/* Modal / overlay full loader card */
.caml-overlay-loader {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(34, 28, 22, 0.25);
    padding: 20px;
}

.caml-overlay-loader-card {
    background: var(--desert-card-bg, #fffaf3);
    border: 1px solid var(--desert-sand, #EED6C4);
    border-radius: 16px;
    padding: 28px 32px;
    box-shadow: 0 12px 40px rgba(139, 94, 60, 0.2);
    text-align: center;
    min-width: 200px;
}

.caml-overlay-loader-card strong {
    display: block;
    margin-top: 12px;
    color: var(--desert-accent-dark, #8B5E3C);
}

.caml-loader--tumbleweed {
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.caml-loader--tumbleweed .caml-loader-text {
    font-size: 0.9rem;
    color: var(--desert-muted, #6b5c52);
}

/* Upgrade FA spinners when marked */
i.fa-spinner.caml-sandstorm-replaced {
    display: none !important;
}

.caml-fa-loader-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    vertical-align: middle;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .caml-sandstorm i,
    .caml-caravan-dot,
    .caml-dune-shimmer,
    .route-shell-dune,
    .route-shell-scene,
    .route-shell-scene::before,
    .route-shell-tumble,
    .dash-skel,
    .caml-cold-progress-bar,
    .progress-bar,
    .route-shell-horizon {
        animation: none !important;
    }

    .route-shell-tumble {
        left: 50%;
        transform: translateX(-50%);
    }

    .caml-sandstorm i {
        opacity: 0.6;
    }

    .caml-toggle-slider::before,
    .auto-toggle-slider::before {
        transition: transform 0.15s ease;
    }

    .caml-toggle input:checked + .caml-toggle-slider::before,
    .auto-toggle input:checked + .auto-toggle-slider::before {
        transform: translateX(24px) rotate(180deg);
    }

    .caml-tumbleweed--btn,
    .caml-tumbleweed--overlay {
        animation: none;
    }
}
