/* Mobile-First Responsive Styles and Cross-Platform Integration */

/* CSS Custom Properties for Mobile */
:root {
    --mobile-header-height: 60px;
    --mobile-nav-height: 70px;
    --mobile-padding: 1rem;
    --mobile-margin: 0.75rem;
    --touch-target-size: 44px;
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
    --safe-area-inset-right: env(safe-area-inset-right);
    --vh: 1vh;
}

/* Mobile Device Detection and Base Styles */
.mobile-device {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-device * {
    box-sizing: border-box;
}

/* PWA and Standalone App Styles */
.standalone-app {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* Mobile Install Banner */
.mobile-install-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #228B22, #32CD32);
    color: white;
    padding: 1rem;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 9999;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.mobile-install-banner.show {
    transform: translateY(0);
}

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 400px;
    margin: 0 auto;
}

.install-banner-icon {
    font-size: 1.5rem;
    opacity: 0.9;
}

.install-banner-text h6 {
    margin: 0;
    font-weight: 600;
}

.install-banner-text small {
    opacity: 0.8;
}

.install-banner-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

/* Mobile Navigation */
@media (max-width: 768px) {
    .navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        padding: 0.5rem 1rem;
        height: var(--mobile-header-height);
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.95);
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }

    .navbar-brand {
        font-size: 1.1rem;
        font-weight: 700;
    }

    .navbar-toggler {
        border: none;
        padding: 0.25rem;
        font-size: 1.2rem;
    }

    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid rgba(0,0,0,0.1);
        box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        max-height: calc(100vh - var(--mobile-header-height));
        overflow-y: auto;
    }

    .navbar-nav {
        padding: 1rem;
    }

    .nav-link {
        padding: 0.75rem 1rem;
        border-radius: 8px;
        margin-bottom: 0.25rem;
        font-weight: 500;
        transition: all 0.2s ease;
    }

    .nav-link:hover, .nav-link:focus {
        background: #f8f9fa;
        transform: translateX(5px);
    }

    /* Main content padding for fixed header */
    .container-fluid, .container {
        padding-top: calc(var(--mobile-header-height) + 1rem);
    }
}

/* Mobile Cards and Components */
@media (max-width: 768px) {
    .card {
        border-radius: 12px;
        margin-bottom: 1rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    .card-header {
        padding: 1rem;
        border-radius: 12px 12px 0 0;
    }

    .card-body {
        padding: 1rem;
    }

    .btn {
        min-height: var(--touch-target-size);
        padding: 0.75rem 1.5rem;
        font-weight: 500;
        border-radius: 8px;
        transition: all 0.2s ease;
    }

    .btn:active {
        transform: scale(0.98);
    }

    .btn-sm {
        min-height: 36px;
        padding: 0.5rem 1rem;
    }

    .btn-lg {
        min-height: 52px;
        padding: 1rem 2rem;
        font-size: 1.1rem;
    }
}

/* Mobile Forms */
@media (max-width: 768px) {
    .form-control, .form-select {
        min-height: var(--touch-target-size);
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
        padding: 0.75rem 1rem;
        transition: all 0.2s ease;
    }

    .form-control:focus, .form-select:focus {
        transform: scale(1.02);
        box-shadow: 0 0 0 3px rgba(34, 139, 34, 0.1);
    }

    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
        color: #333;
    }

    .form-group {
        margin-bottom: 1.5rem;
    }

    textarea.form-control {
        resize: vertical;
        min-height: 100px;
    }

    /* File input styling */
    .form-control[type="file"] {
        padding: 0.5rem;
        cursor: pointer;
    }

    .form-control[type="file"]::-webkit-file-upload-button {
        background: #228B22;
        color: white;
        border: none;
        padding: 0.5rem 1rem;
        border-radius: 6px;
        margin-right: 1rem;
        cursor: pointer;
    }
}

/* Mobile Tables */
@media (max-width: 768px) {
    .table-responsive {
        border-radius: 8px;
        overflow: hidden;
    }

    .table {
        font-size: 0.9rem;
    }

    .table th, .table td {
        padding: 0.75rem 0.5rem;
        vertical-align: middle;
    }

    /* Stack table rows on mobile */
    .table-mobile-stack {
        display: block;
    }

    .table-mobile-stack thead {
        display: none;
    }

    .table-mobile-stack tbody,
    .table-mobile-stack tr,
    .table-mobile-stack td {
        display: block;
    }

    .table-mobile-stack tr {
        background: white;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .table-mobile-stack td {
        border: none;
        padding: 0.5rem 0;
        position: relative;
        padding-left: 40%;
    }

    .table-mobile-stack td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        top: 0.5rem;
        font-weight: 600;
        color: #666;
    }
}

