/* ============================================================================
   ADMIN & SUPER ADMIN MOBILE ENHANCEMENTS
   Comprehensive mobile optimization for all admin interfaces
   ============================================================================ */

/* ── Super Admin Layout Mobile ─────────────────────────────────────── */
@media (max-width: 768px) {
    .super-admin-app {
        height: auto;
        min-height: 100vh;
    }

    .super-admin-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .super-admin-logo {
        justify-content: space-between;
    }

    .super-admin-title {
        font-size: 0.9rem;
    }

    /* Horizontal scrollable navigation on mobile */
    .super-admin-nav {
        width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        display: flex;
        gap: 0.5rem;
        padding-bottom: 0.25rem;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }

    .super-admin-nav::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .super-admin-nav-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 0.625rem 1rem;
        min-height: 40px;
        font-size: 0.8125rem;
    }

    /* User menu on mobile */
    .super-admin-user {
        width: 100%;
        justify-content: space-between;
        padding: 0.5rem;
        background: #f8f9fa;
        border-radius: 6px;
    }

    .admin-user-name {
        font-size: 0.8125rem;
    }

    .admin-logout-btn {
        min-height: 36px;
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }

    /* Content area */
    .super-admin-content {
        padding: 1rem;
    }
}

/* ── Admin Dashboard Stats Grid Mobile ────────────────────────────── */
@media (max-width: 768px) {
    .admin-dashboard-container {
        padding: 0;
    }

    .dashboard-header {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .dashboard-header h1 {
        font-size: 1.5rem;
    }

    .dashboard-subtitle {
        font-size: 0.875rem;
    }

    /* Stats grid - 1 column on mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        padding: 0 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .stat-icon {
        font-size: 1.75rem;
    }

    .stat-value {
        font-size: 1.75rem;
        margin: 0.5rem 0;
    }

    .stat-label {
        font-size: 0.875rem;
    }

    .stat-breakdown {
        font-size: 0.75rem;
        margin-top: 0.5rem;
    }

    /* Revenue cards */
    .stat-card-revenue .stat-value {
        font-size: 2rem;
        font-weight: 700;
    }
}

/* ── Admin Tables Mobile (Card-Based) ─────────────────────────────── */
@media (max-width: 768px) {
    .admin-page-container {
        padding: 1rem;
    }

    /* Hide table, show card view instead */
    .data-table {
        display: none;
    }

    /* Create mobile card view for tables */
    .data-table-wrapper {
        display: block;
    }

    /* If table must be shown, make it scrollable */
    .data-table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .data-table-scroll .data-table {
        display: table;
        min-width: 600px;
        font-size: 0.8125rem;
    }

    .data-table thead th {
        padding: 0.625rem 0.5rem;
        font-size: 0.75rem;
    }

    .data-table tbody td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8125rem;
    }

    /* Action buttons in tables */
    .table-action-btn,
    .btn-sm {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
        min-height: 36px;
    }
}

/* ── Organization Cards Mobile ────────────────────────────────────── */
@media (max-width: 768px) {
    .org-grid,
    .organisations-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .org-card {
        padding: 1.25rem;
    }

    .org-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .org-name {
        font-size: 1.125rem;
    }

    .org-badge,
    .plan-badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.625rem;
    }

    .org-details {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .org-detail-item {
        padding: 0.75rem;
    }

    .org-actions {
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

    .org-action-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }
}

/* ── Admin Forms Mobile ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    .form-input,
    .form-select,
    .form-textarea {
        min-height: 48px;
        padding: 0.75rem;
        font-size: 16px; /* Prevent iOS zoom */
    }

    .form-textarea {
        min-height: 120px;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.75rem;
    }

    .form-btn {
        width: 100%;
        min-height: 48px;
        font-size: 1rem;
    }
}

