/* ============================================
   MOBILE-FIRST RESPONSIVE CSS FRAMEWORK
   AIGOS - AI Growth Operating System
   ============================================ */

/* ============================================
   MOBILE FIRST BASE STYLES (320px - 767px)
   ============================================ */

/* CSS Variables for Mobile */
:root {
    /* Mobile-optimized spacing */
    --mobile-spacing-xs: 4px;
    --mobile-spacing-sm: 8px;
    --mobile-spacing-md: 16px;
    --mobile-spacing-lg: 24px;
    --mobile-spacing-xl: 32px;
    
    /* Touch-friendly sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-target-large: 56px;
    
    /* Mobile typography scale */
    --mobile-text-xs: 12px;
    --mobile-text-sm: 14px;
    --mobile-text-base: 16px;
    --mobile-text-lg: 18px;
    --mobile-text-xl: 20px;
    --mobile-text-2xl: 24px;
    --mobile-text-3xl: 28px;
    
    /* Mobile-specific colors */
    --mobile-bg: #1a1d29;
    --mobile-surface: rgba(45, 49, 66, 0.95);
    --mobile-border: rgba(255, 255, 255, 0.1);
    --mobile-text: #e0e0e0;
    --mobile-text-secondary: #9ca3af;
    
    /* Safe areas for notched devices */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-right: env(safe-area-inset-right);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
}

/* Reset and Base Styles */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-size: var(--mobile-text-base);
    line-height: 1.6;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Mobile Container */
.container,
.container-fluid {
    width: 100%;
    padding-left: var(--mobile-spacing-md);
    padding-right: var(--mobile-spacing-md);
    padding-left: calc(var(--mobile-spacing-md) + var(--safe-area-left));
    padding-right: calc(var(--mobile-spacing-md) + var(--safe-area-right));
}

/* Mobile Typography */
h1 {
    font-size: clamp(var(--mobile-text-2xl), 5vw, var(--mobile-text-3xl));
    line-height: 1.2;
    margin-bottom: var(--mobile-spacing-md);
}

h2 {
    font-size: clamp(var(--mobile-text-xl), 4vw, var(--mobile-text-2xl));
    line-height: 1.3;
    margin-bottom: var(--mobile-spacing-md);
}

h3 {
    font-size: clamp(var(--mobile-text-lg), 3.5vw, var(--mobile-text-xl));
    line-height: 1.4;
    margin-bottom: var(--mobile-spacing-sm);
}

p, .text-body {
    font-size: var(--mobile-text-base);
    line-height: 1.6;
    margin-bottom: var(--mobile-spacing-md);
}

/* Mobile Buttons */
.btn {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: var(--mobile-spacing-sm) var(--mobile-spacing-md);
    font-size: var(--mobile-text-base);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

/* Active state for touch feedback */
.btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Full-width buttons on mobile */
.btn-mobile-full {
    width: 100%;
    display: flex;
}

/* Mobile Forms */
.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: var(--mobile-spacing-sm) var(--mobile-spacing-md);
    font-size: var(--mobile-text-base);
    border-radius: 8px;
    border: 1px solid var(--mobile-border);
    background: var(--mobile-surface);
    color: var(--mobile-text);
    -webkit-appearance: none;
    appearance: none;
}

/* Prevent zoom on input focus (iOS) */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
select,
textarea {
    font-size: 16px !important;
}

/* Mobile Cards */
.card {
    border-radius: 12px;
    margin-bottom: var(--mobile-spacing-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-body {
    padding: var(--mobile-spacing-md);
}

.card-header {
    padding: var(--mobile-spacing-md);
    border-radius: 12px 12px 0 0;
}

/* Mobile Navigation */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--mobile-surface);
    border-top: 1px solid var(--mobile-border);
    padding: var(--mobile-spacing-sm) 0;
    padding-bottom: calc(var(--mobile-spacing-sm) + var(--safe-area-bottom));
    z-index: 1000;
    display: flex;
    justify-content: space-around;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target-min);
    color: var(--mobile-text-secondary);
    text-decoration: none;
    font-size: var(--mobile-text-xs);
    transition: color 0.2s ease;
}

.mobile-nav-item.active {
    color: #ff8a3d;
}

.mobile-nav-item i {
    font-size: 20px;
    margin-bottom: 4px;
}

/* Mobile Menu (Hamburger) */
.mobile-menu-toggle {
    position: fixed;
    top: var(--mobile-spacing-md);
    right: var(--mobile-spacing-md);
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    background: var(--mobile-surface);
    border: 1px solid var(--mobile-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    cursor: pointer;
}

.mobile-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 80%;
    max-width: 320px;
    height: 100%;
    background: var(--mobile-surface);
    z-index: 1002;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding-top: calc(var(--mobile-spacing-xl) + var(--safe-area-top));
}

