/**
 * AST Case Manager - Mobile App Experience
 * Modern Finance Mobile UI
 * Version: 4.0.0
 */

/* ========================================
   MOBILE VARIABLES
   ======================================== */
:root {
    --mobile-header-height: 56px;
    --mobile-nav-height: 60px;
    --mobile-card-gap: 10px;
    --mobile-padding: 16px;
    --mobile-radius: 12px;
    --mobile-shadow: 0 2px 8px rgba(0,0,0,0.2);
    --mobile-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   MOBILE CONTAINER (768px and below)
   ======================================== */
@media screen and (max-width: 768px) {

    /* Hide Desktop Elements */
    #wpadminbar,
    #adminmenuwrap,
    #adminmenuback,
    .update-nag,
    .notice:not(.mobile-notice) {
        display: none !important;
    }

    body.mobile-app {
        margin: 0 !important;
        padding: 0 !important;
        background: var(--ast-bg-primary, #0f172a) !important;
        min-height: 100vh;
        overflow-x: hidden;
        -webkit-font-smoothing: antialiased;
    }

    .mobile-app-container {
        width: 100vw !important;
        min-height: 100vh;
        margin: 0 !important;
        padding: 0 !important;
        position: relative;
        background: var(--ast-bg-primary, #0f172a);
    }

    /* ========================================
       MOBILE HEADER
       ======================================== */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--mobile-header-height);
        background: var(--ast-bg-secondary, #1e293b);
        border-bottom: 1px solid var(--ast-border, #334155);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 var(--mobile-padding);
        z-index: 1000;
        box-shadow: var(--mobile-shadow);
    }

    .mobile-header-title {
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 17px;
        font-weight: 600;
        flex: 1;
        text-align: center;
        letter-spacing: -0.01em;
    }

    .mobile-menu-btn,
    .mobile-search-btn {
        width: 38px;
        height: 38px;
        border: none;
        background: var(--ast-bg-tertiary, #334155);
        border-radius: 10px;
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 18px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: var(--mobile-transition);
    }

    .mobile-menu-btn:active,
    .mobile-search-btn:active {
        transform: scale(0.95);
        background: var(--ast-bg-hover, #283548);
    }

    /* ========================================
       MOBILE CONTENT
       ======================================== */
    .mobile-content {
        padding-top: var(--mobile-header-height);
        padding-bottom: var(--mobile-nav-height);
        min-height: 100vh;
    }

    .mobile-page {
        padding: var(--mobile-padding);
        padding-bottom: 20px;
    }

    /* ========================================
       MOBILE CARDS
       ======================================== */
    .mobile-card {
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        border-radius: var(--mobile-radius);
        padding: 16px;
        margin-bottom: var(--mobile-card-gap);
        transition: var(--mobile-transition);
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .mobile-card:active {
        transform: scale(0.98);
        background: var(--ast-bg-hover, #283548);
    }

    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
    }

    .mobile-card-title {
        font-size: 15px;
        font-weight: 600;
        color: var(--ast-text-primary, #f1f5f9);
        flex: 1;
    }

    .mobile-card-badge {
        padding: 4px 10px;
        border-radius: 8px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

    .badge-success {
        background: var(--ast-success-bg, rgba(16, 185, 129, 0.1));
        color: var(--ast-success, #10b981);
    }

    .badge-warning {
        background: var(--ast-warning-bg, rgba(245, 158, 11, 0.1));
        color: var(--ast-warning, #f59e0b);
    }

    .badge-danger {
        background: var(--ast-danger-bg, rgba(239, 68, 68, 0.1));
        color: var(--ast-danger, #ef4444);
    }

    .mobile-card-body {
        color: var(--ast-text-secondary, #94a3b8);
        font-size: 14px;
        line-height: 1.5;
    }

    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid var(--ast-border-light, rgba(148, 163, 184, 0.1));
    }

    .mobile-card-row:last-child {
        border-bottom: none;
    }

    .mobile-card-label {
        color: var(--ast-text-secondary, #94a3b8);
        font-size: 13px;
    }

    .mobile-card-value {
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 14px;
        font-weight: 500;
        text-align: right;
    }

    .mobile-card-actions {
        display: flex;
        gap: 8px;
        padding: 12px 0 0;
        border-top: 1px solid var(--ast-border-light, rgba(148, 163, 184, 0.1));
        margin-top: 8px;
        flex-wrap: wrap;
    }

    .mobile-card-actions button,
    .mobile-card-actions a,
    .mobile-card-actions form {
        font-size: 13px;
    }

    /* ========================================
       MOBILE STATS
       ======================================== */
    .mobile-stats-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--mobile-card-gap);
        margin-bottom: 20px;
    }

    .mobile-stat-card {
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        border-radius: var(--mobile-radius);
        padding: 16px;
        text-align: center;
        position: relative;
        overflow: hidden;
    }

    .mobile-stat-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: var(--ast-accent, #3b82f6);
    }

    .mobile-stat-card:nth-child(2)::before { background: var(--ast-success, #10b981); }
    .mobile-stat-card:nth-child(3)::before { background: var(--ast-warning, #f59e0b); }
    .mobile-stat-card:nth-child(4)::before { background: var(--ast-danger, #ef4444); }

    .mobile-stat-value {
        font-size: 26px;
        font-weight: 700;
        margin-bottom: 4px;
        color: var(--ast-text-primary, #f1f5f9);
        font-family: var(--ast-font-mono, monospace);
    }

    .mobile-stat-label {
        font-size: 11px;
        color: var(--ast-text-secondary, #94a3b8);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: 500;
    }

    /* ========================================
       MOBILE LIST VIEW
       ======================================== */
    .mobile-list {
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        border-radius: var(--mobile-radius);
        overflow: hidden;
    }

    .mobile-list-item {
        padding: 14px 16px;
        border-bottom: 1px solid var(--ast-border-light, rgba(148, 163, 184, 0.1));
        position: relative;
        transition: var(--mobile-transition);
    }

    .mobile-list-item:active {
        background: var(--ast-bg-hover, #283548);
    }

    .mobile-list-item:last-child {
        border-bottom: none;
    }

    .mobile-list-primary {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 6px;
    }

    .mobile-list-title {
        font-size: 14px;
        font-weight: 600;
        color: var(--ast-text-primary, #f1f5f9);
        flex: 1;
    }

    .mobile-list-amount {
        font-size: 15px;
        font-weight: 700;
        color: var(--ast-accent, #3b82f6);
        font-family: var(--ast-font-mono, monospace);
    }

    .mobile-list-secondary {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        color: var(--ast-text-secondary, #94a3b8);
    }

    .mobile-list-meta {
        display: flex;
        gap: 12px;
    }

    .mobile-list-meta-item {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    /* ========================================
       MOBILE FAB
       ======================================== */
    .mobile-fab {
        position: fixed;
        bottom: calc(var(--mobile-nav-height) + 16px);
        right: 16px;
        width: 52px;
        height: 52px;
        border-radius: 14px;
        background: var(--ast-accent, #3b82f6);
        color: white;
        border: none;
        font-size: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
        cursor: pointer;
        transition: var(--mobile-transition);
        z-index: 900;
    }

    .mobile-fab:active {
        transform: scale(0.92);
    }

    .mobile-fab-extended {
        width: auto;
        padding: 0 20px;
        border-radius: 14px;
        font-size: 14px;
        font-weight: 600;
        gap: 8px;
    }

    /* ========================================
       MOBILE BOTTOM NAV
       ======================================== */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-nav-height);
        background: var(--ast-bg-secondary, #1e293b);
        border-top: 1px solid var(--ast-border, #334155);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 1000;
    }

    .mobile-nav-item {
        flex: 1;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--ast-text-muted, #64748b);
        text-decoration: none;
        transition: var(--mobile-transition);
        position: relative;
        cursor: pointer;
    }

    .mobile-nav-item.active {
        color: var(--ast-accent, #3b82f6);
    }

    .mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 2px;
        background: var(--ast-accent, #3b82f6);
        border-radius: 1px;
    }

    .mobile-nav-icon {
        font-size: 20px;
        margin-bottom: 3px;
    }

    .mobile-nav-label {
        font-size: 10px;
        font-weight: 500;
    }

    /* ========================================
       MOBILE TABS
       ======================================== */
    .mobile-tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -16px 16px;
        padding: 0 16px;
        gap: 8px;
    }

    .mobile-tabs::-webkit-scrollbar {
        display: none;
    }

    .mobile-tab {
        padding: 8px 16px;
        background: var(--ast-bg-tertiary, #334155);
        border-radius: 8px;
        color: var(--ast-text-secondary, #94a3b8);
        white-space: nowrap;
        font-size: 13px;
        font-weight: 500;
        transition: var(--mobile-transition);
        cursor: pointer;
        flex-shrink: 0;
        border: 1px solid transparent;
    }

    .mobile-tab.active {
        background: var(--ast-accent-light, rgba(59, 130, 246, 0.1));
        color: var(--ast-accent, #3b82f6);
        border-color: var(--ast-accent, #3b82f6);
    }

    /* ========================================
       MOBILE SEARCH
       ======================================== */
    .mobile-search {
        padding: 0 var(--mobile-padding);
        margin-bottom: 16px;
    }

    .mobile-search-input {
        width: 100%;
        padding: 11px 16px;
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        border-radius: var(--mobile-radius);
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 14px;
        transition: var(--mobile-transition);
    }

    .mobile-search-input:focus {
        outline: none;
        border-color: var(--ast-accent, #3b82f6);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .mobile-search-input::placeholder {
        color: var(--ast-text-muted, #64748b);
    }

    /* ========================================
       MOBILE FILTER CHIPS
       ======================================== */
    .mobile-filter-chips {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 var(--mobile-padding);
        margin-bottom: 14px;
    }

    .mobile-filter-chips::-webkit-scrollbar {
        display: none;
    }

    .mobile-filter-chip {
        padding: 6px 14px;
        background: var(--ast-bg-tertiary, #334155);
        border: 1px solid var(--ast-border, #334155);
        border-radius: 8px;
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 13px;
        white-space: nowrap;
        transition: var(--mobile-transition);
        cursor: pointer;
        flex-shrink: 0;
    }

    .mobile-filter-chip.active {
        background: var(--ast-accent-light, rgba(59, 130, 246, 0.1));
        border-color: var(--ast-accent, #3b82f6);
        color: var(--ast-accent, #3b82f6);
    }

    /* ========================================
       MOBILE FORMS
       ======================================== */
    .mobile-form {
        padding: var(--mobile-padding);
    }

    .mobile-form-group {
        margin-bottom: 18px;
    }

    .mobile-form-label {
        display: block;
        color: var(--ast-text-secondary, #94a3b8);
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 8px;
    }

    .mobile-form-input,
    .mobile-form-select,
    .mobile-form-textarea {
        width: 100%;
        padding: 12px;
        background: var(--ast-bg-primary, #0f172a);
        border: 1px solid var(--ast-border, #334155);
        border-radius: 8px;
        color: var(--ast-text-primary, #f1f5f9);
        font-size: 14px;
        transition: var(--mobile-transition);
    }

    .mobile-form-input:focus,
    .mobile-form-select:focus,
    .mobile-form-textarea:focus {
        outline: none;
        border-color: var(--ast-accent, #3b82f6);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .mobile-form-button {
        width: 100%;
        padding: 14px;
        background: var(--ast-accent, #3b82f6);
        border: none;
        border-radius: 10px;
        color: white;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: var(--mobile-transition);
    }

    .mobile-form-button:active {
        transform: scale(0.98);
        background: var(--ast-accent-hover, #2563eb);
    }

    /* ========================================
       MOBILE MODAL (Bottom Sheet)
       ======================================== */
    .mobile-modal {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--ast-bg-secondary, #1e293b);
        border-radius: var(--mobile-radius) var(--mobile-radius) 0 0;
        padding: 20px;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2000;
        max-height: 90vh;
        overflow-y: auto;
        border-top: 1px solid var(--ast-border, #334155);
    }

    .mobile-modal.active {
        transform: translateY(0);
    }

    .mobile-modal-handle {
        width: 36px;
        height: 4px;
        background: var(--ast-bg-tertiary, #334155);
        border-radius: 2px;
        margin: 0 auto 16px;
    }

    .mobile-modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
        z-index: 1999;
        backdrop-filter: blur(4px);
    }

    .mobile-modal-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* ========================================
       MOBILE SKELETON LOADING
       ======================================== */
    .mobile-skeleton {
        background: linear-gradient(90deg,
            var(--ast-bg-tertiary, #334155) 25%,
            var(--ast-bg-hover, #283548) 50%,
            var(--ast-bg-tertiary, #334155) 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 4px;
    }

    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }

    .mobile-skeleton-card {
        height: 100px;
        margin-bottom: var(--mobile-card-gap);
        border-radius: var(--mobile-radius);
    }

    .mobile-skeleton-text {
        height: 14px;
        margin-bottom: 8px;
    }

    .mobile-skeleton-text.w-50 { width: 50%; }
    .mobile-skeleton-text.w-75 { width: 75%; }

    /* ========================================
       MOBILE EMPTY STATE
       ======================================== */
    .mobile-empty-state {
        text-align: center;
        padding: 48px 24px;
        color: var(--ast-text-secondary, #94a3b8);
    }

    .mobile-empty-icon {
        font-size: 48px;
        opacity: 0.4;
        margin-bottom: 16px;
    }

    .mobile-empty-title {
        font-size: 17px;
        font-weight: 600;
        color: var(--ast-text-primary, #f1f5f9);
        margin-bottom: 8px;
    }

    .mobile-empty-desc {
        font-size: 14px;
        line-height: 1.5;
    }

    /* ========================================
       MOBILE TOAST
       ======================================== */
    .mobile-toast {
        position: fixed;
        bottom: calc(var(--mobile-nav-height) + 16px);
        left: 50%;
        transform: translateX(-50%) translateY(80px);
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        padding: 10px 18px;
        border-radius: 10px;
        box-shadow: var(--ast-shadow-lg, 0 8px 24px rgba(0,0,0,0.3));
        display: flex;
        align-items: center;
        gap: 8px;
        z-index: 3000;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-toast.show {
        transform: translateX(-50%) translateY(0);
    }

    .mobile-toast-icon {
        font-size: 16px;
    }

    .mobile-toast-text {
        font-size: 14px;
        color: var(--ast-text-primary, #f1f5f9);
        font-weight: 500;
    }

    /* ========================================
       PULL TO REFRESH
       ======================================== */
    .pull-to-refresh {
        position: fixed;
        top: var(--mobile-header-height);
        left: 50%;
        transform: translateX(-50%) translateY(-100%);
        width: 36px;
        height: 36px;
        background: var(--ast-bg-secondary, #1e293b);
        border: 1px solid var(--ast-border, #334155);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform 0.3s;
        z-index: 999;
        box-shadow: var(--mobile-shadow);
    }

    .pull-to-refresh.visible {
        transform: translateX(-50%) translateY(10px);
    }

    .pull-to-refresh.refreshing {
        animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
        from { transform: translateX(-50%) translateY(10px) rotate(0deg); }
        to { transform: translateX(-50%) translateY(10px) rotate(360deg); }
    }

    /* ========================================
       HIDE TABLES ON MOBILE (use card view)
       ======================================== */
    .wp-list-table,
    table.widefat {
        display: none !important;
    }

    /* ========================================
       UTILITY CLASSES
       ======================================== */
    .mobile-only { display: block !important; }
    .desktop-only { display: none !important; }
    .mobile-text-center { text-align: center !important; }

    .mobile-mt-1 { margin-top: 8px !important; }
    .mobile-mt-2 { margin-top: 16px !important; }
    .mobile-mt-3 { margin-top: 24px !important; }
    .mobile-mb-1 { margin-bottom: 8px !important; }
    .mobile-mb-2 { margin-bottom: 16px !important; }
    .mobile-mb-3 { margin-bottom: 24px !important; }
    .mobile-p-1 { padding: 8px !important; }
    .mobile-p-2 { padding: 16px !important; }
    .mobile-p-3 { padding: 24px !important; }
}

/* ========================================
   LANDSCAPE MODE
   ======================================== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .mobile-header { height: 48px; }
    .mobile-bottom-nav { height: 48px; }
    .mobile-content {
        padding-top: 48px;
        padding-bottom: 48px;
    }
    .mobile-stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .mobile-fab { bottom: 56px; }
}

/* ========================================
   SMALL DEVICES (375px)
   ======================================== */
@media screen and (max-width: 375px) {
    .mobile-header-title { font-size: 15px; }
    .mobile-stat-value { font-size: 22px; }
    .mobile-card { padding: 14px; }
    .mobile-list-item { padding: 12px 14px; }
}

/* ========================================
   ULTRA SMALL (320px)
   ======================================== */
@media screen and (max-width: 320px) {
    :root {
        --mobile-padding: 12px;
        --mobile-card-gap: 8px;
    }
    .mobile-header-title { font-size: 13px; }
    .mobile-nav-label { font-size: 9px; }
    .mobile-stat-value { font-size: 18px; }
}
