/* Portal mobile shell — Candidate / Company / Admin
   Desktop (≥768px): unchanged source layout
   Mobile: off-canvas sidebar + bottom nav + safe padding

   z-index stack (mobile):
     mheader 45 → bottom-nav 50 → overlay 55 → sidebar 60 → modals/toasts 70+
*/
.portal-mheader,
.portal-overlay,
.portal-bottom-nav { display: none; }

@media (max-width: 767.98px) {
    body.portal-mobile-active { padding-bottom: 0; overflow-x: clip; }
    body.portal-sidebar-lock { overflow: hidden; touch-action: none; }

    .portal-mheader {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 45;
        background: #0f172a;
        color: #fff;
        padding: 0.65rem 0.85rem;
        min-height: 3.25rem;
        border-bottom: 1px solid rgba(251, 191, 36, 0.35);
    }
    .portal-mheader .portal-mbtn {
        width: 2.5rem;
        height: 2.5rem;
        border-radius: 0.65rem;
        background: #1e293b;
        color: #fbbf24;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        border: 1px solid #334155;
    }
    .portal-mheader .portal-mbtn-menu { order: 0; }

    .portal-mheader .portal-mtitle {
        flex: 1;
        min-width: 0;
        font-size: 0.875rem;
        font-weight: 700;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .portal-mheader .portal-msub {
        display: block;
        font-size: 0.65rem;
        font-weight: 500;
        color: #94a3b8;
        margin-top: 0.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .portal-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 55;
        backdrop-filter: blur(2px);
    }
    .portal-shell.sidebar-open .portal-overlay { display: block; }

    .portal-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 20rem);
        z-index: 60;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: #fff;
        box-shadow: 8px 0 24px rgba(0,0,0,0.18);
        padding: 0.75rem !important;
        margin: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        max-height: 100dvh;
    }
    .portal-shell.sidebar-open .portal-sidebar {
        transform: translateX(0);
    }
    .portal-sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.35rem 0.25rem 0.85rem;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 0.75rem;
    }
    .portal-sidebar-head strong {
        font-size: 0.85rem;
        color: #0f172a;
    }
    .portal-sidebar-close {
        width: 2.25rem;
        height: 2.25rem;
        border-radius: 9999px;
        background: #f1f5f9;
        color: #334155;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide desktop-only column framing on mobile; content full width */
    .portal-shell > .portal-frame,
    .portal-shell .portal-frame {
        display: block !important;
    }
    .portal-shell .portal-content {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        min-width: 0;
    }
    .portal-shell,
    .portal-shell .portal-frame,
    .portal-shell .max-w-4xl {
        max-width: 100% !important;
        overflow-x: clip;
    }

    .portal-bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        background: #fff;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
        padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
        justify-content: space-around;
        align-items: stretch;
    }
    .portal-bottom-nav a,
    .portal-bottom-nav button.portal-bnav-more {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        min-height: 3.35rem;
        min-width: 0;
        padding: 0.25rem 0.1rem;
        font-size: 0.62rem;
        font-weight: 700;
        color: #64748b;
        text-decoration: none;
        border-radius: 0.65rem;
        line-height: 1.1;
        text-align: center;
        border: 0;
        background: transparent;
        font-family: inherit;
    }
    .portal-bottom-nav a span,
    .portal-bottom-nav button.portal-bnav-more span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .portal-bottom-nav a i,
    .portal-bottom-nav button.portal-bnav-more i {
        font-size: 1.05rem;
        line-height: 1;
    }
    .portal-bottom-nav a.active,
    .portal-bottom-nav button.portal-bnav-more.active {
        color: #0f172a;
        background: #fffbeb;
    }
    .portal-bottom-nav a.active i,
    .portal-bottom-nav button.portal-bnav-more.active i { color: #d97706; }

    /* Content clearance above bottom nav */
    .portal-shell .portal-content,
    .portal-shell > .bg-white,
    body.portal-mobile-active main {
        padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    body.portal-mobile-active footer {
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    }

    /* Tables: contained scroll, no page overflow */
    .portal-shell .overflow-x-auto,
    .admin-content-panel .overflow-x-auto,
    .dash-panel .overflow-x-auto,
    .cdash-panel .overflow-x-auto {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .portal-shell .overflow-x-auto table {
        min-width: 36rem;
    }
    .portal-shell table {
        max-width: 100%;
    }
    .portal-shell td,
    .portal-shell th {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Forms / wizards */
    .portal-shell input,
    .portal-shell select,
    .portal-shell textarea,
    .portal-shell button {
        max-width: 100%;
    }
    .portal-shell input[type="text"],
    .portal-shell input[type="email"],
    .portal-shell input[type="tel"],
    .portal-shell input[type="url"],
    .portal-shell input[type="search"],
    .portal-shell input[type="number"],
    .portal-shell input[type="date"],
    .portal-shell input[type="password"],
    .portal-shell select,
    .portal-shell textarea {
        box-sizing: border-box;
        width: 100%;
    }
    #companyStepper,
    #jobStepper,
    .job-stepper,
    [id*="job-step"] .flex.items-center {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 0.25rem;
        padding-bottom: 0.25rem;
        max-width: 100%;
    }
    #companyStepper .step-label,
    .company-step-pill .step-label,
    #jobStepper .job-step-pill {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Long text / filenames / emails */
    .portal-shell,
    .portal-shell a,
    .portal-shell p,
    .portal-shell h1,
    .portal-shell h2,
    .portal-shell h3,
    .portal-shell td,
    .portal-shell li {
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .portal-shell img {
        max-width: 100%;
    }

    /* CV preview: readable scrollable A4 (not unreadably shrunk) */
    #cv-preview-modal {
        z-index: 70 !important;
        padding: 0.5rem !important;
        align-items: flex-end !important;
    }
    #cv-preview-modal > div {
        width: calc(100vw - 1rem) !important;
        max-width: calc(100vw - 1rem) !important;
        max-height: calc(100dvh - 1rem) !important;
        overflow: auto !important;
        margin: 0.5rem !important;
    }
    #cv-preview-modal .flex.justify-center.bg-slate-100 {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start !important;
        padding: 0.75rem !important;
    }
    #cv-preview-content {
        width: 210mm !important;
        max-width: none !important;
        transform: none !important;
        margin-bottom: 0 !important;
        flex-shrink: 0;
    }
    #cv-preview-modal .p-5.border-t {
        flex-wrap: wrap;
        position: sticky;
        bottom: 0;
    }
    #cv-preview-modal .p-5.border-t > * {
        flex: 1 1 8rem;
        min-width: 0;
    }

    /* Modals above bottom nav — default sheet; auth popups stay centered */
    [id$="-modal"],
    #comp-subscription-plans-modal {
        z-index: 70 !important;
        padding: 0.5rem !important;
        align-items: flex-end !important;
    }
    #signin-modal,
    #create-account-modal,
    #forgot-password-modal,
    #apply-modal {
        align-items: center !important;
        justify-content: center !important;
        padding: 1rem !important;
    }
    [id$="-modal"] > div,
    #comp-subscription-plans-modal > div {
        max-width: 100% !important;
        max-height: min(92dvh, 100%) !important;
        overflow-y: auto !important;
        border-radius: 1rem 1rem 0.5rem 0.5rem !important;
        margin-bottom: env(safe-area-inset-bottom, 0px);
    }
    #signin-modal > div,
    #create-account-modal > div,
    #forgot-password-modal > div,
    #apply-modal > div {
        border-radius: 1rem !important;
        margin-bottom: 0 !important;
        margin-top: 0 !important;
        max-height: min(88dvh, 100%) !important;
    }
    [id$="-modal"] .flex.gap-3,
    [id$="-modal"] .flex.gap-2 {
        flex-wrap: wrap;
    }

    /* Compact panel headers inside cards */
    .portal-shell .bg-slate-900.text-white.p-6 {
        padding: 1rem !important;
    }
    .portal-shell .p-6 {
        padding: 0.85rem !important;
    }

    /* Action button rows — wrap, touch-friendly */
    .portal-shell .flex.gap-1\.5,
    .portal-shell .flex.gap-2,
    .portal-shell .company-filter-item .flex {
        flex-wrap: wrap;
    }
    .portal-shell .company-filter-item button,
    .portal-shell .company-filter-item a.border,
    .portal-shell .company-filter-item a.bg-amber-500,
    .portal-shell .company-filter-item a.bg-slate-900,
    .portal-shell .dash-panel button[type="submit"],
    .portal-shell .cdash-panel button[type="submit"],
    .portal-shell .cdash-panel a.hover\:underline {
        min-height: 2.25rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Toolbars / filters stack */
    .portal-shell .company-panel-tools,
    .jobs-toolbar {
        max-width: 100%;
    }

    /* Toasts */
    .toast, [class*="toast"], #toast-container, .fixed.top-4.right-4 {
        max-width: calc(100vw - 1.5rem) !important;
        left: 0.75rem !important;
        right: 0.75rem !important;
        z-index: 80 !important;
        word-break: break-word;
    }
}

@media (min-width: 768px) {
    .portal-mheader,
    .portal-overlay,
    .portal-bottom-nav,
    .portal-sidebar-head { display: none !important; }
    .portal-sidebar {
        position: static !important;
        transform: none !important;
        width: auto !important;
        max-height: none !important;
        box-shadow: none !important;
        overflow: visible !important;
    }
}

/* Landscape phones: keep bottom nav compact */
@media (max-width: 767.98px) and (orientation: landscape) {
    .portal-bottom-nav {
        padding-top: 0.2rem;
        padding-bottom: calc(0.2rem + env(safe-area-inset-bottom, 0px));
    }
    .portal-bottom-nav a,
    .portal-bottom-nav button.portal-bnav-more {
        min-height: 2.75rem;
        font-size: 0.58rem;
    }
    .portal-sidebar {
        max-height: 100dvh;
    }
}
