/* ==========================================================================
   GPL MODS UNIFIED APP SHELL, MOBILE FIXES, CUSTOM DROPDOWNS & IMAGE SHIELD
   ========================================================================== */
:root {
    --gpl-bg: #0a0a0a;
    --gpl-surface: #121520;
    --gpl-surface-2: #181c2c;
    --gpl-border: rgba(255, 255, 255, 0.09);
    --gpl-border-strong: #272d42;
    --gpl-text: #f5f7ff;
    --gpl-muted: #a6aec4;
    --gpl-gold: #FFD700;
    --gpl-gold-2: #f4b400;
    --gpl-cyan: #00e5ff;
    --gpl-green: #4caf50;
    --gpl-red: #ef5350;
    --gpl-sidebar-w: 256px;
}

/* Browser Surface Overrides + Strict Horizontal Overflow Prevention */
html {
    color-scheme: dark;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 215, 0, 0.35) #0d0f17;
    max-width: 100%;
    overflow-x: clip;
}

body {
    max-width: 100%;
    overflow-x: clip;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0d0f17;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 215, 0, 0.3);
    border-radius: 999px;
    border: 2px solid #0d0f17;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 215, 0, 0.55);
}

::selection {
    background: rgba(255, 215, 0, 0.28);
    color: #ffffff;
}

input, textarea, select {
    caret-color: var(--gpl-gold);
}

:focus-visible {
    outline: 2px solid var(--gpl-gold);
    outline-offset: 2px;
}

/* ==========================================================================
   SITE-WIDE IMAGE DOWNLOAD & LONG-PRESS PREVENTION
   ========================================================================== */
img,
.cat-card-icon,
.subcat-pill img,
.item-icon,
.tool-icon,
.ipa-choice img,
.wave-logo,
.logo-img {
    -webkit-touch-callout: none !important;
    -webkit-user-drag: none !important;
    -khtml-user-drag: none !important;
    -moz-user-drag: none !important;
    -o-user-drag: none !important;
    user-drag: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    pointer-events: none !important;
}

.cat-card,
.subcat-pill,
.item-icon-wrapper,
.logo-wrapper,
.tool-icon-wrap,
.ipa-choice,
.wave-logo-item {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

/* ==========================================================================
   APP SHELL LAYOUT WRAPPER & DESKTOP SIDEBAR WITH HAMBURGER TOGGLE
   ========================================================================== */
body.has-app-shell {
    padding-left: var(--gpl-sidebar-w) !important;
    padding-bottom: 56px !important;
    align-items: stretch !important;
    transition: padding-left 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

body.has-app-shell.sidebar-collapsed {
    padding-left: 0 !important;
}

body.has-app-shell .app-main-wrap {
    width: 100%;
    max-width: 980px;
    min-width: 0;
    margin: 0 auto;
    padding: 0 20px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    overflow-x: clip;
}

/* Prevent wide grids/titles/selects from pushing mobile width out */
body.has-app-shell .app-main-wrap > *,
body.has-app-shell .container,
body.has-app-shell .card,
body.has-app-shell .panel,
body.has-app-shell header,
body.has-app-shell .top-nav-bar,
body.has-app-shell .form-grid,
body.has-app-shell .form-grid > *,
body.has-app-shell .field,
body.has-app-shell .mode-switch,
body.has-app-shell .input,
body.has-app-shell textarea,
body.has-app-shell select {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

body.has-app-shell .card-title,
body.has-app-shell .panel h2,
body.has-app-shell .panel h3,
body.has-app-shell .section-heading-left,
body.has-app-shell .cert-header-left span,
body.has-app-shell code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Fixed Desktop Sidebar */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--gpl-sidebar-w);
    background: linear-gradient(180deg, #10131e 0%, #0b0d14 100%);
    border-right: 1px solid var(--gpl-border);
    display: flex;
    flex-direction: column;
    z-index: 120;
    padding: 18px 14px;
    overflow-y: auto;
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

body.has-app-shell.sidebar-collapsed .app-sidebar {
    transform: translateX(-100%);
}

/* Desktop Floating Hamburger Button (visible when sidebar collapsed on PC) */
.app-desktop-menu-btn {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 118;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(16, 19, 30, 0.92);
    border: 1px solid rgba(255, 215, 0, 0.36);
    color: var(--gpl-gold);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 1.05rem;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.app-desktop-menu-btn:hover {
    transform: translateY(-1px);
    border-color: var(--gpl-gold);
    box-shadow: 0 8px 26px rgba(255, 215, 0, 0.22);
}

@media (min-width: 921px) {
    body.has-app-shell.sidebar-collapsed .app-desktop-menu-btn {
        display: inline-flex;
    }
}

.app-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 6px 14px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--gpl-border);
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
}

.app-sidebar-brand img {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1.5px solid var(--gpl-gold);
    object-fit: cover;
    flex-shrink: 0;
}

.app-sidebar-brand-text strong {
    display: block;
    font-family: 'Outfit', sans-serif;
    font-size: 0.98rem;
    font-weight: 800;
    color: var(--gpl-text);
    line-height: 1.15;
}

.app-sidebar-brand-text span {
    display: block;
    font-size: 0.7rem;
    color: var(--gpl-gold);
    font-weight: 600;
}

.app-sidebar-toggle-btn {
    appearance: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--gpl-border);
    color: var(--gpl-muted);
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

.app-sidebar-toggle-btn:hover {
    color: var(--gpl-gold);
    border-color: rgba(255, 215, 0, 0.45);
    background: rgba(255, 215, 0, 0.08);
}

.app-nav-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #7d86a0;
    padding: 10px 10px 6px;
}

.app-nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--gpl-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.app-nav-link i {
    width: 18px;
    text-align: center;
    font-size: 0.95em;
}

.app-nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gpl-text);
}

