/* App Shell, Pure Monochrome Frosted Rail (Desktop), Sliding Micro-Rail Button (Mobile Bottom-Right) & Tab Viewport */

:root {
    /* Desktop Frosted Glass Hairline Rail Tokens (Dark — Luminous Glass over Live Background) */
    --rail-width: clamp(64px, 4.6vw, 76px);
    --rail-bg: rgba(11, 17, 32, 0.62);
    --rail-sheen: rgba(255, 255, 255, 0.06);
    --rail-border: rgba(255, 255, 255, 0.16);
    --rail-ink: #f5f7ff;
    --rail-muted: rgba(244, 246, 255, 0.68);
    --rail-hover: rgba(244, 246, 255, 0.98);
    --rail-accent: #ff7838;
    --rail-accent-glow: rgba(255, 120, 56, 0.48);
    --rail-tip-bg: rgba(12, 16, 28, 0.84);
    --rail-tip-border: rgba(255, 255, 255, 0.15);

    /* Mobile Compact Tab Button Tokens (Top-Right, Dark / Cinema Default) */
    --mobile-nav-size: 44px;
    --mobile-nav-icon: 26px;
    --mobile-nav-top: max(12px, env(safe-area-inset-top));
    --mobile-nav-right: max(14px, env(safe-area-inset-right));

    --mob-btn-bg: rgba(12, 17, 32, 0.84);
    --mob-btn-bg-hover: rgba(18, 26, 46, 0.94);
    --mob-btn-border: rgba(255, 255, 255, 0.28);
    --mob-btn-ink: #f5f7ff;
    --mob-btn-shadow: 0 8px 24px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

html[data-theme="light"] {
    --rail-bg: rgba(255, 255, 255, 0.70);
    --rail-sheen: rgba(255, 255, 255, 0.24);
    --rail-border: rgba(14, 36, 62, 0.15);
    --rail-ink: #0e1e33;
    --rail-muted: rgba(14, 30, 51, 0.64);
    --rail-hover: rgba(14, 30, 51, 0.98);
    --rail-accent: #c81d62;
    --rail-accent-glow: rgba(200, 29, 98, 0.30);
    --rail-tip-bg: rgba(255, 255, 255, 0.90);
    --rail-tip-border: rgba(14, 36, 62, 0.14);

    --mob-btn-bg: rgba(255, 255, 255, 0.92);
    --mob-btn-bg-hover: #ffffff;
    --mob-btn-border: rgba(14, 36, 62, 0.22);
    --mob-btn-ink: #0e1e33;
    --mob-btn-shadow: 0 8px 22px rgba(14, 36, 62, 0.22), inset 0 1px 0 #ffffff;
}

/* Per-Tab Signature Accent Colors (Dark) */
body[data-active-tab="profile"] {
    --rail-accent: #ff7838;
    --rail-accent-glow: rgba(255, 120, 56, 0.44);
}

body[data-active-tab="videos"] {
    --rail-accent: #17cb8d;
    --rail-accent-glow: rgba(23, 203, 141, 0.42);
}

body[data-active-tab="images"] {
    --rail-accent: #4f69f2;
    --rail-accent-glow: rgba(79, 105, 242, 0.44);
}

body[data-active-tab="social"] {
    --rail-accent: #a78bfa;
    --rail-accent-glow: rgba(167, 139, 250, 0.42);
}

/* Per-Tab Signature Accent Colors (Light) */
html[data-theme="light"] body[data-active-tab="profile"] {
    --rail-accent: #c81d62;
    --rail-accent-glow: rgba(200, 29, 98, 0.28);
}

html[data-theme="light"] body[data-active-tab="videos"] {
    --rail-accent: #129e6d;
    --rail-accent-glow: rgba(18, 158, 109, 0.28);
}

html[data-theme="light"] body[data-active-tab="images"] {
    --rail-accent: #435ce6;
    --rail-accent-glow: rgba(67, 92, 230, 0.28);
}

html[data-theme="light"] body[data-active-tab="social"] {
    --rail-accent: #7c3aed;
    --rail-accent-glow: rgba(124, 58, 237, 0.28);
}

.app-wrapper {
    position: relative;
    display: flex;
    flex-direction: row;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* =======================================================
   DESKTOP: TRUE-TRANSPARENT COLOR-ADAPTIVE HAIRLINE RAIL
   (Overlays the live full-bleed background with zero cloudiness)
======================================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--rail-width);
    height: 100%;
    background:
        linear-gradient(180deg, var(--rail-sheen) 0%, transparent 50%, var(--rail-sheen) 100%),
        var(--rail-bg);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border-right: 1px solid var(--rail-border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.14);
    display: flex;
    align-items: center;
    flex-direction: column;
    padding: clamp(18px, 3.2vh, 32px) 0;
    z-index: 60;
    flex-shrink: 0;
    transition: width 0.25s cubic-bezier(0.25, 1, 0.5, 1),
        background-color 0.25s ease,
        border-color 0.25s ease;
}

