/*
 * ═══════════════════════════════════════════════════════════════
 *  CRM Responsive System — shared across all dashboard pages
 *  Version: 3.0 — Mobile-First
 * ═══════════════════════════════════════════════════════════════
 */

/* ─── 0. GLOBAL OVERFLOW LOCK — prevent horizontal scroll on mobile ── */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* ─── 1. HAMBURGER TOGGLE BUTTON ─────────────────────────────── */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 200;
    background: var(--primary, #4f8ef7);
    border: none;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    color: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
    transition: transform .15s;
}

.menu-toggle:active {
    transform: scale(.92);
}

.menu-toggle svg {
    width: 20px;
    height: 20px;
}

/* ─── 2. SIDEBAR OVERLAY ──────────────────────────────────────── */
.sb-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    z-index: 998;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
}

.sb-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* ─── 3. SKELETON LOADING ─────────────────────────────────────── */
.skeleton-wrap {
    padding: .5rem 0;
}

.skeleton-row {
    height: 48px;
    background: linear-gradient(90deg, #f0f4f8 25%, #e2e8f0 50%, #f0f4f8 75%);
    background-size: 800px 100%;
    border-radius: 8px;
    margin-bottom: 8px;
    animation: shimmer 1.5s infinite;
}

.skeleton-row:nth-child(2) {
    opacity: .75;
    width: 90%;
}

.skeleton-row:nth-child(3) {
    opacity: .5;
    width: 80%;
}

@keyframes shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

/* ─── 4. STAT CARD ENHANCEMENT ───────────────────────────────── */
.sc-hint,
.scard-hint {
    font-size: .68rem;
    color: inherit;
    opacity: 0;
    transition: opacity .2s;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.sc.clickable,
.scard.clickable {
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.sc.clickable::after,
.scard.clickable::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, .04);
    opacity: 0;
    transition: opacity .2s;
}

.sc.clickable:hover::after,
.scard.clickable:hover::after {
    opacity: 1;
}

.sc.clickable:hover .sc-hint,
.scard.clickable:hover .scard-hint {
    opacity: .75;
}

.sc.clickable:hover,
.scard.clickable:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .1);
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box i {
    position: absolute;
    right: 10px;
    pointer-events: none;
}
.search-box input {
    padding-right: 34px !important;
    min-width: 220px;
}

/* PAGINATION */
.search-hidden { display: none !important; }
.pagination-controls { padding: 1rem 0; display: flex; align-items: center; justify-content: center; border-top: 1px solid var(--border); }

/* IFRAME MODAL GLOBALS */
.iframe-modal-bg {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.6);
    z-index: 9999; align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.iframe-modal-bg.open { display: flex; }