.app-nav-link.active {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.16) 0%, rgba(255, 215, 0, 0.06) 100%);
    color: var(--gpl-gold);
    border-color: rgba(255, 215, 0, 0.36);
}

.app-sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--gpl-border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-sidebar-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--gpl-border);
    color: var(--gpl-muted);
    font-size: 0.76rem;
    text-decoration: none;
}

.app-sidebar-pill:hover {
    border-color: rgba(0, 229, 255, 0.4);
    color: var(--gpl-cyan);
}

/* Mobile Top Header & Drawer Backdrop */
.app-mobile-bar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 110;
    width: 100%;
    padding: 10px 14px;
    background: rgba(12, 14, 22, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gpl-border);
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    box-sizing: border-box;
}

.app-mobile-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    color: var(--gpl-text);
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 0.96rem;
}

.app-mobile-brand img {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--gpl-gold);
}

.app-menu-btn {
    appearance: none;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--gpl-border);
    color: var(--gpl-text);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
}

.app-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 115;
}

.app-sidebar-backdrop.open {
    display: block;
}

/* Mobile Bottom Tab Bar */
.app-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 110;
    background: rgba(12, 14, 22, 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--gpl-border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
}

.app-bottom-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 4px;
    border-radius: 10px;
    color: var(--gpl-muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
}

.app-bottom-item i {
    font-size: 1.05rem;
}

.app-bottom-item.active {
    color: var(--gpl-gold);
    background: rgba(255, 215, 0, 0.1);
}

/* ==========================================================================
   MOBILE RESPONSIVE ALIGNMENT FIXES (<= 920px & <= 640px)
   ========================================================================== */
@media (max-width: 920px) {
    body.has-app-shell {
        padding-left: 0 !important;
        padding-bottom: 84px !important;
    }
    body.has-app-shell .app-main-wrap {
        padding: 0 12px 28px;
    }
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-mobile-bar {
        display: flex;
    }
    .app-bottom-nav {
        display: flex;
    }
}

@media (max-width: 640px) {
    body.has-app-shell .app-main-wrap {
        padding: 0 8px 26px;
    }
    body.has-app-shell .container {
        padding: 0 4px !important;
        width: 100% !important;
    }
    body.has-app-shell .top-nav-bar {
        padding: 10px 4px !important;
        width: 100% !important;
    }
    body.has-app-shell header {
        width: 100% !important;
        padding: 20px 14px !important;
        margin: 6px auto 16px !important;
        border-radius: 18px !important;
    }
    body.has-app-shell .card,
    body.has-app-shell .panel {
        padding: 15px 13px !important;
        border-radius: 16px !important;
        width: 100% !important;
    }
    body.has-app-shell .mode-switch {
        grid-template-columns: 1fr !important;
    }
    body.has-app-shell .input-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    body.has-app-shell .input-row > * {
        width: 100% !important;
    }
    .gpl-file-picker {
        padding: 10px 11px;
        gap: 9px;
    }
    .gpl-file-badge {
        padding: 4px 8px;
        font-size: 0.68rem;
    }
}

