:root {
    --bg-color: #0f0f13;
    --sidebar-bg: #16161a;
    --card-bg: #1e1e24;
    --accent-color: #5865F2;
    --text-color: #fffffe;
    --text-muted: #94a1b2;
    --success: #2cb67d;
    --danger: #ef4565;
    --border-radius: 12px;
    --font-main: 'Inter', 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-heading: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Fix for mobile browser bottom bar */
    height: -webkit-fill-available;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    /* iOS Safari fix */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

h1 {
    font-size: 2.25rem;
}

h2 {
    font-size: 1.75rem;
}

h3 {
    font-size: 1.375rem;
}

h4 {
    font-size: 1.125rem;
}

p {
    line-height: 1.6;
    font-weight: 400;
}

code,
pre,
.mono {
    font-family: var(--font-mono);
}

code {
    background: rgba(88, 101, 242, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.875em;
}

pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
}

a {
    text-decoration: none;
    color: inherit;
    transition: 0.2s;
}

ul {
    list-style: none;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 30px;
    color: var(--accent-color);
}

.sidebar .brand img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* Mobile close button */
.sidebar-close {
    display: none;
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
}

.nav-links {
    flex: 1;
    overflow-y: auto;
    direction: rtl;
    padding-left: 3px;
}

.nav-links::-webkit-scrollbar {
    width: 3px;
}

.nav-links::-webkit-scrollbar-track {
    background: transparent;
}

.nav-links::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    transition: background 0.3s;
}

.nav-links:hover::-webkit-scrollbar-thumb {
    background: rgba(88, 101, 242, 0.5);
}

.nav-links::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

.nav-links li {
    margin-bottom: 5px;
    direction: ltr;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: var(--border-radius);
    color: var(--text-muted);
    font-weight: 500;
}

.nav-links a:hover,
.nav-links a.active {
    background: rgba(88, 101, 242, 0.1);
    color: var(--accent-color);
}

.nav-links .section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 20px 0 10px 10px;
    letter-spacing: 1px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info .username {
    font-size: 0.9rem;
    font-weight: 600;
}

.logout-btn {
    font-size: 0.8rem;
    color: var(--danger);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 30px;
    max-width: 100%;
    overflow-y: auto;
}

.content-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 1em;
}

/* Glassmorphism Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.card h2 {
    margin-bottom: 20px;
    font-size: 1.2rem;
}

/* Server Card Hover Effects */
a.card {
    display: block;
    text-decoration: none;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        box-shadow 0.3s ease,
        border-color 0.3s ease !important;
    position: relative !important;
    overflow: hidden !important;
    cursor: pointer !important;
}

a.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg,
            rgba(88, 101, 242, 0) 0%,
            rgba(88, 101, 242, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    border-radius: inherit;
    z-index: 1;
}

a.card:hover,
a.card:focus {
    transform: translateY(-8px) scale(1.02) !important;
    box-shadow:
        0 12px 40px rgba(88, 101, 242, 0.35),
        0 4px 20px rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(88, 101, 242, 0.5) !important;
}

a.card:hover::before {
    opacity: 1;
}

a.card:active {
    transform: translateY(-4px) scale(1.01) !important;
    transition-duration: 0.1s;
}

/* Server icon glow effect */
a.card img {
    transition: transform 0.3s ease, box-shadow 0.3s ease !important;
}

a.card:hover img {
    box-shadow: 0 0 25px rgba(88, 101, 242, 0.6) !important;
    transform: scale(1.1) !important;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

/* Elements */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    background: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
}

.btn:hover {
    filter: brightness(1.1);
}

.btn-danger {
    background: var(--danger);
}

/* Form Elements */
input[type="text"],
input[type="number"],
input[type="color"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    margin-bottom: 10px;
    font-family: inherit;
    font-size: 1rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--accent-color);
    border-color: transparent;
}

/* Fix for color picker */
input[type="color"] {
    height: 42px;
    padding: 4px;
    cursor: pointer;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
}

/* Mobile Header */
.mobile-header {
    display: none;
}

