/* NAPSA ERM - Responsive Design Enhancements */
/* Version 1.0 - Mobile-First Responsive Framework */

/* ============================================
   CSS VARIABLES FOR RESPONSIVE BREAKPOINTS
   ============================================ */
:root {
    --mobile-breakpoint: 576px;
    --tablet-breakpoint: 768px;
    --desktop-breakpoint: 992px;
    --large-desktop: 1200px;

    /* Responsive spacing */
    --spacing-mobile: 0.75rem;
    --spacing-tablet: 1rem;
    --spacing-desktop: 1.5rem;

    /* Touch-friendly sizes */
    --touch-target-min: 44px;
    --mobile-font-base: 14px;
    --tablet-font-base: 15px;
    --desktop-font-base: 16px;
}

/* ============================================
   1. RESPONSIVE STAT CARDS
   ============================================ */

/* Default: 6 cards in a row on large screens */
.stat-cards-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-cards-row > [class*="col-"] {
    flex: 1 1 auto;
}

/* Responsive stat cards using modern grid */
.row.mb-4 > [class*="col-md-2"] {
    flex: 0 0 auto;
}

/* Large desktop: 6 cards per row */
@media (min-width: 1200px) {
    .row.mb-4 > [class*="col-md-2"] {
        width: 16.666667%;
    }
}

/* Desktop: 4 cards per row */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .row.mb-4 > [class*="col-md-2"] {
        width: 25%;
    }
}

/* Tablet: 3 cards per row */
@media (min-width: 768px) and (max-width: 991.98px) {
    .row.mb-4 > [class*="col-md-2"] {
        width: 33.333333%;
    }
}

