/* ========================================
   FIX-SYSTEM LAYOUT CSS v2.0
   ======================================== */

/* CSS VARIABLES */
:root {
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 70px;
    --topbar-height: 55px;
    --mobile-nav-height: 62px;
    --sidebar-bg: #b4bcc2;
    --topbar-bg: #ffc107;
    --border: #dee2e6;
    --content-bg: rgba(0, 0, 0, 0.05);
}

/* ========================================
   RADZEN LAYOUT OVERRIDES (CRITICAL!)
   ======================================== */
.rz-layout {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    overflow: hidden !important;
}

.rz-header {
    flex-shrink: 0 !important;
    z-index: 1000;
}

.rz-body {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    min-height: 0 !important; /* Ważne dla flex overflow */
}

/* ========================================
   LAYOUT ROOT - główny kontener flex
   ======================================== */
.layout-root {
    display: flex !important;
    flex: 1 1 auto !important;
    width: 100% !important;
    min-height: 0 !important; /* Ważne dla flex overflow */
    overflow: hidden !important;
    background: var(--content-bg);
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex-shrink: 0 !important;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease, min-width 0.25s ease, transform 0.25s ease;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar.closed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

.sidebar.open {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
}

/* ========================================
   MAIN AREA
   ======================================== */
.main-area {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important; /* Ważne dla flex overflow */
    overflow: hidden !important;
}

/* ========================================
   CONTENT AREA
   ======================================== */
.content-area {
    flex: 1 1 auto !important;
    padding: 1.5rem;
    overflow-y: auto !important;
    overflow-x: hidden;
    min-height: 0 !important; /* Ważne dla flex overflow */
}

/* ========================================
   TOPBAR (wewnętrzny, w main-area)
   ======================================== */
.topbar,
.topbar-ultra {
    height: var(--topbar-height);
    flex-shrink: 0 !important;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
}

/* ========================================
   HEADER (Radzen fs-header)
   ======================================== */
.fs-header {
    height: var(--topbar-height);
    flex-shrink: 0 !important;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* ========================================
   BUTTONS & CONTROLS
   ======================================== */
.menu-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: inherit;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.theme-btn,
.mode-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0.5rem;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */
.title {
    font-size: 1.125rem;
    font-weight: 600;
}

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

/* ========================================
   GLASS EFFECT
   ======================================== */
.glass-panel {
    backdrop-filter: blur(14px);
    background: rgb(0, 38, 255);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
}

/* ========================================
   NEON TEXT
   ======================================== */
.neon-text {
    color: var(--neon, #00c8ff);
    text-shadow: 0 0 6px var(--neon, #00c8ff);
}

/* ========================================
   ANIMATIONS
   ======================================== */
.fade-in {
    animation: fadeIn 0.4s ease;
}

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

.fade-menu {
    transition: opacity 0.25s ease-in-out;
}

.menu-fade {
    animation: menuFade 0.3s ease;
}

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

/* ========================================
   LIVE INDICATOR
   ======================================== */
.fs-live-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #6c757d;
    transition: background 0.3s;
}

.fs-live-indicator.online {
    background: #fd7e14;
    box-shadow: 0 0 6px #28a745;
}

.fs-live-indicator.offline {
    background: #dc3545;
}

/* ========================================
   CONNECTION QUALITY
   ======================================== */
.fs-conn-quality {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.fs-conn-quality.good {
    background: #28a745;
    box-shadow: 0 0 6px #28a745;
}

.fs-conn-quality.fair {
    background: #ffc107;
    box-shadow: 0 0 6px #ffc107;
}

.fs-conn-quality.poor {
    background: #fd7e14;
    box-shadow: 0 0 6px #fd7e14;
}

.fs-conn-quality.offline,
.fs-conn-quality.unknown {
    background: #6c757d;
}

/* ========================================
   MOBILE BOTTOM NAV
   ======================================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    justify-content: space-around;
    align-items: center;
    backdrop-filter: blur(14px);
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid var(--border);
    z-index: 2000;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav .nav-btn {
    background: none;
    border: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 0.5rem;
}

.mobile-bottom-nav .nav-btn i {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.mobile-bottom-nav .nav-btn.active {
    opacity: 1;
    transform: translateY(-2px);
    color: var(--rz-primary, #3f51b5);
}

/* ========================================
   RESPONSIVE - TABLET (768px - 1024px)
   ======================================== */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-width-collapsed);
        min-width: var(--sidebar-width-collapsed);
    }
    
    .sidebar.open {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
    }
    
    .content-area {
        padding: 1rem;
    }
}

/* ========================================
   RESPONSIVE - MOBILE (< 768px)
   ======================================== */
@media (max-width: 768px) {
    :root {
        --topbar-height: 50px;
    }
    
    .layout-root {
        position: relative;
    }
    
    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100vh !important;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        z-index: 1001 !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.15);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar.closed {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
    }
    
    .main-area {
        width: 100% !important;
    }
    
    .content-area {
        padding: 1rem;
        padding-bottom: calc(var(--mobile-nav-height) + 1rem);
    }
    
    .mobile-bottom-nav {
        display: flex !important;
    }
    
    /* Ukryj wewnętrzny topbar na mobile - jest już RadzenHeader */
    .topbar-ultra.mobile-topbar {
        display: none;
    }
    
    .title {
        font-size: 1rem;
    }
    
    .user-box span {
        display: none;
    }
    
    /* Overlay when sidebar open */
    .sidebar.open::after {
        content: "";
        position: fixed;
        top: 0;
        left: var(--sidebar-width);
        right: 0;
        bottom: 0;
        background: #ffc107;
        z-index: -1;
    }
}

/* ========================================
   DASHBOARD SPECIFIC
   ======================================== */
@media (max-width: 576px) {
    .rz-card {
        margin-bottom: 0.5rem;
    }
    
    .content-area .rz-stack {
        gap: 0.5rem !important;
    }
    
    /* Dashboard stats cards */
    .content-area .rz-card .rz-stack {
        flex-wrap: wrap;
    }
}

/* ========================================
   THEME TRANSITION
   ======================================== */
.theme-fade-out {
    opacity: 0.7;
    transition: opacity 0.15s ease;
}

/* ========================================
   HIDE/SHOW UTILITIES
   ======================================== */
@media (min-width: 769px) {
    .mobile-bottom-nav {
        display: none !important;
    }
    
    .hide-on-desktop {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */
.sidebar::-webkit-scrollbar,
.content-area::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.content-area::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.content-area::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.content-area::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}