/* ==========================================================================
   CUSTOM NON-NATIVE DROPDOWN UI (REPLACES BROWSER STATIC <SELECT> POPUPS)
   ========================================================================== */
select.gpl-select-native-hidden {
    position: absolute !important;
    opacity: 0 !important;
    width: 1px !important;
    height: 1px !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

.gpl-dropdown {
    position: relative;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    font-family: inherit;
}

.gpl-dropdown-trigger {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 13px;
    border-radius: 12px;
    background: #0b0e18;
    border: 1px solid var(--gpl-border-strong);
    color: var(--gpl-text);
    font-size: 0.84rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
    box-sizing: border-box;
    font-family: inherit;
}

.gpl-dropdown-trigger:hover {
    border-color: rgba(255, 215, 0, 0.45);
}

.gpl-dropdown.open .gpl-dropdown-trigger {
    border-color: var(--gpl-gold);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.14);
}

.gpl-dropdown-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gpl-dropdown-chevron {
    color: var(--gpl-gold);
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.gpl-dropdown.open .gpl-dropdown-chevron {
    transform: rotate(180deg);
}

.gpl-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 450;
    background: #101422;
    border: 1px solid rgba(255, 215, 0, 0.35);
    border-radius: 14px;
    padding: 6px;
    max-height: 270px;
    overflow-y: auto;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.85), 0 0 24px rgba(255, 215, 0, 0.1);
    display: none;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.gpl-dropdown.open .gpl-dropdown-menu {
    display: block;
    animation: gplDropFade 0.14s ease-out;
}

@keyframes gplDropFade {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.gpl-dropdown-search-wrap {
    padding: 4px 4px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    margin-bottom: 5px;
    position: sticky;
    top: -6px;
    background: #101422;
    z-index: 2;
}

.gpl-dropdown-search {
    width: 100%;
    padding: 7px 10px;
    border-radius: 9px;
    background: #080b13;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--gpl-text);
    font-size: 0.78rem;
    outline: none;
    box-sizing: border-box;
    font-family: inherit;
}

.gpl-dropdown-search:focus {
    border-color: var(--gpl-gold);
}

.gpl-dropdown-option {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--gpl-text);
    font-size: 0.81rem;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.14s ease, color 0.14s ease;
    font-family: inherit;
    line-height: 1.35;
}

.gpl-dropdown-option span {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.gpl-dropdown-option:hover {
    background: rgba(255, 255, 255, 0.06);
}

.gpl-dropdown-option.selected {
    background: rgba(255, 215, 0, 0.16);
    color: var(--gpl-gold);
    font-weight: 600;
}

.gpl-dropdown-option .gpl-opt-check {
    font-size: 0.75rem;
    color: var(--gpl-gold);
    flex-shrink: 0;
}

/* Custom iOS-style Toggle Switch for Checkboxes */
.gpl-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.83rem;
    color: var(--gpl-text);
    max-width: 100%;
}

.gpl-switch input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: #23293d;
    border: 1px solid rgba(255, 255, 255, 0.12);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.gpl-switch input[type="checkbox"]::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #d3d9ec;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s ease;
}

.gpl-switch input[type="checkbox"]:checked {
    background: linear-gradient(135deg, #FFD700 0%, #f4b400 100%);
    border-color: #FFD700;
}

.gpl-switch input[type="checkbox"]:checked::after {
    transform: translateX(18px);
    background: #0a0a0a;
}

/* Custom File Picker Card */
.gpl-file-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 13px;
    background: #0b0e18;
    border: 1px dashed rgba(255, 215, 0, 0.35);
    cursor: pointer;
    transition: border-color 0.18s ease, background-color 0.18s ease;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.gpl-file-picker:hover {
    border-color: var(--gpl-gold);
    background: rgba(255, 215, 0, 0.05);
}

.gpl-file-picker.has-file {
    border-style: solid;
    border-color: rgba(76, 175, 80, 0.55);
    background: rgba(76, 175, 80, 0.06);
}

.gpl-file-picker input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.gpl-file-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255, 215, 0, 0.12);
    color: var(--gpl-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.gpl-file-picker.has-file .gpl-file-icon {
    background: rgba(76, 175, 80, 0.18);
    color: #81c784;
}

.gpl-file-text {
    min-width: 0;
    flex: 1;
}

.gpl-file-text strong {
    display: block;
    font-size: 0.82rem;
    color: var(--gpl-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gpl-file-text small {
    display: block;
    font-size: 0.72rem;
    color: var(--gpl-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gpl-file-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--gpl-text);
    flex-shrink: 0;
}