/* Mobile Modals */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }

    .modal-fullscreen-sm-down {
        width: 100vw;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .modal-header {
        padding: 1rem;
        border-radius: 0;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }

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

    .modal-footer .btn {
        width: 100%;
    }
}

/* Pull to Refresh */
.pull-refresh-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 1rem 2rem;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: top 0.3s ease;
    z-index: 9999;
}

.pull-refresh-indicator.active {
    top: 0;
}

.refresh-spinner {
    color: #228B22;
}

/* Connection Status Toast */
.connection-toast {
    position: fixed;
    top: var(--safe-area-inset-top, 20px);
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: white;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    font-weight: 500;
    z-index: 9999;
    transition: transform 0.3s ease;
}

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

.connection-toast.toast-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.connection-toast.toast-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Mobile Toast Notifications */
.mobile-toast {
    position: fixed;
    bottom: calc(var(--safe-area-inset-bottom, 0px) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 25px;
    font-weight: 500;
    z-index: 9999;
    transition: transform 0.3s ease;
    max-width: calc(100vw - 2rem);
    text-align: center;
}

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

.mobile-toast.toast-success {
    background: rgba(40, 167, 69, 0.9);
}

.mobile-toast.toast-warning {
    background: rgba(255, 193, 7, 0.9);
    color: #212529;
}

.mobile-toast.toast-error {
    background: rgba(220, 53, 69, 0.9);
}

/* Copy Code Button */
.copy-code-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.copy-code-btn:hover {
    opacity: 1;
}

/* Mobile Dashboard Optimizations */
@media (max-width: 768px) {
    .dashboard-card {
        margin-bottom: 1rem;
    }

    .progress-container {
        margin-bottom: 1rem;
        padding: 1rem;
    }

    .progress-label {
        font-size: 0.9rem;
    }

    .progress-counter {
        font-size: 1rem;
        padding: 0.25rem 0.75rem;
    }

    .achievement-badge-container {
        margin-bottom: 1rem;
        padding: 1rem;
    }

    .achievement-badge-icon {
        font-size: 2rem;
    }

    .financial-overview .col-md-3 {
        margin-bottom: 1rem;
    }

    .financial-overview .card {
        text-align: center;
    }

    .recent-transactions .table-responsive {
        border-radius: 8px;
        overflow-x: auto;
    }
}

/* Landscape Orientation Optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        height: 50px;
    }

    .container-fluid, .container {
        padding-top: calc(50px + 0.5rem);
    }

    .modal-dialog {
        max-height: 90vh;
    }
}

/* Dark Mode Support for Mobile */
@media (prefers-color-scheme: dark) {
    .mobile-device {
        background: #121212;
        color: #ffffff;
    }

    .navbar {
        background: rgba(18, 18, 18, 0.95);
        border-bottom-color: rgba(255,255,255,0.1);
    }

    .card {
        background: #1e1e1e;
        border-color: rgba(255,255,255,0.1);
    }

    .form-control, .form-select {
        background: #2a2a2a;
        border-color: rgba(255,255,255,0.2);
        color: white;
    }

    .table {
        color: white;
    }

    .table th {
        border-color: rgba(255,255,255,0.1);
    }
}

/* High DPI Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .mobile-device img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Accessibility Improvements for Mobile */
@media (max-width: 768px) {
    .sr-only-mobile {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0,0,0,0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    /* Focus indicators for touch devices */
    .btn:focus,
    .form-control:focus,
    .nav-link:focus {
        outline: 2px solid #228B22;
        outline-offset: 2px;
    }

    /* Larger touch targets for better accessibility */
    .btn, .nav-link, .form-control {
        min-height: var(--touch-target-size);
        min-width: var(--touch-target-size);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .mobile-device * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles for Mobile */
@media print {
    .mobile-install-banner,
    .connection-toast,
    .mobile-toast,
    .pull-refresh-indicator {
        display: none !important;
    }

    .mobile-device .container {
        padding-top: 0 !important;
    }
}