/* ================================================================
   responsive-mobile.css
   Mobile & Tablet responsive overrides for SSO PublicPortal
   Targets: max-width 1024px — covers phones + all tablets including
   iPad landscape (1024px). Desktop (> 1024px) is COMPLETELY UNAFFECTED.
   RTL-aware layout — Arabic portal (dir="rtl").
   ================================================================ */

/* ================================================================
   1. GLOBAL OVERFLOW & BASE FIXES
   ================================================================ */
@media (max-width: 1024px) {
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Fix containers overflowing viewport */
    .container,
    .container-fluid {
        padding-left: 0.9rem !important;
        padding-right: 0.9rem !important;
        max-width: 100% !important;
    }

    /* Fix hardcoded employee-container width (site.css already patched for desktop) */
    .employee-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto;
        box-sizing: border-box;
    }

    /* Prevent max-content overflow on main content */
    .main-content {
        max-width: 100% !important;
        overflow-x: hidden;
    }

    /* Ensure images never overflow */
    img {
        max-width: 100%;
        height: auto;
    }

    /* iOS: prevent auto-zoom on input focus (requires font-size >= 16px) */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Touch-friendly minimum tap target */
    .btn,
    button,
    a.nav-link,
    .quick-link {
        min-height: 44px;
    }
}

/* ================================================================
   2. RESPONSIVE TABLE WRAPPER
   JS in _EnhancedLayout & _Layout adds .table-wrap around tables
   ================================================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    margin-bottom: 1rem;
}

.table-wrap > table {
    margin-bottom: 0 !important;
}

/* ================================================================
   3. HAMBURGER BUTTON — hidden on desktop, shown on mobile/tablet
   ================================================================ */
.mobile-nav-toggle {
    display: none; /* Desktop: hidden */
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    color: white;
    font-size: 1.15rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease;
    padding: 0;
    line-height: 1;
    outline: none;
}

.mobile-nav-toggle:hover,
.mobile-nav-toggle:focus {
    background: rgba(255, 255, 255, 0.28);
}

@media (max-width: 1024px) {
    .mobile-nav-toggle {
        display: flex !important;
    }
}

/* ================================================================
   3b. PHONE-ONLY HEADER ELEMENTS
   These flex items sit inside the phone header container on all
   non-login layouts: hamburger + landscape logo + spacer + username.
   In _EnhancedLayout they're flex items inside .banner .container.
   In other layouts they're inside .mobile-phone-header fixed bar.
   ================================================================ */

/* Landscape logo — hidden until phone breakpoint */
.mobile-landscape-logo {
    display: none;
    height: 34px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    flex-shrink: 0;
}

/* Flex spacer — stretches to push username to the LEFT (RTL end) */
.mobile-header-spacer {
    display: none;
    flex: 1;
    min-width: 0;
}

/* Username — appears on LEFT side of phone header */
.mobile-header-username {
    display: none;
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    flex-shrink: 1;
}

/* Fixed phone-only header bar — used in layouts that don't own a .banner
   (_IdentitySelectionLayout, _Layout, _DashboardLayout) */
.mobile-phone-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1e40af 100%);
    z-index: 10100;
    align-items: center;
    padding: 0 0.85rem;
    gap: 0.75rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    flex-direction: row;  /* RTL: starts from RIGHT */
}