/* Small tablet: 2 cards per row */
@media (min-width: 576px) and (max-width: 767.98px) {
    .row.mb-4 > [class*="col-md-2"] {
        width: 50%;
    }

    .stat-card .card-body {
        padding: 0.75rem;
    }

    .stat-card h3 {
        font-size: 1.5rem;
    }

    .stat-card h6 {
        font-size: 0.75rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}

/* Mobile: 2 cards per row, compact */
@media (max-width: 575.98px) {
    .row.mb-4 > [class*="col-md-2"] {
        width: 50%;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .row.mb-4 {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .stat-card .card-body {
        padding: 0.625rem;
    }

    .stat-card h3 {
        font-size: 1.25rem;
        margin-bottom: 0;
    }

    .stat-card h6 {
        font-size: 0.7rem;
        margin-bottom: 0.25rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 0.875rem;
    }

    /* Stack icon below text on very small cards */
    .stat-card .d-flex {
        flex-direction: column;
        text-align: center;
    }

    .stat-card .stat-icon {
        margin-top: 0.5rem;
    }
}

/* ============================================
   2. RESPONSIVE TABLES
   ============================================ */

/* Table container with horizontal scroll */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

/* Responsive table with priority columns */
.table-responsive-priority {
    width: 100%;
    min-width: 100%;
}

/* Column priority classes - hide on smaller screens */
.table th.priority-low,
.table td.priority-low {
    /* Lowest priority - hide first */
}

.table th.priority-medium,
.table td.priority-medium {
    /* Medium priority */
}

.table th.priority-high,
.table td.priority-high {
    /* High priority - always show */
}

/* Hide low priority columns on tablet */
@media (max-width: 991.98px) {
    .table th.priority-low,
    .table td.priority-low {
        display: none;
    }
}

/* Hide medium priority columns on mobile */
@media (max-width: 767.98px) {
    .table th.priority-medium,
    .table td.priority-medium {
        display: none;
    }

    /* Compact table cells */
    .table td, .table th {
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    /* Truncate long text */
    .table .text-truncate-mobile {
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Very small screens - show only essential columns */
@media (max-width: 575.98px) {
    .table th.priority-medium,
    .table td.priority-medium,
    .table th.priority-low,
    .table td.priority-low {
        display: none;
    }

    .table td, .table th {
        padding: 0.375rem;
        font-size: 0.8125rem;
    }

    .table .text-truncate-mobile {
        max-width: 100px;
    }

    /* Stack action buttons vertically */
    .table .btn-group-actions {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .table .btn-group-actions .btn {
        width: 100%;
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Mobile card view for tables */
@media (max-width: 575.98px) {
    .table-to-cards {
        display: block;
    }

    .table-to-cards thead {
        display: none;
    }

    .table-to-cards tbody {
        display: block;
    }

    .table-to-cards tr {
        display: block;
        background: white;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }

    .table-to-cards td {
        display: flex;
        justify-content: space-between;
        padding: 0.375rem 0;
        border: none;
        border-bottom: 1px solid var(--gray-100);
    }

    .table-to-cards td:last-child {
        border-bottom: none;
    }

    .table-to-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray-600);
        margin-right: 1rem;
    }
}

/* ============================================
   3. MOBILE NAVIGATION & SIDEBAR
   ============================================ */

/* Mobile hamburger menu button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1051;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.mobile-menu-toggle.active {
    background: var(--danger-color);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile sidebar styles */
@media (max-width: 991.98px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1045;
        transition: left 0.3s ease;
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        left: 0;
        box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    }

    /* Adjust main content when sidebar is closed */
    .main-content {
        margin-left: 0 !important;
        padding-top: 60px;
    }

    /* Page header adjustments */
    .page-header {
        padding-left: 60px;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991.98px) {
    .sidebar {
        width: 240px;
        left: -240px;
    }
}

/* ============================================
   4. RESPONSIVE TABS & NAVIGATION
   ============================================ */

/* Scrollable tabs on mobile */
.nav-tabs-responsive {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.nav-tabs-responsive::-webkit-scrollbar {
    display: none;
}

.nav-tabs-responsive .nav-item {
    flex: 0 0 auto;
}

@media (max-width: 767.98px) {
    .nav-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    .nav-tabs .nav-link i {
        display: none;
    }

    /* Or show only icon on very small screens */
    .nav-tabs-icon-only .nav-link span {
        display: none;
    }

    .nav-tabs-icon-only .nav-link i {
        display: inline-block;
        margin: 0;
    }
}

/* Dropdown tabs for mobile */
@media (max-width: 575.98px) {
    .nav-tabs-dropdown {
        display: none;
    }

    .nav-tabs-mobile-select {
        display: block;
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        border: 1px solid var(--gray-300);
        border-radius: 8px;
        background: white;
        margin-bottom: 1rem;
    }
}

/* ============================================
   5. FORM AUTO-SAVE INDICATORS
   ============================================ */

/* Auto-save status indicator */
.autosave-indicator {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 1000;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(10px);
}

.autosave-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.autosave-indicator.saving {
    background: var(--info-color);
    color: white;
}

.autosave-indicator.saved {
    background: var(--success-color);
    color: white;
}

.autosave-indicator.error {
    background: var(--danger-color);
    color: white;
}

.autosave-indicator .spinner-border {
    width: 1rem;
    height: 1rem;
}

/* Recovery banner for auto-saved data */
.autosave-recovery-banner {
    background: linear-gradient(135deg, var(--info-color), var(--primary-color));
    color: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.autosave-recovery-banner .btn {
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .autosave-recovery-banner {
        flex-direction: column;
        text-align: center;
    }

    .autosave-recovery-banner .btn-group {
        width: 100%;
        display: flex;
    }

    .autosave-recovery-banner .btn {
        flex: 1;
    }
}

/* ============================================
   6. RESPONSIVE MODALS
   ============================================ */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 12px;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }

    /* Full screen modals on mobile */
    .modal-fullscreen-mobile .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-fullscreen-mobile .modal-content {
        height: 100%;
        border-radius: 0;
    }
}

/* ============================================
   7. RESPONSIVE CARDS & CONTAINERS
   ============================================ */

@media (max-width: 767.98px) {
    .card {
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-footer {
        padding: 0.75rem 1rem;
    }
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .page-header {
        padding: 1rem 0;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .page-header p {
        font-size: 0.875rem;
    }
}

/* ============================================
   8. RESPONSIVE BUTTONS & ACTIONS
   ============================================ */

/* Touch-friendly buttons */
@media (max-width: 767.98px) {
    .btn {
        min-height: var(--touch-target-min);
        padding: 0.5rem 1rem;
    }

    .btn-sm {
        min-height: 36px;
        padding: 0.375rem 0.75rem;
    }

    .btn-group {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    /* Floating action button for mobile */
    .fab-mobile {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.25);
        z-index: 1000;
    }
}

/* ============================================
   9. RESPONSIVE FILTERS
   ============================================ */

/* Collapsible filter panel */
.filter-panel-mobile {
    position: fixed;
    top: 0;
    right: -100%;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    background: white;
    z-index: 1050;
    transition: right 0.3s ease;
    overflow-y: auto;
    box-shadow: -4px 0 15px rgba(0,0,0,0.2);
}

.filter-panel-mobile.open {
    right: 0;
}

.filter-panel-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
}

.filter-panel-body {
    padding: 1rem;
}

.filter-panel-footer {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 1rem;
    border-top: 1px solid var(--gray-200);
}

@media (min-width: 992px) {
    .filter-panel-mobile {
        position: static;
        width: auto;
        max-width: none;
        height: auto;
        box-shadow: none;
    }

    .filter-toggle-mobile {
        display: none;
    }
}

@media (max-width: 991.98px) {
    .filter-toggle-mobile {
        display: inline-flex;
    }

    .filter-panel-desktop {
        display: none;
    }
}

/* ============================================
   10. RESPONSIVE TYPOGRAPHY
   ============================================ */

/* Fluid typography using clamp() */
h1, .h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h2, .h2 {
    font-size: clamp(1.25rem, 3.5vw, 2rem);
}

h3, .h3 {
    font-size: clamp(1.125rem, 3vw, 1.75rem);
}

h4, .h4 {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
}

/* Risk score displays */
.risk-score-display {
    font-size: clamp(2rem, 8vw, 4rem);
    font-weight: 700;
}

/* ============================================
   11. UTILITY CLASSES
   ============================================ */

/* Show/hide based on screen size */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

@media (max-width: 767.98px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-hidden {
        display: none !important;
    }
}

/* Responsive text alignment */
@media (max-width: 575.98px) {
    .text-center-mobile {
        text-align: center !important;
    }

    .text-left-mobile {
        text-align: left !important;
    }
}

/* Responsive spacing */
.p-responsive {
    padding: var(--spacing-desktop);
}

@media (max-width: 767.98px) {
    .p-responsive {
        padding: var(--spacing-tablet);
    }
}

@media (max-width: 575.98px) {
    .p-responsive {
        padding: var(--spacing-mobile);
    }
}

/* ============================================
   12. PRINT STYLES
   ============================================ */

@media print {
    .sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay,
    .autosave-indicator,
    .fab-mobile,
    .filter-toggle-mobile,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .table th.priority-low,
    .table td.priority-low,
    .table th.priority-medium,
    .table td.priority-medium {
        display: table-cell !important;
    }
}
