/* JustU Core Layout - Critical Styles to prevent FOUC */

/* Authentication Visibility States */
.auth-only,
.guest-only {
    display: none !important;
}

.is-logged-in .auth-only {
    display: block !important;
}

.is-logged-in .auth-only.flex {
    display: flex !important;
}

.is-guest .guest-only {
    display: block !important;
}

.is-guest .guest-only.flex {
    display: flex !important;
}

/* Page Specific Visibility */
.home-only {
    display: none !important;
}

.is-index .home-only {
    display: flex !important;
}

.is-index .home-only.inline-flex {
    display: inline-flex !important;
}

.subpage-only {
    display: none !important;
}

html:not(.is-index) .subpage-only {
    display: block !important;
}

:root {
    --primary: #b8111d;
    --primary-container: #dc3133;
}

body.is-app .is-app-hidden {
    display: none !important;
}

html.is-app.page-login nav,
html.is-app.page-signup nav {
    display: none !important;
}

/* Standardize App Padding for all pages */
body.is-app main {
    padding-bottom: 2rem !important;
    min-height: auto !important;
}

/* Extra bottom padding only when bottom nav is visible */
html.has-bottom-nav body.is-app main {
    padding-bottom: 5rem !important;
    /* ~112px clearance */
}

/* Bottom Nav Visibility Control */
#bottom-nav {
    display: none !important;
}

html.has-bottom-nav #bottom-nav {
    display: flex !important;
}

/* Fix h-screen issues when inside a master page */
.min-h-screen {
    min-height: 100vh;
}

@media (min-width: 1024px) {

    /* Adjust for Desktop Master Header (h-20 = 80px) */
    body:not(.is-app) .min-h-screen {
        min-height: calc(100vh - 5rem);
    }
}

/* Dark Theme Stability */
html.dark,
html.dark body {
    background-color: #0c0a09 !important;
    /* stone-950 */
    color: #f9f9f9;
}

html {
    transition: background-color 0.3s ease;
}

/* App Mode Navigation Icons */
body.is-app #mbBack {
    display: flex !important;
}

body.is-app.is-index #mbBack {
    display: none !important;
}


/* Sidebar Trigger: Only visible on Home Page in App Mode */
body.is-app #open-sidebar {
    display: none !important;
}

body.is-app.is-index #open-sidebar {
    display: flex !important;
}

/* Secondary triggers are removed */
#open-sidebar-right {
    display: none !important;
}

/* Desktop Master context (only if back button added) */
header #mbBack {
    display: none;
}

header.has-back #mbBack {
    display: flex;
}

/* Hide wrappers until injected */
#header-wrapper:empty,
#sidebar-wrapper:empty,
#nav-wrapper:empty {
    display: none;
}

/* Sidebar critical styles (pre-tailwind) */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    pointer-events: none;
    visibility: hidden;
    /* Prevent flicker before JS injection */
}

#sidebar.active {
    visibility: visible;
    pointer-events: auto;
}

#sidebar-content {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 80%;
    max-width: 320px;
    background: white;
    transform: translateX(-100%);
    transition: transform 0.3s ease-out;
}

.dark #sidebar-content {
    background: #0c0a09;
    /* stone-950 */
}

#sidebar.active #sidebar-content {
    transform: translateX(0);
}

#sidebar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
}

#sidebar.active #sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* Material Symbols fix */
.material-symbols-outlined {
    font-display: block;
    width: auto;
    height: auto;
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24 !important;
    font-weight: 400 !important;
}

/* Tap highlight */
body {
    -webkit-tap-highlight-color: transparent;
}

/* Global Scrollbar Hide for Native App Feel */
* {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

*::-webkit-scrollbar {
    display: none !important;
}

/* SVG Logo Control via Reference */
.justu-logo {
    transition: filter 0.3s ease;
}

/* In Dark Mode, we invert the logo colors.
   Magic Filter: 
   1. invert(1) makes Black -> White and Red -> Cyan.
   2. hue-rotate(180deg) makes Cyan -> Red again.
   Result: White text + Red 'u'. */
.dark .justu-logo {
    /* Magic Filter for Deep Red U + White Text:
       1. invert(1) Inverts colors
       2. hue-rotate(180deg) brings Cyan back to Red
       3. saturate(2.5) makes the red more vivid (less pink)
       4. contrast(1.2) makes it sharper */
    filter: invert(1) hue-rotate(180deg) saturate(2.5) contrast(1.2);
}

/* Button & Link Global Interactions */
button,
a,
.clickable {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

button:hover,
a:hover {
    opacity: 0.9;
}

button:active,
a:active {
    transform: scale(0.96);
    opacity: 0.8;
}

/* Primary Button Premium Effect */
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-container) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(184, 17, 29, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(184, 17, 29, 0.3);
    transform: translateY(-1px);
    opacity: 1;
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: scale(0.95) translateY(0);
    box-shadow: 0 2px 8px rgba(184, 17, 29, 0.2);
}

/* Icon Button Hover */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    padding: 8px;
    color: inherit;
}

.icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.dark .icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Disable logo link in App Mode */
/* Global Form Element Styles */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="password"],
textarea,
select {
    border: 1.5px solid #d6d3d1 !important;
    /* stone-300 */
    transition: all 0.2s ease;
}

.dark input[type="text"],
.dark input[type="number"],
.dark input[type="email"],
.dark input[type="tel"],
.dark input[type="password"],
.dark textarea,
.dark select {
    border-color: #44403c !important;
    /* stone-700 */
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary) !important;
    outline: none;
    box-shadow: 0 0 0 3px rgba(184, 17, 29, 0.1);
}

body.is-app .logo-link-app-disable {
    pointer-events: none;
    cursor: default;
}

/* Loading Spinner Standardizer */
.loading-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    width: 24px;
    height: 24px;
}

.loading-spinner.hidden {
    display: none !important;
}

.loading-spinner .material-symbols-outlined {
    font-size: 24px !important;
    width: 24px !important;
    height: 24px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1 !important;
    /* Force center rotation */
    transform-origin: center center !important;
}

/* Ensure smooth spinning */
@keyframes spin-smooth {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.animate-spin-smooth {
    animation: spin-smooth 0.8s linear infinite;
}