@media (max-width: 600px) {
    /* Activate phone elements */
    .mobile-landscape-logo  { display: block !important; order: 2; }
    .mobile-header-spacer   { display: block !important; order: 3; }
    .mobile-header-username { display: block !important; order: 4; }
    .mobile-phone-header    { display: flex; }

    /* ── Other-layout phone header: hide original headers, pad body ── */

    /* _IdentitySelectionLayout: show banner on phones like _EnhancedLayout,
       override its dark gradient and pill borders to match system phone header */
    .identity-layout .banner {
        height: 70px !important;
        background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1e40af 100%) !important;
        border-style: none !important;
        border-end-end-radius: 0 !important;
        border-start-start-radius: 0 !important;
    }

    .identity-layout .banner .container {
        height: 70px !important;
    }

    /* Hide user info and logout on phone — accessible via drawer */
    .identity-layout .banner .user-info {
        display: none !important;
    }
    /* Hide the gov-header used by _Layout */
    .main-layout .gov-header {
        display: none !important;
    }
    /* Hide the dashboard-header used by _DashboardLayout */
    .dashboard-layout .dashboard-header {
        display: none !important;
    }
    /* Hide the dashboard sidebar on phones (navigation via drawer) */
    .dashboard-layout .dashboard-sidebar {
        display: none !important;
    }

    /* Pad body so content starts below the fixed 70px phone header bar.
       identity-layout uses banner in normal flow, so no padding-top needed. */
    body.main-layout,
    body.dashboard-layout {
        padding-top: 70px !important;
    }

    /* Dashboard: main content has margin-top from header var — reset it */
    .dashboard-layout .main-content {
        margin-right: 0 !important;
        margin-top: 0 !important;
    }
    .dashboard-layout .dashboard-footer {
        margin-right: 0 !important;
    }
}

/* ================================================================
   4. MOBILE NAV DRAWER — polished, matches system sidebar
   Sidebar colors: #1e293b → #334155 (same as enhanced-layout.css)
   Accent: #6366f1 (indigo) — same as --accent-color
   ================================================================ */

/* ─── Backdrop ────────────────────────────────────────────── */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
}

.mobile-nav-overlay.open {
    display: block;
}

/* ─── Panel ───────────────────────────────────────────────── */
.mobile-nav-panel {  
    position: fixed;
    top: 0;
    right: -100%;
    width: min(310px, 88vw);
    height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    z-index: 10001;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    transition: right 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 40px rgba(0, 0, 0, 0.45),
                -1px 0 0 rgba(255,255,255,0.06);
}

/* Top accent stripe (blue → indigo → violet) */
.mobile-nav-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #60a5fa 0%, #818cf8 50%, #a78bfa 100%);
    z-index: 2;
    flex-shrink: 0;
}

/* Subtle inner glow at top */
.mobile-nav-panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(to bottom, rgba(255,255,255,0.06) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
}

.mobile-nav-overlay.open .mobile-nav-panel {
    right: 0;
}

/* ─── Panel Header ────────────────────────────────────────── */
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.mobile-nav-title {
    color: white;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* Vertical accent bar before title text */
.mobile-nav-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: linear-gradient(to bottom, #60a5fa, #a78bfa);
    border-radius: 2px;
    flex-shrink: 0;
}

.mobile-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px; 
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.mobile-nav-close:hover,
.mobile-nav-close:focus {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.28);
    outline: none;
}

/* Landscape logo inside drawer header — natural colors on semi-transparent background */
.mobile-nav-logo {
    height: 70px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 8px 14px;
}

/* ─── User Info Card ──────────────────────────────────────── */
.mobile-nav-user-info {
    margin: 1rem 0.9rem 0;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 14px;
    color: white;
    text-align: right;
    flex-shrink: 0;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18),
                inset 0 1px 0 rgba(255, 255, 255, 0.12);
    position: relative;
    z-index: 1;
}

.mobile-nav-user-name {
    font-weight: 700;
    font-size: 0.98rem;
    color: white;
    line-height: 1.3;
    margin-bottom: 0;
}

.mobile-nav-user-role {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.68);
    margin-top: 0.2rem;
}

/* ─── Nav Links ───────────────────────────────────────────── */
.mobile-nav-links {
    flex: 1;
    padding: 0.9rem 0.75rem 0.5rem;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.mobile-nav-links .nav-link {
    color: rgba(255, 255, 255, 0.82) !important;
    padding: 0.78rem 1rem !important;
    border-radius: 10px !important;
    margin-bottom: 0.28rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.8rem !important;
    text-decoration: none !important;
    font-size: 0.93rem !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
    background: transparent !important;
    border: 1px solid transparent !important;
    width: 100%;
    position: relative;
}

.mobile-nav-links .nav-link:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: white !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Active page: indigo pill matching --accent-color */
.mobile-nav-links .nav-link.active-page {
    background: rgba(99, 102, 241, 0.28) !important;
    border-color: rgba(99, 102, 241, 0.45) !important;
    color: white !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.22) !important;
}