/* ── Admin Modals Mobile ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .admin-modal .modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .admin-modal .modal-header {
        padding: 1rem;
        min-height: 56px;
    }

    .admin-modal .modal-body {
        padding: 1rem;
        overflow-y: auto;
        flex: 1;
    }

    .admin-modal .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
        gap: 0.75rem;
    }

    .admin-modal .modal-footer .btn {
        width: 100%;
        min-height: 48px;
    }
}

/* ── Revenue & Analytics Charts Mobile ────────────────────────────── */
@media (max-width: 768px) {
    .revenue-chart-container,
    .analytics-chart-container {
        height: 250px; /* Shorter on mobile */
        margin: 1rem 0;
    }

    .chart-legend {
        flex-wrap: wrap;
        gap: 0.5rem;
        font-size: 0.75rem;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .chart-filters {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chart-filter-btn {
        flex-shrink: 0;
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }
}

/* ── Pending Registrations Mobile ─────────────────────────────────── */
@media (max-width: 768px) {
    .pending-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .pending-card {
        padding: 1.25rem;
        border-radius: 8px;
        background: #ffffff;
        border: 1px solid #e5e7eb;
    }

    .pending-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 1rem;
    }

    .pending-name {
        font-size: 1.125rem;
        font-weight: 600;
        color: #1a1a1a;
    }

    .pending-email {
        font-size: 0.875rem;
        color: #6b7280;
        margin-top: 0.25rem;
    }

    .pending-details {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .pending-detail-item {
        display: flex;
        justify-content: space-between;
        padding: 0.625rem;
        background: #f9fafb;
        border-radius: 4px;
        font-size: 0.875rem;
    }

    .pending-actions {
        display: flex;
        gap: 0.75rem;
    }

    .pending-action-btn {
        flex: 1;
        min-height: 44px;
        font-size: 0.875rem;
        border-radius: 6px;
        font-weight: 500;
    }

    .pending-approve-btn {
        background: #10b981;
        color: white;
    }

    .pending-reject-btn {
        background: #ef4444;
        color: white;
    }
}

/* ── Demo Requests Mobile ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .demo-requests-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .demo-request-card {
        padding: 1.25rem;
        background: #ffffff;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
    }

    .demo-header {
        margin-bottom: 1rem;
    }

    .demo-company {
        font-size: 1.125rem;
        font-weight: 600;
        color: #1a1a1a;
        margin-bottom: 0.25rem;
    }

    .demo-contact {
        font-size: 0.875rem;
        color: #6b7280;
    }

    .demo-details {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .demo-detail-row {
        display: flex;
        justify-content: space-between;
        font-size: 0.875rem;
        padding: 0.5rem;
        background: #f9fafb;
        border-radius: 4px;
    }

    .demo-message {
        background: #f9fafb;
        padding: 1rem;
        border-radius: 6px;
        font-size: 0.875rem;
        color: #4b5563;
        margin-bottom: 1rem;
        line-height: 1.5;
    }

    .demo-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .demo-action-btn {
        width: 100%;
        min-height: 44px;
        font-size: 0.875rem;
    }
}

/* ── Admin Settings Page Mobile ───────────────────────────────────── */
@media (max-width: 768px) {
    .settings-section {
        margin-bottom: 2rem;
    }

    .settings-header {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    .settings-description {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }

    .settings-group {
        background: #ffffff;
        padding: 1.25rem;
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .setting-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 0;
        border-bottom: 1px solid #e5e7eb;
    }

    .setting-item:last-child {
        border-bottom: none;
    }

    .setting-label {
        flex: 1;
        font-size: 0.9375rem;
        font-weight: 500;
    }

    .setting-description {
        font-size: 0.8125rem;
        color: #6b7280;
        margin-top: 0.25rem;
    }

    /* Toggle switches */
    .setting-toggle {
        width: 48px;
        height: 28px;
        border-radius: 14px;
        position: relative;
        background: #d1d5db;
        cursor: pointer;
        transition: background 0.3s;
    }

    .setting-toggle.active {
        background: #10b981;
    }

    .setting-toggle::after {
        content: '';
        position: absolute;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: white;
        top: 2px;
        left: 2px;
        transition: transform 0.3s;
    }

    .setting-toggle.active::after {
        transform: translateX(20px);
    }
}

/* ── Pricing Page Mobile ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .pricing-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
    }

    .pricing-card {
        padding: 1.5rem;
    }

    .pricing-header {
        text-align: center;
        margin-bottom: 1.5rem;
    }

    .pricing-plan-name {
        font-size: 1.25rem;
    }

    .pricing-amount {
        font-size: 2.5rem;
    }

    .pricing-features {
        margin: 1.5rem 0;
    }

    .pricing-feature {
        padding: 0.75rem 0;
        font-size: 0.9375rem;
    }

    .pricing-btn {
        width: 100%;
        min-height: 48px;
        font-size: 1rem;
    }
}

/* ── Touch Feedback for Admin ─────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .super-admin-nav-item:active,
    .org-action-btn:active,
    .table-action-btn:active,
    .demo-action-btn:active,
    .pending-action-btn:active {
        transform: scale(0.97);
        opacity: 0.8;
    }
}

/* ── Admin Page Scrolling ─────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Ensure content areas scroll smoothly */
    .super-admin-content,
    .admin-page-container,
    .modal-body {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }

    /* Prevent body scroll when modal open */
    body.modal-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ── Tablet Admin Layout (769-1024px) ─────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
    .super-admin-header {
        padding: 1rem 1.5rem;
    }

    .super-admin-nav-item {
        padding: 0.5rem 0.875rem;
        font-size: 0.8125rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .org-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .pricing-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Admin Loading States Mobile ──────────────────────────────────── */
@media (max-width: 768px) {
    .admin-loading-overlay {
        backdrop-filter: blur(4px);
    }

    .admin-spinner {
        width: 40px;
        height: 40px;
    }

    .admin-loading-text {
        font-size: 0.875rem;
        margin-top: 1rem;
    }
}

/* ── Admin Empty States Mobile ────────────────────────────────────── */
@media (max-width: 768px) {
    .empty-state {
        padding: 3rem 1.5rem;
        text-align: center;
    }

    .empty-state-icon {
        font-size: 3rem;
        margin-bottom: 1rem;
    }

    .empty-state-title {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    .empty-state-description {
        font-size: 0.9375rem;
        color: #6b7280;
        margin-bottom: 1.5rem;
    }

    .empty-state-btn {
        min-height: 48px;
        padding: 0.75rem 2rem;
    }
}

/* ── Admin Alerts & Notifications Mobile ──────────────────────────── */
@media (max-width: 768px) {
    .admin-alert {
        margin: 1rem;
        padding: 1rem;
        border-radius: 8px;
        font-size: 0.875rem;
    }

    .admin-alert-title {
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    .admin-toast {
        width: calc(100% - 2rem);
        max-width: 400px;
        bottom: 1rem;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ── Accessibility for Admin Mobile ───────────────────────────────── */
@media (max-width: 768px) {
    /* Larger focus indicators */
    .super-admin-nav-item:focus-visible,
    .admin-modal button:focus-visible,
    .form-input:focus-visible {
        outline: 3px solid #3b82f6;
        outline-offset: 2px;
    }

    /* Ensure minimum text size */
    .admin-page * {
        min-font-size: 14px;
    }
}
