/* Muhiim Electronics - Responsive Layout */

/* Safety: show page even if theme JS fails to load */
#main-wrapper {
    opacity: 1 !important;
}

#preloader {
    z-index: 99999;
}

body.loaded #preloader {
    display: none !important;
}

/* ---- Logo containers ---- */
.nav-header {
    overflow: visible !important;
}

.nav-header .brand-logo,
.sidebar-brand,
.sidebar-brand-link {
    overflow: hidden !important;
}

/* Sidebar toggle button — must stay visible ( sits outside nav-header ) */
.nav-control {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 9999 !important;
}

@media (min-width: 768px) {
    [data-sidebar-style="mini"] .nav-control,
    [data-sidebar-style="full"] .nav-control {
        display: block !important;
    }

    .nav-control .hamburger .line {
        background: #fff !important;
    }
}

/* Full logo - desktop sidebar header */
.muhiim-logo-full {
    display: block !important;
    width: 100% !important;
    max-width: calc(100% - 0.5rem) !important;
    height: auto !important;
    max-height: 62px !important;
    min-height: 40px;
    object-fit: contain !important;
    object-position: center !important;
    margin: 0 auto !important;
}

/* Mini logo - collapsed sidebar */
.muhiim-logo-mini {
    display: none !important;
    width: 48px !important;
    height: 48px !important;
    max-width: 48px !important;
    max-height: 48px !important;
    object-fit: contain !important;
    margin: 0 auto !important;
}

/* Sidebar brand logo (mobile drawer) */
.sidebar-brand-logo {
    display: block !important;
    width: 100% !important;
    max-width: 200px !important;
    height: auto !important;
    max-height: 52px !important;
    object-fit: contain !important;
    margin: 0 auto !important;
}

/* Mobile top header logo */
.header-mobile-logo {
    display: block !important;
    width: auto !important;
    max-width: 110px !important;
    height: auto !important;
    max-height: 30px !important;
    object-fit: contain !important;
    flex-shrink: 0;
}

/* ---- Nav Header ---- */
.nav-header {
    background: #0120BC !important;
}

.nav-header .brand-logo {
    display: flex !important;
    padding: 0.5rem 0.75rem !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    height: 100%;
    width: 100%;
}

/* Sidebar brand block */
.sidebar-brand {
    display: none;
    padding: 1rem 0.75rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background: #0120BC;
    text-align: center;
}

.sidebar-brand-link {
    display: block;
    text-decoration: none;
}

/* Mobile header row */
.header-brand-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.header .navbar-collapse {
    align-items: center;
}

/* Desktop: full logo in nav-header */
@media (min-width: 768px) {
    .sidebar-brand {
        display: none !important;
    }

    .header-brand-row {
        display: none !important;
    }

    .muhiim-logo-full {
        display: block !important;
    }

    .muhiim-logo-mini {
        display: none !important;
    }

    .nav-header .brand-logo {
        padding: 0.625rem 1rem !important;
    }
}

/* Collapsed sidebar: mini logo */
@media (min-width: 768px) {
    .menu-toggle .muhiim-logo-full,
    [data-sidebar-style="mini"] .muhiim-logo-full {
        display: none !important;
    }

    .menu-toggle .muhiim-logo-mini,
    [data-sidebar-style="mini"] .muhiim-logo-mini {
        display: block !important;
    }

    .menu-toggle .nav-header .brand-logo,
    [data-sidebar-style="mini"] .nav-header .brand-logo {
        justify-content: center !important;
        padding: 0.375rem !important;
    }
}

/* Sidebar overlay backdrop — mobile drawer only */
.sidebar-backdrop {
    display: none !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.25s ease;
}

@media (max-width: 767px) {
    .menu-toggle .sidebar-backdrop {
        display: block !important;
        opacity: 1;
    }
}

/* ---- Quick action buttons ---- */
.muhiim-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 1rem;
}

.muhiim-quick-actions .btn {
    white-space: nowrap;
}

/* ---- Header company title ---- */
.header-company-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 1rem;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Dashboard cards ---- */
.dashboard-cards .widget-stat.card {
    border-radius: 10px;
    margin-bottom: 0.75rem;
}

.dashboard-cards .widget-stat .card-body {
    padding: 1rem 1.25rem;
}

/* ---- Tablet (768px - 1199px) ---- */
@media (min-width: 768px) and (max-width: 1199px) {
    .header-company-title {
        font-size: 1.1rem;
    }

    .muhiim-quick-actions .btn {
        font-size: 11px !important;
        padding: 8px 10px !important;
    }
}