.iframe-modal {
    background: #f8fafc; border-radius: 16px; width: 95%; max-width: 1000px; height: 90vh;
    overflow: hidden; display: flex; flex-direction: column; animation: pop .22s ease;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.iframe-modal-hdr {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem; border-bottom: 1px solid #e2e8f0; background: #fff;
}
.iframe-modal iframe { flex: 1; width: 100%; border: none; background: #f8fafc; }

/* ─── 5. REFRESH BUTTON SPIN ──────────────────────────────────── */
.btn-refresh svg.spinning {
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── 6. TRANSACTION DETAIL MODAL ────────────────────────────── */
.detail-modal .modal {
    max-width: 680px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: #f8fafc;
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.detail-field .df-label {
    display: block;
    font-size: .72rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 4px;
}

.detail-field .df-value {
    font-size: .93rem;
    font-weight: 600;
    color: #1e293b;
}

.detail-field.df-full {
    grid-column: 1 / -1;
}

/* Status Tracker */
.tracker {
    display: flex;
    align-items: center;
    margin: 1.25rem 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
}

.step-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .83rem;
    z-index: 2;
    border: 3px solid;
    transition: all .3s;
}

.step-dot.done {
    background: #10b981;
    border-color: #10b981;
    color: #fff;
}

.step-dot.active {
    background: var(--primary, #4f8ef7);
    border-color: var(--primary, #4f8ef7);
    color: #fff;
}

.step-dot.pending {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #94a3b8;
}

.step-label {
    font-size: .7rem;
    color: #64748b;
    margin-top: 6px;
    text-align: center;
}

.step-line {
    position: absolute;
    top: 15px;
    width: 100%;
    height: 3px;
    right: -50%;
    z-index: 1;
}

.step-line.done {
    background: #10b981;
}

.step-line.pending {
    background: #e2e8f0;
}

.step:first-child .step-line {
    display: none;
}

/* ─── 7. EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: #94a3b8;
}

.empty-state .empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.25rem;
    background: #f1f5f9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state .empty-icon svg {
    width: 28px;
    height: 28px;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: .4rem;
}

.empty-state p {
    font-size: .88rem;
}

/* ─── 8. COUNTER ANIMATION ────────────────────────────────────── */
.count-anim {
    display: inline-block;
    transition: transform .15s ease;
}

.count-anim.bump {
    transform: scale(1.25);
}

/* ─── 9. LAST UPDATED BADGE ───────────────────────────────────── */
.last-updated {
    font-size: .72rem;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

.last-updated svg {
    width: 11px;
    height: 11px;
}

/* ─── 10. RESPONSIVE BREAKPOINTS ─────────────────────────────── */

/* Tablet */
@media (max-width: 1024px) {
    .g2, .g3 { grid-template-columns: 1fr !important; }
}

/* ══════════════════════════════════════════════════
   Mobile ≤ 768px
══════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Hamburger ── */
    .menu-toggle { display: flex; z-index: 1000; }

    /* ── Sidebar: off-screen by default ── */
    .sb {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        height: 100vh !important;
        width: 280px !important;
        transform: translateX(110%) !important;   /* 110% to guarantee fully off-screen */
        transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 999 !important;
        overflow: hidden !important;
        box-shadow: none !important;
    }
    .sb.open {
        transform: translateX(0) !important;
        box-shadow: -6px 0 28px rgba(0, 0, 0, .2) !important;
    }

    /* ── Main: full width ── */
    .main {
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* ── Header ── */
    .top {
        padding: 0 0.9rem !important;
        padding-right: 62px !important;
        height: 56px !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, .06) !important;
    }
    .top-title { font-size: 0.97rem !important; }
    .top-right { gap: 0.5rem !important; }
    #uinfo, .dept-pill, .rt-badge { display: none !important; }
    .avatar { width: 34px !important; height: 34px !important; font-size: 0.82rem !important; }

    /* ── Content ── */
    .content { padding: 0.85rem !important; max-width: 100% !important; }
    .card { padding: 0.9rem !important; margin-bottom: 1rem !important; }

    /* ── Stats: always 2-column ── */
    .stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.65rem !important;
        margin-bottom: 1.1rem !important;
    }
    .sc, .scard {
        padding: 0.8rem 0.85rem !important;
        gap: 0.65rem !important;
        flex-direction: row !important;
        align-items: center !important;
        border-radius: 10px !important;
    }
    .sv, .sval { font-size: 1.4rem !important; line-height: 1 !important; }
    .sl, .slbl { font-size: 0.73rem !important; margin-top: 2px !important; }
    .si, .sico {
        width: 36px !important; height: 36px !important;
        flex-shrink: 0 !important; border-radius: 8px !important;
    }
    .si svg, .sico svg { width: 15px !important; height: 15px !important; }
    .sc-hint, .scard-hint { display: none !important; }

    /* ── Section header ── */
    .sec-hdr {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.6rem !important;
        margin-bottom: 0.9rem !important;
    }
    .sec-hdr h2 { font-size: 1.15rem !important; margin: 0 !important; }
    .sec-hdr p { font-size: 0.81rem !important; margin: 0 !important; }

    /* ── Touch targets: 44px ── */
    .btn, .fc, select, select.fc {
        min-height: 44px !important;
        font-size: 0.92rem !important;
    }
    textarea.fc { min-height: 80px !important; }
    .btn {
        height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 1rem !important;
        border-radius: 10px !important;
    }
    .btn-sm {
        height: 38px !important;
        min-height: 38px !important;
        padding: 0 0.75rem !important;
        font-size: 0.81rem !important;
    }

    /* ── Forms ── */
    .fg { margin-bottom: 0.9rem !important; }
    .fg-row { grid-template-columns: 1fr !important; }
    .g2 { grid-template-columns: 1fr !important; }

    /* ── Detail grid ── */
    .detail-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.6rem !important;
        padding: 0.9rem !important;
    }
    .detail-field .df-label { font-size: 0.65rem !important; }
    .detail-field .df-value { font-size: 0.86rem !important; }

    /* ── Modals: bottom sheet & Iframe Modals ── */
    .modal-bg {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .modal {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 1.4rem 1.1rem 1.8rem !important;
        border-radius: 18px 18px 0 0 !important;
        max-height: 88vh !important;
        overflow-y: auto !important;
        animation: slideUp .22s ease !important;
    }
    .iframe-modal-bg {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .iframe-modal {
        max-width: 100% !important;
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        animation: slideUp .22s ease !important;
    }
    @keyframes slideUp {
        from { transform: translateY(40px); opacity: 0; }
        to   { transform: translateY(0);   opacity: 1; }
    }
    .mhdr { margin-bottom: 1.1rem !important; }
    .mtitle { font-size: 1rem !important; }
    #md-actions { gap: 0.65rem !important; flex-wrap: wrap !important; }

    /* ── Tables: horizontal scroll with card rows ── */
    .tw {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        margin: 0 -0.9rem !important;
        padding: 0 0.9rem 0.6rem !important;
    }
    .tw::-webkit-scrollbar { display: none; }

    .tw table {
        border-collapse: separate !important;
        border-spacing: 0 0.45rem !important;
        white-space: nowrap !important;
        width: 100% !important;
    }

    /* thead transparent */
    .tw thead tr {
        background: transparent !important;
        box-shadow: none !important;
    }
    .tw th {
        border: none !important;
        padding: 0.25rem 0.8rem !important;
        font-size: 0.7rem !important;
        color: #94a3b8 !important;
        background: transparent !important;
        white-space: nowrap !important;
    }

    /* tbody rows = floating cards */
    .tw tbody tr {
        background: #fff !important;
        border-radius: 10px !important;
        box-shadow: 0 1px 5px rgba(0, 0, 0, .07) !important;
        transition: transform .15s !important;
    }
    .tw tbody tr:hover td { background: transparent !important; }
    .tw tbody tr:active { transform: scale(0.983) !important; }
    .tw tbody tr.overdue td { background: #fef2f2 !important; }

    .tw tbody td {
        border: none !important;
        padding: 0.75rem 0.8rem !important;
        font-size: 0.84rem !important;
        background: transparent !important;
        vertical-align: middle !important;
        white-space: nowrap !important;
    }
    /* RTL: first = right edge, last = left edge */
    .tw tbody td:first-child {
        border-top-right-radius: 10px !important;
        border-bottom-right-radius: 10px !important;
    }
    .tw tbody td:last-child {
        border-top-left-radius: 10px !important;
        border-bottom-left-radius: 10px !important;
    }

    /* table action buttons */
    .tw .btn, .tw .btn-sm {
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 0.7rem !important;
        font-size: 0.79rem !important;
    }

    /* ── Hide secondary columns ── */
    .hide-mobile { display: none !important; }

    /* ── Tracker compact ── */
    .tracker { margin: 0.7rem 0 !important; }
    .step-dot {
        width: 24px !important; height: 24px !important;
        font-size: 0.68rem !important; border-width: 2px !important;
    }
    .step-label { font-size: 0.6rem !important; margin-top: 3px !important; }
    .step-line { top: 11px !important; height: 2px !important; }
}

/* ══════════════════════════════════════════════════
   Small Mobile ≤ 480px
══════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .stats { grid-template-columns: repeat(2, 1fr) !important; }
    .detail-grid { grid-template-columns: 1fr !important; }
    .sec-hdr h2 { font-size: 1.05rem !important; }
    .hero h1 { font-size: 1.2rem !important; }
    .hero-stats { gap: 0.65rem !important; }
    .hero-stat strong { font-size: 1.15rem !important; }
    .auth-card { padding: 1.4rem 1rem !important; }
}
