/* ============================================
   MOBILE RESPONSIVE CSS - All Devices
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* BASE STYLES */
html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f0f4f8;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden;
}

/* TEXT RESPONSIVENESS */
h1 { font-size: clamp(1.5rem, 5vw, 3rem); font-weight: 800; }
h2 { font-size: clamp(1.25rem, 4vw, 2.2rem); font-weight: 700; }
h3 { font-size: clamp(1rem, 3vw, 1.8rem); font-weight: 600; }
h4 { font-size: clamp(0.95rem, 2.5vw, 1.4rem); font-weight: 600; }
h5, h6 { font-size: 1rem; font-weight: 600; }

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

/* BUTTON RESPONSIVENESS */
button, .btn, a.btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 1rem;
    font-size: clamp(0.85rem, 2vw, 1rem);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    touch-action: manipulation;
}

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

/* CONTAINER & LAYOUT */
.container, .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* ============================================
   HEADER/NAVIGATION - MOBILE FIRST
   ============================================ */

.header-content, .topbar {
    padding: 0.75rem 1rem !important;
    flex-wrap: wrap;
}

.brand {
    font-size: clamp(1rem, 4vw, 1.5rem) !important;
    white-space: nowrap;
}

.header-links, nav.header-links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.header-links a {
    font-size: 0.75rem !important;
    padding: 0.4rem 0.6rem !important;
    display: none;
}

.header-links a:nth-child(n+6) {
    display: none;
}

@media (min-width: 768px) {
    .header-links a {
        display: inline-flex !important;
    }
    
    .mobile-nav-drawer {
        display: none !important;
    }
}

/* Mobile hamburger menu */
.mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    gap: 0.35rem;
    padding: 0.5rem;
    margin-left: 0.5rem;
}