.mediaplayer-responsive {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ============ MOBILE STYLES ============ */
@media (max-width: 768px) {

    /* Sidebar Mobile */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        width: 85%;
        max-width: 300px;
        height: 100vh;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Main Content Mobile */
    .main-content {
        padding: 15px;
        padding-top: 70px;
        /* Extra padding for browser bottom bar */
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0));
    }

    /* Mobile Header */
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: var(--sidebar-bg);
        padding: 15px 20px;
        z-index: 50;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .mobile-header button {
        background: rgba(255, 255, 255, 0.1);
        border: none;
        color: white;
        padding: 10px 15px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 1.2rem;
    }

    .mobile-header span {
        font-weight: 700;
        font-size: 1.2rem;
        color: var(--accent-color);
    }

    /* Cards Mobile */
    .card {
        padding: 15px;
    }

    /* Grids Mobile - Stack single column */
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    /* Button Mobile */
    .btn {
        padding: 12px 16px;
        width: 100%;
    }

    /* Form rows stack on mobile */
    .form-row {
        flex-direction: column;
    }

    .form-row>* {
        width: 100% !important;
    }

    /* Flexbox controls stack */
    form[style*="display: flex"] {
        flex-wrap: wrap;
    }

    /* Input full width */
    input[type="text"],
    input[type="number"],
    select,
    textarea {
        min-width: 100% !important;
    }

    /* Controls buttons */
    .card div[style*="display: flex"][style*="gap"] {
        flex-wrap: wrap;
    }

    .card div[style*="display: flex"][style*="gap"]>form {
        flex: 1;
        min-width: 45%;
    }

    .card div[style*="display: flex"][style*="gap"]>form .btn {
        width: 100%;
    }

    .mediaplayer-responsive {
        display: flex;
        flex-direction: column;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .main-content {
        padding: 20px;
    }
}

@media (min-width: 769px) {
    .mobile-header {
        display: none;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar Global */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    transition: background 0.2s;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Discord Embed Style */
.discord-embed {
    background: #2f3136;
    border-radius: 4px;
    padding: 16px;
    position: relative;
    max-width: 520px;
    font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.discord-embed-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.discord-embed-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.discord-embed-author {
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
}

.discord-embed-thumbnail {
    position: absolute;
    right: 16px;
    top: 16px;
}

.discord-embed-thumbnail img {
    width: 80px;
    height: 80px;
    border-radius: 8px;
}

.discord-embed-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-right: 100px;
}

.discord-embed-field {
    flex: 1 0 100%;
}

.discord-embed-field.inline {
    flex: 1 0 30%;
    min-width: 100px;
}

.discord-embed-field .field-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: #b9bbbe;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.discord-embed-field .field-value {
    font-size: 0.9rem;
    color: #dcddde;
    word-break: break-word;
}

.discord-embed-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 0.75rem;
    color: #72767d;
}

/* Responsive adjustments for embed */
@media (max-width: 768px) {
    .discord-embed-thumbnail {
        position: static;
        margin-bottom: 12px;
    }

    .discord-embed-thumbnail img {
        width: 60px;
        height: 60px;
    }

    .discord-embed-fields {
        margin-right: 0;
    }

    .discord-embed-field.inline {
        flex: 1 0 45%;
    }
}

/* Rank Card Customization Layout */
.rank-card-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .rank-card-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .rank-card-layout .discord-embed {
        max-width: 100%;
    }
}

/* ============ AJAX NAVIGATION TRANSITIONS ============ */

/* Content swap animations — only applied by JS during AJAX nav */
.content-exit {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

.content-enter {
    animation: contentFadeIn 0.3s ease forwards;
}

@keyframes contentFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Skeleton Loading */
.ajax-skeleton {
    padding: 20px 0;
}

.skeleton-bar {
    background: linear-gradient(90deg,
            rgba(255, 255, 255, 0.04) 25%,
            rgba(255, 255, 255, 0.08) 50%,
            rgba(255, 255, 255, 0.04) 75%);
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: 8px;
    margin-bottom: 16px;
}

.skeleton-title {
    height: 32px;
    width: 40%;
}

.skeleton-text {
    height: 18px;
    width: 70%;
}

.skeleton-text.short {
    width: 45%;
}

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 30px;
}

.skeleton-card {
    height: 160px;
    background: linear-gradient(90deg,
            rgba(255, 255, 255, 0.04) 25%,
            rgba(255, 255, 255, 0.08) 50%,
            rgba(255, 255, 255, 0.04) 75%);
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: var(--border-radius);
}

@keyframes skeletonPulse {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@media (max-width: 768px) {
    .skeleton-grid {
        grid-template-columns: 1fr;
    }
}

/* ============ LAZY LOADING ============ */

.lazy-hidden {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.lazy-loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Pagination sentinel (invisible) */
.pagination-sentinel {
    height: 1px;
    width: 100%;
}

/* ============ TOAST NOTIFICATIONS ============ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(100%) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: 360px;
}

.toast-show {
    opacity: 1;
    transform: translateX(0) scale(1);
}

.toast-hide {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-success i {
    color: var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-error i {
    color: var(--danger);
}

.toast-info {
    border-left: 4px solid var(--accent-color);
}

.toast-info i {
    color: var(--accent-color);
}

@media (max-width: 768px) {
    .toast-container {
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }

    .toast {
        max-width: 100%;
    }
}