/* Right-edge indicator stripe on active link (RTL visual right) */
.mobile-nav-links .nav-link.active-page::after {
    content: '';
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: linear-gradient(to bottom, #60a5fa, #818cf8);
    border-radius: 2px 0 0 2px;
}

.mobile-nav-links .nav-link i {
    width: 1.15rem;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.88rem;
    opacity: 0.78;
}

.mobile-nav-links .nav-link.active-page i {
    opacity: 1;
    color: #93c5fd; /* light blue matching accent */
}

/* ─── Footer / Logout ─────────────────────────────────────── */
.mobile-nav-footer {
    padding: 0.75rem 0.9rem 1.3rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.mobile-nav-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.82rem 1rem;
    background: linear-gradient(135deg, rgba(220,38,38,0.88) 0%, rgba(185,28,28,0.95) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.22s ease;
    min-height: 44px;
    box-shadow: 0 4px 16px rgba(220, 38, 38, 0.32);
}

.mobile-nav-logout-btn:hover,
.mobile-nav-logout-btn:focus {
    background: linear-gradient(135deg, rgba(185,28,28,1) 0%, rgba(153,27,27,1) 100%);
    box-shadow: 0 6px 22px rgba(220, 38, 38, 0.5);
    transform: translateY(-1px);
    outline: none;
}

/* ─── Scrollbar ───────────────────────────────────────────── */
.mobile-nav-panel::-webkit-scrollbar { width: 4px; }
.mobile-nav-panel::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }
.mobile-nav-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 2px; }

/* ================================================================
   5. _EnhancedLayout.cshtml BANNER HEADER — tablet overrides
   The banner has three absolute-positioned elements:
     .header-user-info  (right side)
     #main-logo         (centered)
     .header-logout-area (left side)
   Tablet (601–1024px): compact 100px banner, role icon + switch visible.
   Phone (≤600px): 70px banner, only hamburger + landscape logo.
   ================================================================ */