.mobile-menu.active {
    left: 0;
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    display: none;
}

.mobile-menu-overlay.active {
    display: block;
}

/* Mobile Tables */
.table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--mobile-spacing-md));
    padding: 0 var(--mobile-spacing-md);
}

/* Convert table to cards on mobile */
@media (max-width: 767px) {
    .table-mobile-cards {
        display: block;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody {
        display: block;
    }
    
    .table-mobile-cards tr {
        display: block;
        margin-bottom: var(--mobile-spacing-md);
        background: var(--mobile-surface);
        border-radius: 8px;
        padding: var(--mobile-spacing-md);
    }
    
    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: var(--mobile-spacing-sm) 0;
        border: none;
    }
    
    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--mobile-text-secondary);
    }
}

/* Mobile Modals */
.modal-mobile {
    padding: 0;
}

.modal-mobile .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
}

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

/* Bottom Sheet Modal */
.modal-bottom-sheet .modal-dialog {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    max-width: 100%;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.modal-bottom-sheet.show .modal-dialog {
    transform: translateY(0);
}

.modal-bottom-sheet .modal-content {
    border-radius: 16px 16px 0 0;
    padding-bottom: var(--safe-area-bottom);
}

/* Mobile Grid System */
.row-mobile {
    display: flex;
    flex-wrap: wrap;
    margin: 0 calc(-1 * var(--mobile-spacing-sm));
}

.col-mobile {
    flex: 1 0 100%;
    padding: 0 var(--mobile-spacing-sm);
    margin-bottom: var(--mobile-spacing-md);
}

.col-mobile-6 {
    flex: 0 0 50%;
    max-width: 50%;
}

/* Mobile Utilities */
.mobile-only {
    display: block !important;
}

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

.text-mobile-center {
    text-align: center;
}

.p-mobile-0 {
    padding: 0 !important;
}

.m-mobile-0 {
    margin: 0 !important;
}

/* ============================================
   TABLET STYLES (768px - 1023px)
   ============================================ */
@media (min-width: 768px) {
    :root {
        --mobile-text-base: 16px;
        --mobile-text-lg: 20px;
        --mobile-text-xl: 24px;
        --mobile-text-2xl: 32px;
        --mobile-text-3xl: 40px;
    }
    
    .container {
        max-width: 750px;
        margin: 0 auto;
    }
    
    /* Hide mobile navigation on tablets */
    .mobile-nav {
        display: none;
    }
    
    .mobile-menu-toggle {
        display: none;
    }
    
    /* Tablet grid */
    .col-tablet-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    .col-tablet-4 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }
    
    .col-tablet-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }
    
    /* Restore table layout on tablets */
    .table-mobile-cards {
        display: table;
    }
    
    .table-mobile-cards thead {
        display: table-header-group;
    }
    
    .table-mobile-cards tbody {
        display: table-row-group;
    }
    
    .table-mobile-cards tr {
        display: table-row;
        margin-bottom: 0;
        background: transparent;
        border-radius: 0;
        padding: 0;
    }
    
    .table-mobile-cards td {
        display: table-cell;
        padding: 12px;
    }
    
    .table-mobile-cards td::before {
        display: none;
    }
    
    .mobile-only {
        display: none !important;
    }
    
    .desktop-only {
        display: block !important;
    }
}

/* ============================================
   DESKTOP STYLES (1024px+)
   ============================================ */
@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
    
    /* Desktop grid */
    .col-desktop-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    .col-desktop-4 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }
    
    .col-desktop-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }
    
    .col-desktop-2 {
        flex: 0 0 16.666%;
        max-width: 16.666%;
    }
    
    /* Remove mobile-specific padding */
    body {
        padding-top: 0;
        padding-bottom: 0;
    }
    
    .btn-mobile-full {
        width: auto;
    }
}

/* ============================================
   LARGE DESKTOP STYLES (1440px+)
   ============================================ */
@media (min-width: 1440px) {
    .container {
        max-width: 1400px;
    }
}

/* ============================================
   ACCESSIBILITY & PERFORMANCE
   ============================================ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --mobile-border: rgba(255, 255, 255, 0.5);
        --mobile-text: #ffffff;
        --mobile-text-secondary: #cccccc;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Dark mode preference */
@media (prefers-color-scheme: dark) {
    :root {
        --mobile-bg: #0a0a0a;
        --mobile-surface: #1a1a1a;
    }
}

/* Print styles */
@media print {
    .mobile-nav,
    .mobile-menu-toggle,
    .mobile-menu,
    .btn,
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }
}