.mobile-menu-toggle span {
    width: 24px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
    display: block;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(10px, 10px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

@media (min-width: 768px) {
    .mobile-menu-toggle {
        display: none !important;
    }
}

/* Mobile Navigation Drawer */
.mobile-nav-drawer {
    position: fixed;
    left: -100%;
    top: 60px;
    width: 100%;
    height: auto;
    max-height: calc(100vh - 60px);
    background: white;
    z-index: 999;
    overflow-y: auto;
    transition: left 0.3s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    padding-bottom: 20px;
}

.mobile-nav-drawer.active {
    left: 0;
}

.mobile-nav-drawer a {
    display: block;
    padding: 1rem;
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.mobile-nav-drawer a:hover {
    background: #f5f5f5;
    padding-left: 1.25rem;
}

.mobile-nav-drawer a:active {
    background: #eee;
}

/* ============================================
   SIDEBAR - RESPONSIVE
   ============================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1000;
    overflow-y: auto;
    width: 100% !important;
    max-width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.sidebar.active, .sidebar.show {
    transform: translateX(0);
}

.wrapper {
    display: flex;
}

.main-content, .sidebar-content {
    margin-left: 0 !important;
    width: 100%;
}

/* Show sidebar on larger screens */
@media (min-width: 768px) {
    .sidebar {
        position: fixed;
        width: 240px !important;
        max-width: none;
        left: 0;
        transform: translateX(0);
    }
    
    .main-content, .sidebar-content {
        margin-left: 240px !important;
    }
    
    .mobile-menu-toggle {
        display: none !important;
    }
    
    .mobile-nav-drawer {
        display: none !important;
    }
}

/* Sidebar toggle for mobile */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    color: white;
    font-size: 1.5rem;
}

/* ============================================
   GRID & LAYOUT - MOBILE FIRST
   ============================================ */

.panels-grid, .stats-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (min-width: 480px) {
    .panels-grid, .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (min-width: 768px) {
    .panels-grid, .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .panels-grid, .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 2rem;
    }
}

/* Cards */
.card, .panel-card, .stat-card, .section-card {
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

@media (min-width: 480px) {
    .card, .panel-card, .stat-card, .section-card {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }
}

@media (min-width: 768px) {
    .card, .panel-card, .stat-card, .section-card {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
}

/* ============================================
   TABLES - MOBILE RESPONSIVE
   ============================================ */

.table-wrapper {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

@media (min-width: 768px) {
    table {
        font-size: 0.9rem;
    }
}

table th, table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

@media (max-width: 767px) {
    table thead {
        display: none;
    }
    
    table, table tbody, table tr, table td {
        display: block;
        width: 100%;
    }
    
    table tr {
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 0.5rem;
        overflow: hidden;
    }
    
    table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        border: none;
        border-bottom: 1px solid #eee;
    }
    
    table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.7rem;
        color: #666;
    }
    
    table td:last-child {
        border-bottom: none;
    }
}

/* ============================================
   FORMS - MOBILE FRIENDLY
   ============================================ */

input, textarea, select, .form-control, .form-select {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: 0.5rem;
    border: 1px solid #ddd;
    margin-bottom: 0.5rem;
    touch-action: manipulation;
}

@media (min-width: 768px) {
    input, textarea, select, .form-control, .form-select {
        padding: 0.75rem;
    }
}

.form-group, .form-item {
    margin-bottom: 1rem;
    width: 100%;
}

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

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

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

/* ============================================
   MODAL/DIALOG - MOBILE FRIENDLY
   ============================================ */

.modal-body, .modal-content {
    max-width: 100%;
    border-radius: 0.75rem;
}

@media (max-width: 480px) {
    .modal-content {
        width: 95vw;
        max-width: none;
    }
    
    .modal-body {
        max-height: 80vh;
        overflow-y: auto;
    }
}

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

img {
    max-width: 100%;
    height: auto;
    display: block;
}

picture {
    display: block;
    width: 100%;
}

video {
    max-width: 100%;
    height: auto;
}

/* ============================================
   SPACING - RESPONSIVE PADDING/MARGIN
   ============================================ */

.px-responsive {
    padding: 1rem;
}

@media (min-width: 480px) {
    .px-responsive {
        padding: 1.25rem;
    }
}

@media (min-width: 768px) {
    .px-responsive {
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .px-responsive {
        padding: 2rem;
    }
}

/* ============================================
   DISPLAY & VISIBILITY
   ============================================ */

.hide-mobile {
    display: none;
}

.hide-desktop {
    display: block;
}

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

/* ============================================
   VIEWPORT SPECIFIC (Mobile First)
   ============================================ */

/* Extra Small (< 480px) */
@media (max-width: 479px) {
    .topbar,
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.75rem !important;
    }
    
    .section-card-header,
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .main-content {
        padding: 1rem !important;
    }
}

/* Small (480px - 767px) */
@media (min-width: 480px) and (max-width: 767px) {
    .main-content {
        padding: 1.25rem !important;
    }
    
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Medium (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .main-content {
        padding: 1.5rem !important;
    }
}

/* Large (1024px+) */
@media (min-width: 1024px) {
    .main-content {
        padding: 2rem !important;
    }
    
    .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* ============================================
   LANDSCAPE MODE (Mobile)
   ============================================ */

@media (max-height: 600px) and (orientation: landscape) {
    .sidebar {
        max-height: 100%;
        overflow-y: auto;
    }
    
    h1, h2 {
        font-size: clamp(1rem, 3vw, 1.5rem);
    }
    
    .main-content {
        padding: 0.75rem 1rem;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    button,
    a,
    .btn,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    a:active,
    button:active {
        background-color: rgba(0, 0, 0, 0.1);
    }
}

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

@media print {
    .sidebar,
    .header,
    .topbar,
    .mobile-menu-toggle,
    nav,
    button,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0;
    }
    
    body {
        background: white;
    }
}

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

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

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

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

/* Safe area for notch/punch-hole compatibility */
.safe-area-top {
    padding-top: max(1rem, env(safe-area-inset-top));
}

.safe-area-bottom {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.safe-area-left {
    padding-left: max(1rem, env(safe-area-inset-left));
}

.safe-area-right {
    padding-right: max(1rem, env(safe-area-inset-right));
}