@media (max-width: 1024px) {
    /* Tablet banner: 100px intermediate height */
    .banner {
        height: 100px !important;
        border-end-end-radius: 35px !important;
        border-start-start-radius: 35px !important;
    }

    /* Container: override inline height:140px, keep relative for abs logo */
    .banner .container.d-flex {
        height: 100px !important;
        position: relative !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 0.5rem 0.85rem !important;
        gap: 0.4rem;
    }

    /* Header user-info: show compact on tablets (role icon + switch btn only) */
    .header-user-info {
        position: relative !important;
        transform: none !important;
        flex-shrink: 0;
        z-index: 1;
        text-align: right;
        max-width: none;
        min-width: auto !important;
    }

    /* Hide greeting text ("أهلاً، username") — no class, only style attribute */
    .header-user-info > div:not(.role-indicator) {
        display: none !important;
    }

    /* Compact role indicator pill in header */
    .header-user-info .role-indicator {
        padding: 0.3rem 0.45rem !important;
        gap: 0.35rem !important;
    }

    /* Hide role name & title labels — keep only the colored icon */
    .header-user-info .role-info-section {
        display: none !important;
    }

    /* Switch button: icon only in header */
    .header-user-info .btn-switch span {
        display: none !important;
    }

    .header-user-info .btn-switch {
        padding: 0.3rem 0.4rem !important;
        font-size: 0.85rem !important;
        min-height: 32px !important;
    }

    /* Logo: keep absolute centering but shrink to fit 100px banner */
    #main-logo {
        position: absolute !important;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
        max-height: 80px !important;
        max-width: 200px;
        z-index: 0;
    }

    /* Logout area: replace absolute positioning with normal flow */
    .header-logout-area {
        position: relative !important;
        transform: none !important;
        flex-shrink: 0;
        z-index: 1;
    }

    /* Logout button — square icon-only on tablet/phone */
    .enhanced-logout-btn {
        width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        gap: 0 !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 0 !important;        /* zero out any inherited text sizing */
    }

    /* Icon: restore explicit size and center it */
    .enhanced-logout-btn i {
        font-size: 1.15rem !important;
        line-height: 1 !important;
        display: block !important;
        flex-shrink: 0;
    }

    /* Hide text label — !important to beat the inline <style> block */
    .enhanced-logout-btn .logout-btn-text {
        display: none !important;
    }

    /* Force hamburger to show above logo */
    .mobile-nav-toggle {
        flex-shrink: 0;
        z-index: 1;
        position: relative !important;
    }

    /* Hide desktop sidebar completely (overrides Bootstrap d-md-block) */
    #enhancedSidebar,
    .sidebar.d-none.d-md-block {
        display: none !important;
    }

    /* Main content: remove sidebar margin, fix top margin for 100px tablet banner */
    .main-content,
    .main-content.with-sidebar {
        margin-right: 0 !important;
        margin-left: 0 !important;
        margin-top: 100px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* ================================================================
   PHONE HEADER (≤ 600px) — _EnhancedLayout
   RIGHT side: [☰ hamburger] [landscape logo]
   SPACE (flex grows)
   LEFT side:  [username]
   All other banner elements hidden — accessible via drawer.
   ================================================================ */
@media (max-width: 600px) {

    /* Phone banner: shrink to 70px (from tablet's 100px) */
    .banner {
        height: 70px !important;
        border-end-end-radius: 0 !important;
        border-start-start-radius: 0 !important;
    }

    .banner .container.d-flex {
        height: 70px !important;
        justify-content: flex-start !important;
    }

    /* Main content: adjust margin for 70px phone banner */
    .main-content,
    .main-content.with-sidebar {
        margin-top: 70px !important;
    }

    /* Hide logout button — accessible through hamburger drawer */
    .header-logout-area {
        display: none !important;
    }

    /* Hide role info — accessible via drawer */
    .header-user-info {
        display: none !important;
    }

    /* Hide the square centered logo — replaced by landscape logo element */
    #main-logo {
        display: none !important;
        position: static !important;
    }

    /* Hamburger on RIGHT (RTL: order 1 = visual RIGHT) */
    .mobile-nav-toggle {
        order: 1;
        flex-shrink: 0;
    }
    /* mobile-landscape-logo order: 2, mobile-header-spacer order: 3,
       mobile-header-username order: 4 — set in section 3b above */
}

/* IdentitySelection layout: hide logout on phones too */
@media (max-width: 600px) {
    .banner .logout-container {
        display: none !important;
    }
}

/* ================================================================
   5b. MOBILE NAV DRAWER — role indicator inside user card
   Role icon + name on row 1; switch button on row 2 (more space).
   ================================================================ */
.mobile-nav-role-badge {
    margin-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 0.7rem;
}

/* Role indicator: wrap so the switch button drops to its own row */
.mobile-nav-role-badge .role-indicator {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    gap: 0.55rem !important;
    width: 100%;
    flex-wrap: wrap !important;    /* enables the 2-row layout */
}

/* Row 1: icon + role info section (takes remaining width) */
.mobile-nav-role-badge .role-icon-section {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.75rem !important;
    border-radius: 6px !important;
    flex-shrink: 0;
}

.mobile-nav-role-badge .role-info-section {
    flex: 1 !important;
    max-width: none !important;    /* remove 200px desktop cap */
    min-width: 0;
}

.mobile-nav-role-badge .role-title {
    font-size: 0.68rem !important;
    color: rgba(255, 255, 255, 0.6) !important;
}

.mobile-nav-role-badge .role-name {
    font-size: 0.9rem !important;
    color: rgba(255, 255, 255, 0.95) !important;
    white-space: normal !important;   /* allow wrapping for long names */
}

/* Row 2: switch button — full width on its own line */
.mobile-nav-role-badge .role-actions {
    width: 100% !important;
    margin-top: 0.55rem !important;
}

