/* ==========================================================================
   Masar — Mobile-only styles
   Loaded after styles.css + theme style.css
   Uses body[class*="sam-style-"] specificity to beat preset class rules
   ========================================================================== */

/* --------------------------------------------------------------------------
   0) Hide mobile drawer chrome on desktop (md+ = >= 768px)
   -------------------------------------------------------------------------- */
@media (min-width: 768px) {

    .sam-mobile-nav,
    .sam-mobile-hamburger,
    .sam-mobile-backdrop,
    .sam-mobile-drawer {
        display: none !important;
    }
}


/* --------------------------------------------------------------------------
   1) Tablet & phone (<= 991.98px) — light tweaks
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {

    body[class*="sam-style-"] .page-wrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    body[class*="sam-style-"] .body-wrapper > .container-fluid,
    body[class*="sam-style-"] .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
}


/* --------------------------------------------------------------------------
   2) Phone only (<= 767.98px) — main mobile experience
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {

    /* ===== Top header (topbar) ===== */
    body[class*="sam-style-"] header.topbar {
        position: sticky;
        top: 0;
        z-index: 1030;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }

    body[class*="sam-style-"] header.topbar .app-header {
        padding: 8px 12px 8px 60px !important;
        min-height: 60px;
        display: flex;
        align-items: center;
    }

    [dir="rtl"] body[class*="sam-style-"] header.topbar .app-header,
    body[dir="rtl"][class*="sam-style-"] header.topbar .app-header {
        padding: 8px 60px 8px 12px !important;
    }

    body[class*="sam-style-"] header.topbar .app-header > nav.navbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap;
        width: 100%;
        gap: 8px;
    }

    /* Logo on mobile — compact */
    body[class*="sam-style-"] header.topbar .app-header .navbar > .d-block.d-md-none img,
    body[class*="sam-style-"] header.topbar .app-header .navbar img.dark-logo {
        max-width: 130px;
        height: auto;
    }

    /* Hide the spare three-dots toggler that duplicates the offcanvas trigger */
    body[class*="sam-style-"] header.topbar .app-header > nav.navbar > a.navbar-toggler {
        display: none !important;
    }

    /* Hide the dead offcanvas trigger (no #mobilenavbar exists) */
    body[class*="sam-style-"] header.topbar a[data-bs-target="#mobilenavbar"] {
        display: none !important;
    }

    /* Hide left sidebar collapse button (we have our own hamburger) */
    body[class*="sam-style-"] header.topbar .nav-link.sidebartoggler {
        display: none !important;
    }

    /* Right-side icon group: notifications + profile */
    body[class*="sam-style-"] header.topbar #navbarNav {
        flex: 0 0 auto !important;
        width: auto !important;
        display: block !important;
    }

    body[class*="sam-style-"] header.topbar #navbarNav .d-flex.align-items-center {
        gap: 4px;
        padding: 0 !important;
    }

    body[class*="sam-style-"] header.topbar .navbar-nav.flex-row {
        gap: 4px;
        align-items: center;
    }

    body[class*="sam-style-"] header.topbar .navbar-nav .nav-link {
        padding: 8px !important;
        position: relative;
    }

    body[class*="sam-style-"] header.topbar .navbar-nav .nav-link .notification.badge-number {
        width: 16px;
        height: 16px;
        min-width: 16px;
        font-size: 10px;
        line-height: 1;
        position: absolute;
        top: 2px;
        right: 2px;
    }

    body[class*="sam-style-"] header.topbar .user-profile-img img {
        width: 32px !important;
        height: 32px !important;
    }


    /* ===== Mobile drawer menu (new structure) ===== */

    .sam-mobile-toggle-input {
        position: absolute !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* Hamburger button — fixed top-left, always above drawer */
    .sam-mobile-hamburger {
        position: fixed;
        top: 31px;
        left: 14px;
        width: 36px;
        height: 36px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        background: #ffffff;
        border-radius: 8px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
        cursor: pointer;
        z-index: 1050;
        margin: 0;
        padding: 0;
        transition: background 0.2s ease;
    }

    [dir="rtl"] .sam-mobile-hamburger,
    body[dir="rtl"] .sam-mobile-hamburger {
        left: auto;
        right: 14px;
    }

    .sam-mobile-hamburger:hover,
    .sam-mobile-hamburger:active {
        background: #f6f9fc;
    }

    .sam-mobile-hamburger > span {
        display: block;
        width: 20px;
        height: 2.4px;
        background: #2a3547;
        border-radius: 2px;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* Backdrop — covers screen when drawer is open */
    .sam-mobile-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(20, 27, 45, 0.55);
        opacity: 0;
        visibility: hidden;
        cursor: pointer;
        z-index: 1040;
        transition: opacity 0.28s ease, visibility 0.28s ease;
        margin: 0;
    }

    /* Drawer — fixed left, slides in */
    .sam-mobile-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 290px;
        max-width: 86vw;
        height: 100vh;
        height: 100dvh;
        background: #ffffff;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    [dir="rtl"] .sam-mobile-drawer,
    body[dir="rtl"] .sam-mobile-drawer {
        left: auto;
        right: 0;
        transform: translateX(100%);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    }

    /* Open state — checkbox checked */
    .sam-mobile-toggle-input:checked ~ .sam-mobile-backdrop {
        opacity: 1;
        visibility: visible;
    }

    .sam-mobile-toggle-input:checked ~ .sam-mobile-drawer {
        transform: translateX(0);
    }

    /* Animate hamburger to X when open */
    .sam-mobile-toggle-input:checked ~ .sam-mobile-hamburger > span:nth-child(1) {
        transform: translateY(7.4px) rotate(45deg);
    }
    .sam-mobile-toggle-input:checked ~ .sam-mobile-hamburger > span:nth-child(2) {
        opacity: 0;
    }
    .sam-mobile-toggle-input:checked ~ .sam-mobile-hamburger > span:nth-child(3) {
        transform: translateY(-7.4px) rotate(-45deg);
    }

    /* Lock body scroll when drawer is open */
    body:has(.sam-mobile-toggle-input:checked) {
        overflow: hidden;
    }

    /* Drawer header (logo + close X) */
    .sam-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        background: var(--primary-color, #5d87ff);
        color: #ffffff;
        flex-shrink: 0;
        min-height: 64px;
    }

    .sam-drawer-logo {
        max-height: 36px;
        max-width: 160px;
        width: auto;
        height: auto;
        filter: brightness(0) invert(1);
    }

    .sam-drawer-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.18);
        color: #ffffff;
        border-radius: 8px;
        cursor: pointer;
        margin: 0;
        padding: 0;
        transition: background 0.18s ease;
    }

    .sam-drawer-close:hover,
    .sam-drawer-close:active {
        background: rgba(255, 255, 255, 0.32);
    }

    /* Drawer user info strip */
    .sam-drawer-user {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        background: #f6f9fc;
        border-bottom: 1px solid #eaeff4;
        flex-shrink: 0;
    }

    .sam-drawer-avatar {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        object-fit: cover;
        flex-shrink: 0;
        border: 2px solid #ffffff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    }

    .sam-drawer-user-info {
        display: flex;
        flex-direction: column;
        min-width: 0;
        flex: 1;
    }

    .sam-drawer-user-info strong {
        font-size: 14px;
        font-weight: 700;
        color: #2a3547;
        line-height: 1.2;
        margin-bottom: 2px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sam-drawer-user-info small {
        font-size: 11px;
        color: #7c8fac;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Drawer nav (scrollable area) */
    .sam-drawer-nav {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0;
    }

    .sam-drawer-nav #menu {
        list-style: none !important;
        margin: 0 !important;
        padding: 0 !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        overflow: visible !important;
    }

    .sam-drawer-nav #menu li.nav-small-cap {
        padding: 12px 18px 6px !important;
        margin: 4px 0 0 !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        text-transform: uppercase;
        letter-spacing: 0.6px;
        color: #7c8fac !important;
        background: transparent;
    }

    .sam-drawer-nav #menu li.nav-small-cap:not(:first-child) {
        border-top: 1px solid #eaeff4;
        margin-top: 8px !important;
        padding-top: 14px !important;
    }

    .sam-drawer-nav #menu li.nav-small-cap span.hide-menu,
    .sam-drawer-nav #menu li.nav-small-cap a {
        color: inherit !important;
        text-decoration: none;
        background: transparent !important;
        padding: 0 !important;
        font-weight: 700 !important;
        display: inline;
    }

    .sam-drawer-nav #menu li.sidebar-item {
        padding: 0 !important;
        margin: 2px 8px !important;
        list-style: none;
    }

    .sam-drawer-nav #menu li.sidebar-item a.sidebar-link {
        display: flex !important;
        align-items: center;
        padding: 10px 14px !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        color: #2a3547 !important;
        border-radius: 8px !important;
        text-decoration: none;
        transition: background 0.15s ease, color 0.15s ease;
        line-height: 1.3;
    }

    .sam-drawer-nav #menu li.sidebar-item a.sidebar-link:hover,
    .sam-drawer-nav #menu li.sidebar-item a.sidebar-link:focus,
    .sam-drawer-nav #menu li.sidebar-item a.sidebar-link:active {
        background: var(--primary-color, #5d87ff) !important;
        color: #ffffff !important;
    }

    .sam-drawer-nav #menu li.sidebar-item a.sidebar-link span.hide-menu {
        display: inline !important;
    }

    /* Drawer footer (logout) */
    .sam-drawer-footer {
        flex-shrink: 0;
        padding: 12px 16px;
        border-top: 1px solid #eaeff4;
        background: #ffffff;
    }

    .sam-drawer-logout {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 11px 16px;
        background: rgba(250, 137, 107, 0.1);
        color: #fa896b;
        border-radius: 8px;
        font-weight: 600;
        font-size: 14px;
        text-decoration: none;
        transition: background 0.18s ease, color 0.18s ease;
    }

    .sam-drawer-logout:hover,
    .sam-drawer-logout:active {
        background: #fa896b;
        color: #ffffff;
    }

    /* Hide the desktop quick-links menu on mobile (it's already d-none d-md-flex) */
    body[class*="sam-style-"] .quick-links {
        display: none !important;
    }


    /* ===== Inner page header card (.card.bg-info-subtle) ===== */
    body[class*="sam-style-"] .card.bg-info-subtle {
        margin: 8px 0 12px !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, #ebf3fe 0%, #e6f4ff 100%) !important;
        border: 1px solid #d6e6ff !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle > .card-body {
        padding: 12px !important;
        margin: 0 !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle > .card-body > .row {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px;
        margin: 0 !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle > .card-body > .row > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        padding: 0 !important;
    }

    /* Title — centered chip on top */
    body[class*="sam-style-"] .card.bg-info-subtle > .card-body > .row > .text-center {
        order: -1;
    }

    body[class*="sam-style-"] .card.bg-info-subtle h4.fw-semibold {
        font-size: 15px !important;
        font-weight: 700 !important;
        text-align: center;
        color: #1f3a68 !important;
        background: #ffffff;
        padding: 8px 12px !important;
        border-radius: 8px;
        border: 1px solid #d6e6ff;
        margin: 0 !important;
        letter-spacing: 0.3px;
    }

    /* Button row — wrap, equal-spaced, compact */
    body[class*="sam-style-"] .card.bg-info-subtle .d-flex {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        justify-content: center !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle .d-flex .btn {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0 !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        border-radius: 8px !important;
        white-space: nowrap;
        height: auto;
        line-height: 1.2;
        gap: 6px;
    }

    body[class*="sam-style-"] .card.bg-info-subtle .d-flex .btn img.emoji {
        width: 14px !important;
        height: 14px !important;
        margin: 0 !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle .d-flex.justify-content-end:empty {
        display: none !important;
    }


    /* ===== Table action buttons row (.table-action-btns) ===== */
    body[class*="sam-style-"] .row.table-action-btns {
        margin: 8px 0 12px !important;
        padding: 10px 8px !important;
        background: #ffffff;
        border-radius: 12px;
        border: 1px solid #eaeff4;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        align-items: center;
        justify-content: flex-start;
    }

    body[class*="sam-style-"] .row.table-action-btns > [class*="col-"] {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        padding: 0 !important;
    }

    body[class*="sam-style-"] .row.table-action-btns .btn {
        margin: 0 !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        border-radius: 8px !important;
        height: auto;
        min-height: 36px;
        line-height: 1.2;
        display: inline-flex !important;
        align-items: center;
        gap: 6px;
        white-space: nowrap;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    }

    body[class*="sam-style-"] .row.table-action-btns .btn img.emoji {
        width: 14px !important;
        height: 14px !important;
        margin: 0 !important;
        display: inline-block;
        vertical-align: middle;
    }

    /* Icon-only buttons (no visible text after the emoji) — square shape */
    body[class*="sam-style-"] .row.table-action-btns .samRequestsButton,
    body[class*="sam-style-"] .row.table-action-btns .samAllowRequestsButton {
        width: 38px;
        min-width: 38px;
        padding: 8px 0 !important;
        justify-content: center;
        background: #f6f9fc !important;
        color: #2a3547 !important;
        border: 1px solid #eaeff4;
    }

    body[class*="sam-style-"] .row.table-action-btns .samRequestsButton img.emoji,
    body[class*="sam-style-"] .row.table-action-btns .samAllowRequestsButton img.emoji {
        width: 16px !important;
        height: 16px !important;
    }


    /* ===== General readability tweaks on mobile ===== */
    body[class*="sam-style-"] .card {
        border-radius: 10px;
    }

    body[class*="sam-style-"] .card-body {
        padding: 12px;
    }

    body[class*="sam-style-"] h4,
    body[class*="sam-style-"] .h4 {
        font-size: 17px;
    }

    body[class*="sam-style-"] h5,
    body[class*="sam-style-"] .h5 {
        font-size: 15px;
    }

    body[class*="sam-style-"] .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    body[class*="sam-style-"] .form-control,
    body[class*="sam-style-"] .form-select {
        font-size: 14px;
    }

    body[class*="sam-style-"] .btn {
        min-height: 36px;
    }

    .body-wrapper {
        padding: 0 !important;
    }

}


/* --------------------------------------------------------------------------
   3) Small phones (<= 380px) — extra compaction
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {

    body[class*="sam-style-"] header.topbar .app-header .navbar img.dark-logo,
    body[class*="sam-style-"] header.topbar .app-header .navbar > .d-block.d-md-none img {
        max-width: 110px;
    }

    body[class*="sam-style-"] .card.bg-info-subtle .d-flex .btn,
    body[class*="sam-style-"] .row.table-action-btns .btn {
        padding: 7px 10px !important;
        font-size: 12px !important;
    }

    body[class*="sam-style-"] .card.bg-info-subtle h4.fw-semibold {
        font-size: 14px !important;
    }
}