.sidebar-nav {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 1.8vh, 18px);
    margin: auto 0;
}

/* Sliding Vertical Hairline Needle along the right edge */
.rail-indicator {
    position: absolute;
    top: 0;
    right: -1px;
    width: 3px;
    height: clamp(26px, 3.3vh, 32px);
    border-radius: var(--radius-full);
    background: var(--rail-accent);
    box-shadow: 0 0 12px var(--rail-accent-glow);
    opacity: 0;
    pointer-events: none;
    will-change: transform;
    transition: transform 0.32s var(--ease-out-quart),
        opacity 0.2s ease,
        background-color 0.28s ease,
        box-shadow 0.28s ease;
}

.rail-indicator.is-ready {
    opacity: 1;
}

.rail-indicator.is-instant {
    transition: none;
}

/* Frameless Rail Navigation Buttons */
.tab-btn {
    position: relative;
    width: 100%;
    height: clamp(54px, 6.8vh, 66px);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--rail-muted);
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s var(--ease-out-expo),
        transform 0.2s var(--ease-out-expo);
}

.tab-btn .icon-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(28px, 2.05vw, 32px);
    height: clamp(28px, 2.05vw, 32px);
}

.tab-btn .icon-slot svg {
    width: 100%;
    height: 100%;
    display: block;
    transition: transform 0.28s var(--ease-out-quart),
        color var(--dur-base) ease,
        filter var(--dur-base) ease;
}

.tab-btn:hover {
    color: var(--rail-hover);
}

.tab-btn:hover .icon-slot svg {
    transform: scale(1.07);
}

.tab-btn:active {
    transform: scale(0.92);
}

.tab-btn:focus-visible {
    outline: none;
    color: var(--rail-accent);
}

.tab-btn:focus-visible .icon-slot {
    outline: 1.5px solid var(--rail-accent);
    outline-offset: 6px;
    border-radius: var(--radius-md);
}

.tab-btn::before {
    content: '';
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: transparent;
    border: 1px solid transparent;
    opacity: 0;
    transform: scale(0.86);
    pointer-events: none;
    transition: opacity 0.22s ease,
        transform var(--dur-base) var(--ease-out-quart),
        background-color var(--dur-base) ease,
        border-color var(--dur-base) ease,
        box-shadow var(--dur-base) ease;
}

.tab-btn:hover::before {
    opacity: 1;
    transform: scale(1);
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.10);
}

html[data-theme="light"] .tab-btn:hover::before {
    background: rgba(14, 36, 62, 0.06);
    border-color: rgba(14, 36, 62, 0.09);
}

.tab-btn.active {
    color: var(--rail-accent);
}

.tab-btn.active::before {
    opacity: 1;
    transform: scale(1);
    background: color-mix(in srgb, var(--rail-accent) 18%, transparent);
    border-color: color-mix(in srgb, var(--rail-accent) 38%, transparent);
    box-shadow: 0 4px 18px color-mix(in srgb, var(--rail-accent) 22%, transparent);
}

.tab-btn.active .icon-slot svg {
    color: var(--rail-accent);
    transform: scale(1.06);
    filter: drop-shadow(0 0 10px var(--rail-accent-glow));
}

/* Refined Frosted Glass Micro-Tooltip */
.tooltip {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--rail-tip-bg);
    color: var(--rail-ink);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: 0.01em;
    padding: 0.36rem 0.68rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--rail-tip-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    z-index: 1000;
    transition: opacity 0.18s var(--ease-out-expo),
        transform 0.2s var(--ease-out-expo);
}

.tooltip kbd {
    font-family: 'Inter', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.66rem;
    font-weight: 600;
    opacity: 0.56;
    line-height: 1;
}

.tab-btn:hover .tooltip,
.tab-btn:focus-visible .tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Theme Switcher (Bottom Anchor of Desktop Rail) */
.theme-switcher {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-top: 12px;
}