.mobile-nav-role-badge .btn-switch {
    width: 100% !important;
    justify-content: center !important;
    padding: 0.55rem 1rem !important;
    font-size: 0.85rem !important;
    min-height: 38px !important;
    border-radius: 8px !important;
    background: rgba(99, 102, 241, 0.75) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
    gap: 0.5rem !important;
}

.mobile-nav-role-badge .btn-switch:hover {
    background: rgba(99, 102, 241, 0.95) !important;
}

/* Show full label text in the drawer */
.mobile-nav-role-badge .btn-switch span {
    display: inline !important;
}

/* ================================================================
   6. _IdentitySelectionLayout.cshtml BANNER — tablet overrides
   Uses class-based positioning: .user-info, .logo-container, .logout-container
   Scoped to .identity-layout to avoid clashing with Section 5.
   ================================================================ */
@media (max-width: 1024px) {
    /* Tablet banner: 100px intermediate height, reduced border-radius */
    .identity-layout .banner {
        height: 100px !important;
        border-end-end-radius: 35px !important;
        border-start-start-radius: 35px !important;
    }

    /* Container: collapse height to match */
    .identity-layout .banner .container {
        height: 100px !important;
        padding: 0.5rem 1rem !important;
    }

    /* Hide user info on tablet for identity selection (user is selecting a role) */
    .identity-layout .banner .header-user-info {
        display: none !important;
    }

    /* Shrink logo image to fit 100px banner height */
    .identity-layout .banner .logo-container img {
        max-height: 80px !important;
        width: auto !important;
    }

    /* Logout container: unstick CSS-based absolute positioning */
    .identity-layout .banner .logout-container {
        position: relative !important;
        transform: none !important;
    }

    /* Logout area: compact icon-only button on tablet */
    .identity-layout .header-logout-area button {
        padding: 0 !important;
        width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        font-size: 0 !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .identity-layout .header-logout-area button i {
        font-size: 1.15rem !important;
    }

    .identity-layout .header-logout-area button span {
        display: none !important;
    }

    /* Also handle legacy .logout-container if present */
    .identity-layout .enhanced-logout-btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
    }

    .identity-layout .enhanced-logout-btn .logout-btn-text {
        display: none !important;
    }

    /* Identity selection page-wrapper: reduce top padding */
    .page-wrapper {
        padding: 15px 3% !important;
    }

    /* Fix flex overflow: 62% + 38% + gap > 100%. Stack columns on tablet. */
    .content-container {
        flex-direction: column !important;
        gap: 20px !important;
    }

    .identity-layout .main-area {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .identity-layout .sidebar {
        width: 100% !important;
        flex: 1 1 100% !important;
    }

    /* Page title font on tablet */
    .page-title h1 {
        font-size: 1.5rem !important;
    }
}

@media (max-width: 600px) {
    /* Expand role cards to full width on phones —
       .main-area has flex: 0 0 62% in base CSS; force full-width in column layout */
    .identity-layout .content-container {
        flex-direction: column !important;
        gap: 15px !important;
    }

    .identity-layout .main-area {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .identity-layout .sidebar {
        width: 100% !important;
    }

    /* Reduce the large gap between banner and role cards */
    .identity-layout .page-wrapper {
        padding-top: 8px !important;
        padding-bottom: 12px !important;
    }

    .identity-layout .page-title {
        margin-bottom: 12px !important;
    }

    .identity-layout .page-title h1 {
        font-size: 1.35rem !important;
    }

    .identity-layout .page-title p {
        font-size: 0.82rem !important;
        margin-bottom: 0 !important;
    }
}

/* ================================================================
   7. _Layout.cshtml GOV-HEADER — mobile overrides
   Uses .gov-header > .header-main > .container > .d-flex
   ================================================================ */
@media (max-width: 1024px) {
    /* Allow header to wrap onto multiple lines */
    .gov-header .header-main .container .d-flex {
        flex-wrap: wrap !important;
        gap: 0.6rem;
    }

    /* Nav section wraps and centers */
    .gov-header .nav-section {
        width: 100% !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    /* Logo: keep proportional, cap at 40px on tablet */
    .gov-header .logo-section img {
        height: 40px !important;
        width: auto !important;
    }

    .gov-header .site-title {
        font-size: 1.1rem !important;
    }

    .gov-header .site-subtitle {
        font-size: 0.8rem !important;
    }

    /* User role menu: full width, centered */
    .gov-header .enhanced-role-menu {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Smaller buttons */
    .gov-header .btn {
        font-size: 0.85rem;
        padding: 0.5rem 0.9rem;
        min-height: 44px;
    }
}

@media (max-width: 576px) {
    /* Even smaller nav items */
    .gov-header .enhanced-role-menu .user-name {
        max-width: 140px !important;
    }

    .gov-header .enhanced-role {
        max-width: 160px !important;
    }
}

/* ================================================================
   8. _DashboardLayout.cshtml — tablet overrides
   Already has @media (max-width: 1024px) in inline styles.
   Extra fixes + explicit logo sizing below.
   ================================================================ */
@media (max-width: 1024px) {
    /* Tablet header: 100px height, reduced border-radius */
    .dashboard-header {
        padding: 0 1rem !important;
        height: 100px !important;
        border-end-end-radius: 35px !important;
        border-start-start-radius: 35px !important;
    }

    /* Container inside dashboard header */
    .dashboard-header .container.d-flex {
        height: 100px !important;
    }

    /* User info: compact on tablet */
    .dashboard-layout .header-user-info {
        position: relative !important;
        transform: none !important;
        min-width: auto !important;
    }

    .dashboard-layout .header-user-info > div:not(.role-indicator) {
        display: none !important;
    }

    .dashboard-layout .header-user-info .role-info-section {
        display: none !important;
    }

    .dashboard-layout .header-user-info .btn-switch span {
        display: none !important;
    }

    /* Logo: fit inside 100px header */
    .dashboard-header #main-logo {
        max-height: 80px !important;
    }

    /* Logout area: flow layout */
    .dashboard-layout .header-logout-area {
        position: relative !important;
        transform: none !important;
    }

    /* Logout button: compact */
    .dashboard-layout .header-logout-area button {
        padding: 0.4rem 0.6rem !important;
        font-size: 0 !important;
        width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .dashboard-layout .header-logout-area button i {
        font-size: 1.15rem !important;
    }

    .dashboard-layout .header-logout-area button span {
        display: none !important;
    }

    /* Dashboard sidebar: full width block on tablet */
    .dashboard-sidebar {
        position: relative !important;
        top: 0 !important;
        height: auto !important;
        width: 100% !important;
        border-radius: 0 !important;
    }

    /* Main content below sidebar (_DashboardLayout only — does NOT affect _EnhancedLayout) */
    .dashboard-layout .main-content {
        margin-right: 0 !important;
        margin-top: 0 !important;
    }
}

/* ================================================================
   9. _LoginLayout.cshtml MODERN BANNER — mobile overrides
   Uses .modern-banner > .logo-container > img.protected-image
   ================================================================ */
@media (max-width: 1024px) {
    /* Ensure logo image inside modern-banner is proportional */
    .modern-banner .logo-container img,
    .modern-banner .logo-container .protected-image {
        max-height: 60px !important;
        width: auto !important;
    }

    /* Prevent banner text from overflowing */
    .modern-banner .logo-container p {
        font-size: 1.1rem !important;
        text-align: center;
    }
}

@media (max-width: 576px) {
    .modern-banner .logo-container img,
    .modern-banner .logo-container .protected-image {
        max-height: 48px !important;
    }

    .modern-banner .logo-container p {
        font-size: 0.95rem !important;
    }
}

/* ================================================================
   10. CARDS & LAYOUT COMPONENTS — common responsive fixes
   ================================================================ */
@media (max-width: 1024px) {
    /* Cards: ensure full width */
    .card {
        margin-bottom: 1rem;
        width: 100%;
    }

    /* Grid responsiveness */
    .row > [class*="col-"] {
        margin-bottom: 0.5rem;
    }

    /* Pagination: wrap and center */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Modals: reduce horizontal margin */
    .modal-dialog {
        margin: 0.5rem auto !important;
    }

    /* Badge wrapping */
    .badge {
        white-space: normal;
    }
}

@media (max-width: 576px) {
    /* Reduce heading sizes on tiny screens */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.1rem !important; }

    /* Alert text */
    .alert {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }

    /* Tables: ensure horizontal scroll.
       420px (down from 480px) reduces scroll distance on 375–414px iPhones
       while still giving columns enough space to be readable. */
    .employee-table {
        min-width: 420px;
    }

    /* Modals: explicit near-full-width on small phones to maximise usable space */
    .modal-dialog {
        max-width: calc(100% - 0.5rem) !important;
        margin: 0.25rem auto !important;
    }
}

@media (max-width: 480px) {
    /* Fix custom-select overflowing on very small phones (min-width: 200px in site.css) */
    .custom-select {
        min-width: 100% !important;
        width: 100% !important;
    }
}

/* ================================================================
   11. CIRCULARS PANEL — mobile fix
   Desktop: .circulars-toggle-button is rotated 90° and offset 70px left;
            .circulars-panel is position:absolute right:40px.
   On phones this causes the panel to float off-screen.
   Fix: stack wrapper vertically, reset button transform, make panel static.
   ================================================================ */
@media (max-width: 768px) {
    .circulars-toggle-wrapper {
        flex-direction: column !important;
        align-items: center !important;
        gap: 10px;
    }

    .circulars-toggle-button {
        position: static !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        display: flex !important;
        rotate: 0deg;
    }

    .circulars-panel {
        position: static !important;
        right: auto !important;
        top: auto !important;
        transform: none !important;
        width: 100% !important;
        min-width: unset !important;
    }
}

/* ================================================================
   12. LOW PRIORITY ENHANCEMENTS
   ================================================================ */

/* ─── 12a. Fluid Typography ──────────────────────────────────────
   dashboard.css headings have NO responsive rules — they stay at
   1.75rem / 1.5rem even on 320px phones. Add smooth clamp() scaling
   for the 576px–768px range. Below 576px the global h1/h2 rules in
   section 10 (1.5rem / 1.25rem !important) take over automatically.
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .dashboard-title h1 {
        font-size: clamp(1.35rem, 4.5vw, 1.75rem) !important;
    }

    .welcome-title h2,
    .user-identity h2 {
        font-size: clamp(1.1rem, 4vw, 1.5rem) !important;
    }

    /* Service catalog widget main heading — smooth between 768px breakpoints */
    .service-catalog-widget .widget-title h2 {
        font-size: clamp(1.25rem, 3.5vw, 2rem) !important;
    }
}

/* ─── 12b. Gap & Padding Scaling ─────────────────────────────────
   site.css .input-group keeps gap:15px / padding:20px at all sizes.
   dashboard.css welcome modal keeps padding:2rem / gap:1.5rem down
   to 320px phones. Tighten both on very small phones (≤480px).
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    /* Reduce input-group gap and padding */
    .input-group {
        gap: 10px !important;
        padding: 12px !important;
    }

    /* Welcome modal inner content padding */
    .welcome-modal-content {
        padding: 1.25rem !important;
    }

    /* Welcome sections gap and individual section padding */
    .welcome-sections {
        gap: 1rem !important;
    }

    .user-info-section,
    .auth-method-section,
    .features-section {
        padding: 1rem !important;
    }

    /* Welcome action buttons: reduce gap between stacked buttons */
    .welcome-actions {
        gap: 0.75rem !important;
    }
}

/* ─── 12c. Grid auto-fit safety at ≤360px ────────────────────────
   .user-details-grid uses minmax(200px,1fr). On 320px phones the
   available grid width (after modal + section padding) can shrink
   to ~204px — only 4px above the minimum before columns collapse
   unpredictably. Force single-column explicitly at ≤360px.
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 360px) {
    .user-details-grid {
        grid-template-columns: 1fr !important;
    }
}
