/* =====================================
   Bullionet Responsive Enhancements
   Mobile-first responsive design
   Inspired by shadcn/ui and modern UI patterns
   ===================================== */

/* ========================================
   RESPONSIVE UTILITIES
   ======================================== */

/* Flex utilities for responsive layouts */
.flex-mobile-column {
    display: flex;
}

@media (max-width: 768px) {
    .flex-mobile-column {
        flex-direction: column;
    }
}

/* Hide/Show utilities */
.hide-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

.show-mobile {
    display: none;
}

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

/* Container improvements */
.container-responsive {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

@media (max-width: 768px) {
    .container-responsive {
        padding: 0 1rem;
    }
}

@media (max-width: 576px) {
    .container-responsive {
        padding: 0 0.75rem;
    }
}

/* ========================================
   NAVIGATION & HEADER IMPROVEMENTS
   ======================================== */

/* Mobile Navigation Toggle Button */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    background: var(--bullionet-accent);
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mobile-nav-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.mobile-nav-toggle i {
    color: white;
    font-size: 24px;
}

@media (max-width: 768px) {
    .mobile-nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Improved Navbar for Mobile */
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
    }

    .navbar-brand {
        flex: 1;
    }

    .navbar-toggler {
        padding: 0.5rem;
        border: none;
        background: var(--bullionet-bg-tertiary);
        border-radius: var(--radius-md);
    }

    .navbar-collapse {
        width: 100%;
        margin-top: 1rem;
        background: var(--bullionet-bg-secondary);
        border-radius: var(--radius-lg);
        padding: 1rem;
    }

    .navbar-nav {
        flex-direction: column;
        width: 100%;
    }

    .navbar-nav .nav-item {
        width: 100%;
        margin: 0.25rem 0;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-radius: var(--radius-md);
        width: 100%;
    }

    /* Dropdown menus full width on mobile */
    .navbar .dropdown-menu {
        position: static !important;
        transform: none !important;
        width: 100%;
        margin-top: 0.5rem;
        border-radius: var(--radius-md);
    }
}

/* Sidebar improvements for mobile */
@media (max-width: 768px) {
    .sidenav,
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1050;
        transition: left 0.3s ease;
        overflow-y: auto;
        box-shadow: var(--shadow-xl);
    }

    .sidenav.active,
    .sidebar.active {
        left: 0;
    }

    /* Sidebar overlay */
    .sidenav-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1040;
        backdrop-filter: blur(2px);
    }

    .sidenav-overlay.active {
        display: block;
    }

    /* Main content adjustment when sidebar is open */
    body.sidenav-open {
        overflow: hidden;
    }
}

/* ========================================
   CARD IMPROVEMENTS
   ======================================== */

/* Responsive card grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

@media (max-width: 576px) {
    .card-grid {
        gap: 0.75rem;
    }
}

/* Card improvements on mobile */
@media (max-width: 768px) {
    .card {
        box-shadow: var(--shadow-sm) !important;
    }

    .card:hover {
        transform: none;
        box-shadow: var(--shadow-md) !important;
    }

    .card-img-top {
        max-height: 200px;
        object-fit: cover;
    }

    /* Horizontal cards on mobile become vertical */
    .card-horizontal {
        flex-direction: column;
    }

    .card-horizontal .card-img {
        width: 100%;
        height: auto;
        max-height: 200px;
        object-fit: cover;
    }
}

/* ========================================
   FORM IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Form groups stack better */
    .form-group,
    .form-row {
        margin-bottom: 1rem;
    }

    /* Input groups full width */
    .input-group {
        flex-wrap: wrap;
    }

    .input-group > * {
        flex: 1 1 100%;
    }

    .input-group-prepend,
    .input-group-append {
        flex: 1 1 auto;
    }

    /* File upload buttons */
    .custom-file-label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Checkbox and radio larger touch targets */
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-top: 0.125rem;
    }

    .form-check-label {
        padding-left: 0.5rem;
    }

    /* Select dropdowns */
    select.form-control,
    .form-select {
        background-position: right 0.75rem center;
        padding-right: 2.5rem;
    }
}

@media (max-width: 576px) {
    /* Extra small form adjustments */
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents iOS zoom */
    }

    /* Labels above inputs */
    .form-inline {
        flex-direction: column;
        align-items: stretch !important;
    }

    .form-inline .form-group,
    .form-inline .form-control {
        width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* ========================================
   BUTTON IMPROVEMENTS
   ======================================== */

/* Button groups responsive */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .btn-group {
        flex-direction: column;
    }

    .btn-group > .btn {
        width: 100%;
        border-radius: var(--radius-md) !important;
    }

    /* Toolbar buttons */
    .btn-toolbar {
        flex-direction: column;
        gap: 0.75rem;
    }

    .btn-toolbar .btn-group {
        width: 100%;
    }
}

/* ========================================
   TABLE IMPROVEMENTS
   ======================================== */

/* Responsive table wrapper */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    /* Mobile-first table layout */
    .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: 1rem;
        border: 1px solid var(--bullionet-border);
        border-radius: var(--radius-md);
        background: var(--bullionet-bg-card);
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem;
        border: none !important;
        border-bottom: 1px solid var(--bullionet-border) !important;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none !important;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--bullionet-text-primary);
        flex: 0 0 40%;
    }

    .table-mobile-cards td > * {
        flex: 1;
        text-align: right;
    }
}