.theme-switcher::before {
    content: '';
    width: 18px;
    height: 1px;
    background: var(--rail-border);
    margin-bottom: 12px;
}

.theme-switcher .tab-btn {
    height: clamp(46px, 5.6vh, 54px);
}

.theme-switcher .tab-btn .icon-slot {
    width: clamp(24px, 1.75vw, 27px);
    height: clamp(24px, 1.75vw, 27px);
}

.theme-switcher .tab-btn:active .icon-slot svg {
    transform: scale(0.85) rotate(-40deg);
}

/* Main Tab Stage (Always Full-Height Immersive) */
.main-content {
    flex: 1;
    min-width: 0;
    height: 100%;
    position: relative;
    z-index: 10;
    overflow: hidden;
    background: transparent;
}

.tab-content {
    display: none;
    width: 100%;
    height: 100%;
}

.tab-content.active-tab {
    display: block;
    animation: tabFadeIn var(--dur-base) var(--ease-out-expo);
}

.tab-content.media-tab-layout.active-tab {
    display: flex;
}

@keyframes tabFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =======================================================
   COMPACT / MOBILE: TOP-RIGHT COMPACT TAB BUTTON
   (Mobile Portrait/Landscape, Square 1:1 & Portrait Tablet)
======================================================= */
@media (max-width: 960px), (max-aspect-ratio: 6 / 5), (max-height: 520px) {
    :root {
        --rail-width: 0px;
    }

    .app-wrapper {
        flex-direction: column;
    }

    .main-content {
        flex: 1 1 100%;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
    }

    .rail-indicator {
        display: none;
    }

    /* Keep glass button dark-tinted and crisp over dark cinema media tabs even in Light Theme */
    html[data-theme="light"] body[data-active-tab="videos"],
    html[data-theme="light"] body[data-active-tab="images"] {
        --mob-btn-bg: rgba(12, 17, 32, 0.84);
        --mob-btn-bg-hover: rgba(18, 26, 46, 0.94);
        --mob-btn-border: rgba(255, 255, 255, 0.28);
        --mob-btn-ink: #f5f7ff;
        --mob-btn-shadow: 0 8px 24px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    }

    html[data-theme="light"] body[data-active-tab="videos"] {
        --rail-accent: #17cb8d;
        --rail-accent-glow: rgba(23, 203, 141, 0.42);
    }

    html[data-theme="light"] body[data-active-tab="images"] {
        --rail-accent: #4f69f2;
        --rail-accent-glow: rgba(79, 105, 242, 0.44);
    }

    .sidebar {
        position: fixed;
        top: var(--mobile-nav-top);
        right: var(--mobile-nav-right);
        bottom: auto;
        left: auto;
        width: auto;
        height: calc(var(--mobile-nav-size) - 2px);
        flex-direction: row;
        align-items: center;
        gap: 0;
        border-radius: var(--radius-full);
        padding: 0 6px 0 5px;
        background: color-mix(in srgb, var(--mob-btn-bg) 88%, rgba(255, 255, 255, 0.06));
        border: 1.25px solid color-mix(in srgb, var(--rail-accent) 44%, var(--mob-btn-border));
        box-shadow:
            0 6px 20px rgba(0, 0, 0, 0.36),
            0 0 16px color-mix(in srgb, var(--rail-accent-glow) 34%, transparent),
            inset 0 1px 0 rgba(255, 255, 255, 0.20);
        backdrop-filter: blur(18px) saturate(165%);
        -webkit-backdrop-filter: blur(18px) saturate(165%);
        z-index: 120;
        pointer-events: auto;
        overflow: hidden;
        isolation: isolate;
        transition: background-color 0.22s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    }

    html[data-theme="light"] body[data-active-tab="profile"] .sidebar,
    html[data-theme="light"] body[data-active-tab="social"] .sidebar {
        background: rgba(255, 255, 255, 0.90);
        border-color: color-mix(in srgb, var(--rail-accent) 32%, rgba(14, 36, 62, 0.16));
        box-shadow:
            0 6px 18px rgba(14, 36, 62, 0.14),
            0 0 14px color-mix(in srgb, var(--rail-accent-glow) 24%, transparent),
            inset 0 1px 0 #ffffff;
    }

    .sidebar-nav {
        position: relative;
        flex-direction: row;
        width: auto;
        height: 100%;
        border-radius: 0;
        margin: 0;
        gap: 0;
    }

    .theme-switcher {
        width: auto;
        height: 100%;
        padding-top: 0;
        flex-direction: row;
        align-items: center;
    }

    .theme-switcher::before,
    .theme-switcher::after {
        display: none;
    }

    .sidebar .tab-btn:focus-visible .icon-slot {
        outline: none;
    }

    .theme-switcher .tab-btn {
        pointer-events: auto;
        width: calc(var(--mobile-nav-size) - 16px);
        height: calc(var(--mobile-nav-size) - 6px);
        border-radius: var(--radius-full);
        padding: 0;
        background: transparent;
        border: 0;
        box-shadow: none;
        color: var(--mob-btn-ink);
        opacity: 0.78;
        transition: color 0.18s ease,
            opacity 0.18s ease,
            transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .theme-switcher .tab-btn::before {
        display: none;
    }

    .theme-switcher .tab-btn .icon-slot {
        width: calc(var(--mobile-nav-icon) - 9px);
        height: calc(var(--mobile-nav-icon) - 9px);
    }

    .theme-switcher .tab-btn .icon-slot svg {
        filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.28));
    }

    html[data-theme="light"] .theme-switcher .tab-btn .icon-slot svg {
        filter: none;
    }

    .theme-switcher .tab-btn:hover {
        background: transparent;
        color: #ffffff;
        opacity: 1;
    }

    html[data-theme="light"] body[data-active-tab="profile"] .theme-switcher .tab-btn:hover,
    html[data-theme="light"] body[data-active-tab="social"] .theme-switcher .tab-btn:hover {
        background: transparent;
        color: var(--rail-accent);
    }

    .theme-switcher .tab-btn:active {
        transform: scale(0.86);
    }

    .sidebar-nav .tab-btn:not(.active) {
        display: none;
    }

    .sidebar-nav .tab-btn.active {
        pointer-events: auto;
        width: calc(var(--mobile-nav-size) - 10px);
        height: calc(var(--mobile-nav-size) - 6px);
        border-radius: var(--radius-full);
        padding: 0;
        background: transparent;
        border: 0;
        box-shadow: none;
        color: var(--rail-accent);
        transition: color 0.22s ease,
            transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .sidebar-nav .tab-btn.active::before {
        display: none;
    }

    .sidebar-nav .tab-btn.active .icon-slot {
        width: calc(var(--mobile-nav-icon) + 1px);
        height: calc(var(--mobile-nav-icon) + 1px);
    }

    .sidebar-nav .tab-btn.active .icon-slot svg {
        color: var(--rail-accent);
        transform: none;
        filter: drop-shadow(0 0 8px var(--rail-accent-glow));
    }

    .sidebar-nav .tab-btn.active:hover {
        background: transparent;
    }

    .sidebar-nav .tab-btn.active:active {
        transform: scale(0.86);
    }

    .tab-btn .tooltip {
        display: none;
    }
}

