/**
 * Professional Responsive Design Framework
 * Mobile-first approach with breakpoints for all devices
 */

/* ============================================
   ROOT VARIABLES
   ============================================ */
:root {
    --mobile-padding: 1rem;
    --tablet-padding: 1.5rem;
    --desktop-padding: 2rem;
    --container-max-width: 1400px;
}

/* ============================================
   MOBILE FIRST BASE STYLES (< 768px)
   ============================================ */

/* Prevent horizontal overflow on all screens */
* {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    width: 100%;
    position: relative;
}

/* Container adjustments */
.container {
    max-width: 100%;
    padding-left: var(--mobile-padding);
    padding-right: var(--mobile-padding);
    margin: 0 auto;
    width: 100%;
}

/* Typography scaling */
h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    line-height: 1.3;
}

h3 {
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1.4;
}

p, li {
    font-size: clamp(0.875rem, 2vw, 1rem);
    line-height: 1.6;
}

/* Button scaling */
.btn, button {
    font-size: clamp(0.875rem, 2vw, 1rem);
    padding: clamp(0.625rem, 2vw, 0.875rem) clamp(1rem, 3vw, 1.5rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Grid systems */
.grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.flex {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Navigation mobile */
.nav-menu {
    display: none;
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    background: var(--bg-primary, #0a0e27);
    padding: 1rem;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.nav-menu.active {
    display: block;
}

.mobile-menu-toggle {
    display: block;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* Cards */
.card {
    margin-bottom: 1rem;
    padding: 1rem;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    min-width: 600px;
    font-size: 0.875rem;
}

/* Hide elements on mobile */
.hide-mobile {
    display: none !important;
}

/* Show only on mobile */
.show-mobile {
    display: block !important;
}

/* Form adjustments */
input, select, textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
    width: 100%;
}

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

/* ============================================
   EXTRA SMALL MOBILE (≤ 320px)
   ============================================ */
@media (max-width: 320px) {
    /* Reduce padding for very small screens */
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Further reduce typography */
    h1 {
        font-size: clamp(1.5rem, 6vw, 2rem);
    }

    h2 {
        font-size: clamp(1.25rem, 5vw, 1.75rem);
    }

    h3 {
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }

    p, li {
        font-size: 0.875rem;
    }

    /* Compact buttons */
    .btn, button {
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem;
        white-space: normal;
    }

    /* Reduce card padding */
    .card {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    /* Reduce gap in grids */
    .grid, .flex {
        gap: 0.5rem;
    }

    /* Compact forms */
    .form-group {
        margin-bottom: 0.75rem;
    }

    input, select, textarea {
        font-size: 14px !important;
        padding: 0.5rem;
    }

    /* Reduce header size */
    .header-content {
        padding: 0.5rem;
    }

    /* Compact tables */
    table {
        font-size: 0.75rem;
    }

    th, td {
        padding: 0.4rem !important;
    }
}

/* ============================================
   SMALL TABLETS (≥ 576px)
   ============================================ */
@media (min-width: 576px) {
    .container {
        padding-left: var(--tablet-padding);
        padding-right: var(--tablet-padding);
    }

    .grid-sm-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .card {
        padding: 1.25rem;
    }
}

/* ============================================
   TABLETS (≥ 768px)
   ============================================ */
@media (min-width: 768px) {
    /* Hide mobile menu toggle */
    .mobile-menu-toggle {
        display: none;
    }

    /* Show desktop navigation */
    .nav-menu {
        display: flex !important;
        position: static;
        background: transparent;
        padding: 0;
        box-shadow: none;
    }

    .nav-menu ul {
        display: flex;
        gap: 2rem;
        align-items: center;
    }

    /* Grid adjustments */
    .grid-md-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-md-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Show/hide helpers */
    .hide-mobile {
        display: block !important;
    }

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

    /* Card adjustments */
    .card {
        padding: 1.5rem;
    }

    /* Table adjustments */
    table {
        font-size: 0.9375rem;
    }
}

/* ============================================
   LARGE TABLETS / SMALL DESKTOPS (≥ 992px)
   ============================================ */
@media (min-width: 992px) {
    .container {
        max-width: 960px;
        padding-left: var(--desktop-padding);
        padding-right: var(--desktop-padding);
    }

    .grid-lg-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .card {
        padding: 2rem;
    }

    /* Sidebar layouts */
    .layout-with-sidebar {
        display: grid;
        grid-template-columns: 250px 1fr;
        gap: 2rem;
    }

    .sidebar {
        display: block !important;
    }
}

/* ============================================
   DESKTOPS (≥ 1200px)
   ============================================ */
@media (min-width: 1200px) {
    .container {
        max-width: var(--container-max-width);
    }

    .grid-xl-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .grid-xl-5 {
        grid-template-columns: repeat(5, 1fr);
    }

    /* Wider sidebar */
    .layout-with-sidebar {
        grid-template-columns: 280px 1fr;
    }
}

/* ============================================
   LARGE DESKTOPS (≥ 1400px)
   ============================================ */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }

    .grid-xxl-6 {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Spacing utilities */
.p-mobile { padding: var(--mobile-padding); }
.p-tablet { padding: var(--tablet-padding); }
.p-desktop { padding: var(--desktop-padding); }

.m-mobile { margin: var(--mobile-padding); }
.m-tablet { margin: var(--tablet-padding); }
.m-desktop { margin: var(--desktop-padding); }

/* Text alignment */
@media (max-width: 767px) {
    .text-center-mobile { text-align: center; }
    .text-left-mobile { text-align: left; }
}

/* Flexbox utilities */
.flex-column-mobile {
    flex-direction: column;
}

@media (min-width: 768px) {
    .flex-row-md {
        flex-direction: row;
    }
}

/* Width utilities */
.w-100 { width: 100%; }
.w-auto { width: auto; }

@media (max-width: 767px) {
    .w-100-mobile { width: 100% !important; }
}

/* Image responsive */
img {
    max-width: 100%;
    height: auto;
}

/* Video responsive */
.video-responsive {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
}

.video-responsive iframe,
.video-responsive video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ============================================
   DASHBOARD SPECIFIC RESPONSIVE
   ============================================ */

/* Dashboard layout */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.dashboard-sidebar {
    width: 280px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.dashboard-main {
    flex: 1;
    min-width: 0; /* Prevents flex overflow */
    padding: 1rem;
}

@media (max-width: 991px) {
    .dashboard-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 1000;
        background: var(--bg-primary, #0a0e27);
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }

    .dashboard-sidebar.active {
        transform: translateX(0);
    }

    .dashboard-main {
        padding: 0.5rem;
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 992px) {
    .dashboard-main {
        padding: 2rem;
    }
}

/* Stats cards responsive */
.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 576px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   FORMS RESPONSIVE
   ============================================ */

.form-row {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row.three-columns {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================
   HEADER / NAVIGATION RESPONSIVE
   ============================================ */

header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--bg-primary, #0a0e27);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    max-width: var(--container-max-width);
    margin: 0 auto;
}

@media (min-width: 768px) {
    .header-content {
        padding: 1rem 2rem;
    }
}

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

@media print {
    .no-print,
    .sidebar,
    .nav-menu,
    button,
    .btn {
        display: none !important;
    }

    * {
        background: white !important;
        color: black !important;
    }

    .container {
        max-width: 100%;
    }
}

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

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--primary, #00d4ff);
    outline-offset: 2px;
}

/* 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) {
    * {
        border-width: 2px;
    }
}