/* ========================================
   MODAL IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    .modal {
        padding: 0 !important;
    }

    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
        display: flex;
        align-items: flex-end;
    }

    .modal-content {
        border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: var(--bullionet-bg-card);
        z-index: 10;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--bullionet-bg-card);
        z-index: 10;
        border-radius: 0 !important;
    }

    /* Full screen modals on mobile */
    .modal-fullscreen-sm-down {
        .modal-dialog {
            height: 100vh;
        }

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

/* ========================================
   SPACING UTILITIES FOR MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Compact spacing */
    .p-mobile-1 { padding: 0.5rem !important; }
    .p-mobile-2 { padding: 1rem !important; }
    .p-mobile-3 { padding: 1.5rem !important; }

    .m-mobile-1 { margin: 0.5rem !important; }
    .m-mobile-2 { margin: 1rem !important; }
    .m-mobile-3 { margin: 1.5rem !important; }

    .px-mobile-1 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    .px-mobile-2 { padding-left: 1rem !important; padding-right: 1rem !important; }

    .py-mobile-1 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
    .py-mobile-2 { padding-top: 1rem !important; padding-bottom: 1rem !important; }

    .mx-mobile-1 { margin-left: 0.5rem !important; margin-right: 0.5rem !important; }
    .mx-mobile-2 { margin-left: 1rem !important; margin-right: 1rem !important; }

    .my-mobile-1 { margin-top: 0.5rem !important; margin-bottom: 0.5rem !important; }
    .my-mobile-2 { margin-top: 1rem !important; margin-bottom: 1rem !important; }
}

/* ========================================
   TEXT & TYPOGRAPHY
   ======================================== */

@media (max-width: 768px) {
    /* Responsive text sizes */
    .text-mobile-sm { font-size: 0.875rem !important; }
    .text-mobile-base { font-size: 1rem !important; }
    .text-mobile-lg { font-size: 1.125rem !important; }

    /* Text alignment */
    .text-mobile-center { text-align: center !important; }
    .text-mobile-left { text-align: left !important; }
    .text-mobile-right { text-align: right !important; }

    /* Line clamp for long text */
    .line-clamp-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .line-clamp-3 {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}

/* ========================================
   BREADCRUMBS & PAGINATION
   ======================================== */

@media (max-width: 768px) {
    /* Breadcrumbs mobile */
    .breadcrumb {
        display: flex;
        flex-wrap: wrap;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    .breadcrumb-item {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .breadcrumb-item:first-child {
        max-width: none;
    }

    /* Pagination mobile */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination .page-item {
        margin: 0.125rem;
    }

    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Hide some pagination items on mobile */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child) {
        display: none;
    }

    .pagination .page-item.active,
    .pagination .page-item:first-child,
    .pagination .page-item:last-child,
    .pagination .page-item.active + .page-item,
    .pagination .page-item:has(+ .page-item.active) {
        display: inline-block;
    }
}

/* ========================================
   ALERTS & NOTIFICATIONS
   ======================================== */

@media (max-width: 768px) {
    .alert {
        border-radius: var(--radius-md);
        padding: 1rem;
        font-size: 0.875rem;
    }

    .alert-dismissible .close,
    .alert-dismissible .btn-close {
        padding: 0.75rem;
    }

    /* Toast notifications */
    .toast {
        max-width: calc(100vw - 2rem);
    }

    .toast-container {
        padding: 1rem;
    }
}

/* ========================================
   TABS & ACCORDIONS
   ======================================== */

@media (max-width: 768px) {
    /* Tabs scroll on mobile */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    /* Tab content padding */
    .tab-content {
        padding: 1rem;
    }

    /* Accordion spacing */
    .accordion-item {
        margin-bottom: 0.5rem;
    }

    .accordion-button {
        padding: 1rem;
        font-size: 0.9375rem;
    }

    .accordion-body {
        padding: 1rem;
    }
}

/* ========================================
   BADGES & LABELS
   ======================================== */

@media (max-width: 768px) {
    .badge {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }

    .badge-lg {
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }
}

/* ========================================
   IMAGES & MEDIA
   ======================================== */

@media (max-width: 768px) {
    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Avatar sizes on mobile */
    .avatar-sm { width: 32px; height: 32px; }
    .avatar-md { width: 48px; height: 48px; }
    .avatar-lg { width: 64px; height: 64px; }

    /* Video embeds responsive */
    .embed-responsive {
        position: relative;
        width: 100%;
        padding-bottom: 56.25%; /* 16:9 aspect ratio */
    }

    .embed-responsive iframe,
    .embed-responsive video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: var(--radius-md);
    }
}

/* ========================================
   PERFORMANCE IMPROVEMENTS
   ======================================== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
    .reduce-motion,
    .reduce-motion * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    /* Hide non-essential elements when printing */
    .navbar,
    .sidebar,
    .sidenav,
    .footer,
    .btn,
    .mobile-nav-toggle {
        display: none !important;
    }

    /* Ensure content is visible */
    body,
    .section-main {
        background: white !important;
        color: black !important;
    }

    .card {
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
    }

    a {
        text-decoration: underline !important;
    }

    /* Show URLs after links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--bullionet-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--bullionet-accent);
    color: white;
    padding: 1rem 2rem;
    border-radius: 0 0 var(--radius-md) 0;
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-to-main:focus {
    top: 0;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --bullionet-border: #ffffff;
        --bullionet-text-secondary: #ffffff;
    }

    .btn,
    .card,
    .form-control {
        border: 2px solid currentColor !important;
    }
}