/* ---- Mobile (max 767px) ---- */
@media (max-width: 767px) {
    /* Nav header: hamburger button only */
    [data-sidebar-style="overlay"] .nav-header {
        width: 3.5rem !important;
        height: 3.5rem;
        background: #0120BC !important;
        position: fixed;
        left: 0;
        top: 0;
        z-index: 1003;
    }

    .sidebar-brand {
        display: block !important;
        position: sticky;
        top: 0;
        z-index: 2;
    }

    /* Hide nav-header logo on mobile - logo is in sidebar drawer */
    [data-sidebar-style="overlay"] .nav-header .brand-logo {
        display: none !important;
    }

    .muhiim-logo-full,
    .muhiim-logo-mini {
        display: none !important;
    }

    /* Keep hamburger fixed top-left when menu open (stop arrow jumping into sidebar) */
    [data-sidebar-style="overlay"] .menu-toggle .nav-header {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        width: 3.5rem !important;
        height: 3.5rem !important;
        z-index: 1004 !important;
    }

    [data-sidebar-style="overlay"] .nav-control {
        position: static !important;
        transform: none !important;
        right: auto !important;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    [data-sidebar-style="overlay"] .nav-control .hamburger {
        width: 28px;
    }

    [data-sidebar-style="overlay"] .nav-control .hamburger .line {
        background: #fff !important;
        height: 2.5px;
    }

    /* Sidebar drawer */
    [data-sidebar-style="overlay"] .deznav {
        width: min(240px, 72vw) !important;
        max-width: 72vw !important;
        padding-top: 3.5rem !important;
        z-index: 1002;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
        overflow: hidden !important;
    }

    [data-sidebar-style="overlay"] .deznav .deznav-scroll {
        padding-top: 0 !important;
        height: 100%;
        overflow-y: auto;
    }

    #menu {
        padding-top: 0 !important;
    }

    #menu > li:first-child {
        margin-top: 0 !important;
    }

    .deznav .metismenu {
        padding-top: 0.5rem !important;
    }

    [data-sidebar-style="overlay"] .menu-toggle .deznav {
        left: 0 !important;
    }

    /* Main content full width */
    [data-sidebar-style="overlay"] .header,
    [data-sidebar-style="overlay"] .content-body,
    [data-sidebar-style="overlay"] .footer {
        margin-left: 0 !important;
        padding-left: 0 !important;
        width: 100%;
    }

    [data-sidebar-style="overlay"] .header {
        padding-left: 3.5rem !important;
        height: 3.5rem;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .header .header-content {
        height: 3.5rem;
        padding-left: 0.5rem !important;
        padding-right: 0.75rem !important;
    }

    .header-left .search-area {
        display: none !important;
    }

    .header-company-title {
        font-size: 0.9rem;
        margin: 0;
        text-align: left;
        flex: 1;
        min-width: 0;
    }

    .header-brand-row .header-company-title {
        display: none;
    }

    .header-mobile-logo {
        max-width: 140px !important;
        max-height: 36px !important;
    }

    .header-right .header-info {
        display: none;
    }

    .header-right .header-profile img {
        width: 32px !important;
        height: 32px;
        border-radius: 50%;
        object-fit: cover;
    }

    .header-right {
        margin-left: auto;
    }

    /* Content area */
    .content-body {
        margin-left: 0 !important;
        max-height: none !important;
        overflow-x: hidden;
        padding-top: 0.5rem;
    }

    .dashboard-container {
        margin-top: 0 !important;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .form-head {
        flex-direction: column;
        align-items: stretch !important;
    }

    .muhiim-quick-actions {
        flex-wrap: wrap;
        overflow-x: visible;
        gap: 8px;
    }

    .muhiim-quick-actions .btn {
        flex: 1 1 calc(50% - 8px);
        min-width: calc(50% - 8px);
        font-size: 11px !important;
        padding: 10px 8px !important;
        text-align: center;
    }

    /* Dashboard stat cards - full width stack */
    .dashboard-cards .chart_detail3 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .dashboard-cards .widget-stat .media-body h4 {
        font-size: 1.25rem;
    }

    .dashboard-cards .widget-stat .chart_title {
        font-size: 0.75rem;
    }

    /* Income summary stacks vertically */
    .sumka .col-sm-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .sumka .card-header {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .sumka .card-tabs .nav-tabs {
        flex-wrap: wrap;
    }

    /* Modal fullscreen on mobile */
    #chart_detail_modal .modal-dialog {
        width: 100% !important;
        margin: 0 !important;
        max-width: 100%;
    }

    /* Footer */
    .footer {
        padding: 1rem 0.75rem !important;
        text-align: center;
    }

    .footer p {
        font-size: 0.8rem;
        margin: 0;
    }
}

/* ---- Small phones (max 480px) ---- */
@media (max-width: 480px) {
    .header-company-title {
        font-size: 0.85rem;
        max-width: 140px;
    }

    .dashboard-cards .widget-stat .card-body {
        padding: 0.875rem 1rem;
    }
}

@media (min-width: 768px) {
    .nav-header {
        height: 5.5rem !important;
        min-height: 5.5rem !important;
    }

    .nav-header .brand-logo {
        max-height: 5.5rem;
    }

    .muhiim-logo-full {
        max-height: 68px !important;
    }

    [data-sidebar-style="full"] .deznav {
        left: 0 !important;
        visibility: visible !important;
    }

    .deznav .metismenu > li > a.has-arrow:after {
        display: block !important;
        opacity: 1 !important;
    }
}

/* ---- Large desktop ---- */
@media (min-width: 1200px) {
    .dashboard-cards .chart_detail3 {
        margin-bottom: 0.5rem;
    }

    .muhiim-quick-actions {
        gap: 8px;
    }
}

/* ---- Forms & tables (all pages) ---- */
@media (max-width: 767px) {
    .content-body .card-body {
        padding: 1rem;
    }

    .content-body .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .content-body .row > [class*="col-"] {
        margin-bottom: 0.75rem;
    }

    .content-body .btn-group,
    .content-body .form-head .btn {
        flex-wrap: wrap;
    }

    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
}