/* Tier A: Small Phone (<= 380px width) — compact balanced touch target */
@media (max-width: 380px) {
    :root {
        --mobile-nav-size: 40px;
        --mobile-nav-icon: 23px;
        --mobile-nav-top: max(11px, env(safe-area-inset-top));
        --mobile-nav-right: max(12px, env(safe-area-inset-right));
    }
}

/* Tier B: Portrait Tablet (iPad 680px..960px) & Larger Square Compact Viewports */
@media (min-width: 680px) and (max-width: 960px) and (orientation: portrait),
       (min-width: 680px) and (max-aspect-ratio: 6 / 5) and (min-height: 521px) {
    :root {
        --mobile-nav-size: 50px;
        --mobile-nav-icon: 29px;
        --mobile-nav-top: max(14px, env(safe-area-inset-top));
        --mobile-nav-right: max(16px, env(safe-area-inset-right));
    }
}

/* Tier C: Short Landscape Phone — compact corner anchor */
@media (max-height: 520px) and (orientation: landscape) {
    :root {
        --mobile-nav-size: 38px;
        --mobile-nav-icon: 22px;
        --mobile-nav-top: max(8px, env(safe-area-inset-top));
        --mobile-nav-right: max(12px, env(safe-area-inset-right));
    }
}

/* Reduced Motion Respect */
@media (prefers-reduced-motion: reduce) {
    .rail-indicator,
    .tab-btn,
    .tooltip {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
