/* Responsive layout — mobile drawer nav, breakpoints, touch-friendly UI */

/* ——— Shell & overlay ——— */
.dash-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.dash-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

body.dash-nav-open {
    overflow: hidden;
}

.dash-sidebar__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.dash-sidebar__head .dash-profile {
    flex: 1;
    min-width: 0;
}

.dash-sidebar-close {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    color: #6b7280;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
}

.dash-sidebar-close:hover {
    background: #f9fafb;
    color: #111827;
}

/* ——— Mobile menu toggle ——— */
.dash-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.dash-menu-toggle__bar {
    display: block;
    width: 18px;
    height: 2px;
    background: #374151;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.dash-topbar-start {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.dash-topbar-titles {
    min-width: 0;
}

.dash-topbar-titles h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.3;
}

/* ——— Table scroll ——— */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.15rem;
    padding: 0 0.15rem;
}

.section .data-table,
.dash-table-wrap .dash-table {
    min-width: 520px;
}

/* ——— Large desktop (≥1400px) ——— */
@media (min-width: 1400px) {
    .dash-modern {
        grid-template-columns: 280px minmax(0, 1fr) 320px;
    }

    .dash-modern--home {
        grid-template-columns: clamp(248px, 16vw, 280px) minmax(0, 1fr) clamp(240px, 14vw, 300px);
    }

    .dash-modern--panel {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .dash-modern--home .dash-charts-row {
        grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
    }
}

/* ——— Laptop (1025px – 1280px) ——— */
@media (max-width: 1280px) {
    .dash-modern {
        grid-template-columns: 240px minmax(0, 1fr) 260px;
    }

    .dash-modern--home {
        grid-template-columns: clamp(210px, 20vw, 240px) minmax(0, 1fr) clamp(200px, 18vw, 248px);
    }

    .dash-modern--panel {
        grid-template-columns: 240px minmax(0, 1fr);
    }

    .dash-kpi-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ——— Tablet & mobile nav (≤1024px) ——— */
@media (max-width: 1024px) {
    .dash-menu-toggle {
        display: flex;
    }

    .dash-sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dash-modern,
    .dash-modern--panel {
        grid-template-columns: minmax(0, 1fr);
        min-height: 100vh;
    }

    .dash-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(288px, 92vw);
        max-width: 100%;
        z-index: 1050;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -8px 0 32px rgba(15, 23, 42, 0.18);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .dash-sidebar.is-open {
        transform: translateX(0);
    }

    .dash-rail--feed {
        border-right: none;
        border-top: 1px solid #e5e7eb;
        padding: 1rem;
    }

    .dash-main {
        padding: 1rem 1.15rem;
        padding-left: max(1.15rem, env(safe-area-inset-left));
        padding-right: max(1.15rem, env(safe-area-inset-right));
        min-width: 0;
    }

    .dash-charts-row,
    .dash-charts-row--bottom,
    .dash-charts-row--tables {
        grid-template-columns: 1fr;
    }

    .dash-kpi-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dash-topbar {
        align-items: flex-start;
    }

    .dash-nav-link,
    .dash-nav-summary {
        min-height: 44px;
    }
}

/* ——— Small tablet (≤768px) ——— */
@media (max-width: 768px) {
    .dash-kpi-value {
        font-size: 1.45rem;
    }

    .dash-donut-wrap {
        flex-direction: column;
        align-items: flex-start;
    }

    .dash-vbar-chart {
        height: 140px;
    }

    .dash-vbar-label {
        font-size: 0.6rem;
    }

    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .meta-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions .btn {
        text-align: center;
        justify-content: center;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar input,
    .filter-bar select,
    .filter-bar .btn {
        width: 100%;
        min-width: 0;
    }

    .login-box {
        padding: 1.5rem 1.25rem;
    }
}

/* ——— Phone (≤480px) ——— */
@media (max-width: 480px) {
    .dash-kpi-row {
        grid-template-columns: 1fr;
    }

    .dash-topbar-titles h1 {
        font-size: 1.1rem;
    }

    .dash-breadcrumb {
        font-size: 0.75rem;
    }

    .dash-main {
        padding: 0.85rem 0.75rem;
    }

    .section,
    .dash-card {
        padding: 0.85rem 0.9rem;
        border-radius: 12px;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tabs a {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .form-grid input,
    .form-grid select,
    .form-grid textarea,
    .login-box input {
        max-width: none;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .coming-soon-card {
        margin: 1rem auto;
        padding: 1.5rem 1rem;
    }
}

/* ——— Reduce motion ——— */
@media (prefers-reduced-motion: reduce) {
    .dash-sidebar,
    .dash-overlay,
    .dash-menu-toggle__bar {
        transition: none;
    }
}

/* =============================================================================
   RESPONSIVE PLATFORM — unified mobile/tablet rules for all modules
   Breakpoints: 1024 (shell) · 768 (content) · 480 (phone)
   ============================================================================= */

/* ——— Touch targets & topbar safe-area ——— */
@media (max-width: 1024px) {
    .dash-menu-toggle,
    .dash-sidebar-close,
    .dash-icon-btn {
        min-width: var(--touch-min, 44px);
        min-height: var(--touch-min, 44px);
        width: var(--touch-min, 44px);
        height: var(--touch-min, 44px);
    }

    .dash-menu-toggle {
        width: var(--touch-min, 44px);
        height: var(--touch-min, 44px);
    }

    .dash-topbar {
        padding-top: max(0.5rem, var(--safe-top));
        padding-left: max(0.75rem, var(--safe-left));
        padding-right: max(0.75rem, var(--safe-right));
    }

    .dash-topbar-end {
        gap: 0.35rem;
    }

    .btn,
    .dash-nav-link,
    .ct-hub-nav__item,
    .acct-hub-nav__item {
        min-height: var(--touch-min, 44px);
    }

    .ct-list-quick__chip,
    .ct-list-view-toggle__btn {
        min-height: 36px;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    #app-sidebar[aria-modal="true"] {
        outline: none;
    }

    #dash-main.is-inert {
        pointer-events: none;
        user-select: none;
    }
}

/* ——— Sticky hub nav on mobile ——— */
@media (max-width: 1024px) {
    .ct-hub-nav,
    .acct-hub-nav {
        position: sticky;
        top: 0;
        z-index: 20;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        padding-bottom: 0.35rem;
        margin-bottom: 0.25rem;
        mask-image: linear-gradient(to left, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    }

    .ct-hub-nav::-webkit-scrollbar,
    .acct-hub-nav::-webkit-scrollbar {
        display: none;
    }

    .ct-hub-nav__item,
    .acct-hub-nav__item {
        flex-shrink: 0;
        scroll-snap-align: start;
        white-space: nowrap;
    }

    .ct-hub-nav__item--action {
        margin-inline-start: 0;
    }

    .ct-hub-nav__divider,
    .ct-hub-nav [class*="divider"] {
        flex: 0 0 auto;
    }
}

/* ——— Guide / wizard contextual sidebar — collapsible on mobile ——— */
.guide-mobile-toggle {
    display: none;
}

@media (max-width: 1024px) {
    .guide-mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
        min-height: var(--touch-min, 44px);
        margin: 0 0 0.65rem;
        padding: 0.65rem 1rem;
        border: 1px solid #e2e8f0;
        border-radius: 14px;
        background: linear-gradient(180deg, #fff, #f8fafc);
        color: #334155;
        font-family: inherit;
        font-size: 0.85rem;
        font-weight: 700;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    }

    .guide-mobile-toggle__icon {
        width: 1.1rem;
        height: 1.1rem;
        background: center/contain no-repeat;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%234338ca' stroke-width='2'%3E%3Cpath d='M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z' stroke-linecap='round'/%3E%3C/svg%3E");
    }

    .guide-mobile-toggle.is-active {
        border-color: #a5b4fc;
        background: #eef2ff;
        color: #4338ca;
    }

    .guide-layout {
        grid-template-columns: 1fr;
    }

    .guide-layout > .guide-sidebar,
    .guide-layout > .hub-guide-aside,
    .guide-layout > aside.guide-sidebar--hub,
    .guide-layout > .tour-aside {
        display: none;
        position: static;
        max-height: none;
        overflow: visible;
        grid-template-columns: 1fr;
    }

    .guide-layout > .guide-sidebar.is-mobile-open,
    .guide-layout > .hub-guide-aside.is-mobile-open,
    .guide-layout > aside.guide-sidebar--hub.is-mobile-open,
    .guide-layout > .tour-aside.is-mobile-open {
        display: flex;
        flex-direction: column;
        gap: 0.65rem;
        margin-top: 0.25rem;
        padding: 0.75rem;
        border: 1px solid #e2e8f0;
        border-radius: 16px;
        background: #f8fafc;
    }

    .tour-layout {
        grid-template-columns: 1fr;
    }

    .tour-layout > .tour-aside:not(.is-mobile-open) {
        display: none;
    }

    .tour-layout > .tour-aside.is-mobile-open {
        display: block;
    }
}

/* ——— Wizard two-column layouts ——— */
@media (max-width: 1024px) {
    .ct-wizard-layout,
    .vc-case-wizard-layout,
    .case-wizard__layout {
        grid-template-columns: 1fr !important;
    }

    .ct-wizard-aside,
    .vc-case-wizard-aside,
    .case-wizard__aside {
        order: 2;
    }
}

/* ——— User settings layout ——— */
@media (max-width: 1024px) {
    .us-app {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .us-sidebar {
        position: static;
        padding: 0.75rem;
    }

    .us-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.35rem;
        padding-bottom: 0.15rem;
        scrollbar-width: none;
    }

    .us-nav::-webkit-scrollbar {
        display: none;
    }

    .us-nav__item {
        flex-shrink: 0;
        white-space: nowrap;
        min-height: var(--touch-min, 44px);
    }

    .us-sidebar__profile {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }
}

/* ——— Accounting layout ——— */
@media (max-width: 1024px) {
    .acct-layout {
        grid-template-columns: 1fr !important;
    }

    .acct-hub-nav__group {
        flex-shrink: 0;
    }

    .acct-hub-nav__group-items {
        flex-wrap: nowrap;
    }
}

/* ——— Universal scrollable tables ——— */
.table-responsive,
.ct-list-table-wrap,
.ct-table-wrap,
.dash-table-wrap,
[class*="-table-wrap"],
[class*="-table-scroll"],
[class*="__table-wrap"],
.fm-table-scroll,
.vs-service-table-wrap,
.staff-table-wrap,
.fin-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.section > .data-table,
.section table.data-table,
.dash-table-wrap > .dash-table,
.ct-list-table,
.ct-table,
.acct-table,
.acct-journal-table,
.vacct-coa-table,
.vacct-journals-table,
.vacct-approvals-table,
.vacct-recent__table,
.vacct-report-table,
.vacct-suppliers-table,
.fin-table,
.fin-table--premium,
.staff-table,
.staff-table--pro,
.comp-table,
.fm-table {
    min-width: min(100%, 520px);
}

@media (max-width: 768px) {
    .section > .data-table,
    .section table.data-table,
    .dash-table,
    .ct-list-table,
    .acct-table,
    .vacct-coa-table,
    .vacct-journals-table,
    .fin-table--premium,
    .staff-table--pro {
        min-width: 560px;
    }

    .data-table th,
    .data-table td,
    .ct-list-table th,
    .ct-list-table td {
        padding: 0.55rem 0.45rem;
        font-size: 0.8rem;
    }

    /* Prefer card view on list pages when available */
    [data-contract-list] [data-results-table],
    [data-passenger-list] [data-results-table],
    [data-followup-list] [data-results-table] {
        display: none !important;
    }

    [data-contract-list] [data-results-cards],
    [data-passenger-list] [data-results-cards],
    [data-followup-list] [data-results-cards] {
        display: flex !important;
    }

    [data-contract-list] .ct-list-view-toggle,
    [data-passenger-list] .ct-list-view-toggle,
    [data-followup-list] .ct-list-view-toggle {
        display: none;
    }
}

/* ——— Form grids & filters ——— */
@media (max-width: 768px) {
    .form-grid,
    .ct-form-grid,
    .case-form-grid,
    .passenger-form-grid {
        grid-template-columns: 1fr !important;
    }

    .form-row,
    .ct-form-row {
        flex-direction: column;
        align-items: stretch;
    }

    .form-row > *,
    .ct-form-row > * {
        width: 100%;
        min-width: 0;
    }

    .ct-list-hero__toolbar,
    .ct-page-head__actions,
    .dash-page-head__actions {
        width: 100%;
    }

    .ct-list-hero__toolbar .btn,
    .ct-page-head__actions .btn {
        flex: 1;
        text-align: center;
        justify-content: center;
    }

    .ct-list-search__actions {
        width: 100%;
    }

    .ct-list-search__actions .btn {
        flex: 1;
    }
}

/* ——— Page heads & sections ——— */
@media (max-width: 768px) {
    .ct-page-head,
    .dash-page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .section {
        padding: 0.85rem 0.9rem;
        border-radius: 12px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 0.4rem 0.65rem;
    }
}

/* ——— Login page ——— */
@media (max-width: 480px) {
    .login-page,
    .auth-page {
        padding: 1rem 0.75rem;
        padding-bottom: max(1rem, var(--safe-bottom));
    }
}

/* ——— Scroll hint for wide tables ——— */
@media (max-width: 768px) {
    .section:has(> .data-table),
    .ct-list-table-wrap,
    .dash-table-wrap {
        position: relative;
    }

    .section:has(> .data-table)::after,
    .ct-list-table-wrap::after {
        content: "← اسکرول افقی →";
        display: block;
        text-align: center;
        font-size: 0.65rem;
        color: #94a3b8;
        padding: 0.35rem 0;
        pointer-events: none;
    }
}
