/**
 * Enhanced Responsive Stylesheet for Binary MLM
 * Mobile-First, Touch-Optimized Design
 */

/* ==================== Responsive Design Breakpoints ==================== */
/* Large Tablets and Small Desktops (992px - 1200px) */
@media (max-width: 1200px) {
    .container {
        max-width: 960px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .sidebar {
        width: 220px;
    }

    .main-content {
        margin-left: 220px;
    }

    .content-wrapper {
        padding: 1.5rem;
    }

    .charts-grid {
        grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    }
}

/* Tablets (768px - 992px) */
@media (max-width: 992px) {
    .container {
        max-width: 720px;
    }

    /* Column adjustments for medium screens */
    .col-md-12 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .col-md-4 {
        flex: 0 0 33.33%;
        max-width: 33.33%;
    }

    .col-md-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }

    /* Stats grid for tablets */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Sidebar adjustments */
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
    }

    /* Typography scaling */
    h1 {
        font-size: 2rem !important;
    }

    h2 {
        font-size: 1.75rem !important;
    }

    h3 {
        font-size: 1.375rem !important;
    }

    /* Button groups stack on tablets */
    .btn-group {
        flex-wrap: wrap;
    }

    /* Topbar adjustments */
    .topbar {
        padding: 1rem 1.5rem;
    }

    .topbar-title {
        font-size: 1.125rem;
    }

    /* Content wrapper */
    .content-wrapper {
        padding: 1.5rem;
    }

    /* Card adjustments */
    .card {
        padding: 1.25rem;
    }

    /* Table responsive behavior */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }
}

/* Mobile Landscape & Small Tablets (576px - 768px) */
@media (max-width: 768px) {

    /* Sidebar mobile behavior */
    .sidebar {
        position: fixed !important;
        transform: translateX(-100%);
        width: 280px;
        z-index: 1060;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1050;
        cursor: pointer;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        display: block;
        pointer-events: auto;
    }

    /* Main content adjustments */
    .main-content {
        margin-left: 0 !important;
        width: 100%;
    }

    /* Menu toggle visible on mobile */
    .menu-toggle {
        display: block !important;
    }

    /* Column adjustments for small screens */
    .col-sm-12,
    .col-6,
    .col-4,
    .col-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Stats grid single column */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Typography for mobile */
    h1 {
        font-size: 1.75rem !important;
    }

    h2 {
        font-size: 1.5rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    h4 {
        font-size: 1.125rem !important;
    }

    /* Topbar mobile */
    .topbar {
        padding: 0.875rem 1rem;
    }

    .topbar-title {
        font-size: 1rem;
    }

    .topbar-right {
        gap: 0.5rem;
    }

    /* Hide user name on very small screens */
    .user-info {
        display: none;
    }

    /* Content wrapper */
    .content-wrapper {
        padding: 1rem;
    }

    /* Cards */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Stat cards mobile */
    .stat-card {
        padding: 1rem;
        gap: 1rem;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    /* Buttons mobile */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
    }

    /* Forms mobile */
    .form-group {
        margin-bottom: 1.25rem;
    }

    /* Tables mobile - card style */
    .table-responsive {
        border: 0;
    }

    .table-responsive .table thead {
        display: none;
    }

    .table-responsive .table,
    .table-responsive .table tbody,
    .table-responsive .table tr,
    .table-responsive .table td {
        display: block;
        width: 100%;
    }

    .table-responsive .table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
        background: white;
    }

    .table-responsive .table td {
        padding: 0.5rem 0;
        border: none;
        position: relative;
        padding-left: 50%;
        text-align: right;
    }

    .table-responsive .table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-left: 0;
        font-weight: 600;
        text-align: left;
        color: var(--text-dark);
    }

    /* Modal mobile */
    .modal-content {
        width: 95%;
        margin: 1rem;
    }

    /* Navigation tabs mobile - scrollable */
    .nav-tabs-modern {
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-tabs-modern::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs-modern .nav-link {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }

    /* Charts grid */
    .charts-grid {
        grid-template-columns: 1fr !important;
    }

    .charts-grid .card {
        height: 350px;
    }

    /* Binary tree mobile */
    .binary-tree-container {
        padding: 1rem;
    }

    .tree-branches {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }

    .tree-branches::before,
    .tree-branches::after {
        display: none;
    }

    .branch-left::before,
    .branch-right::before {
        display: none;
    }

    .node-card {
        min-width: 100%;
    }

    .tree-node {
        margin: 0.5rem 0;
    }
}

/* Mobile Portrait (320px - 576px) */
@media (max-width: 576px) {

    /* Container full width on mobile */
    .container {
        padding: 0 0.75rem;
    }

    /* All columns full width */
    .col-xs-12,
    .col-1,
    .col-2,
    .col-3,
    .col-4,
    .col-5,
    .col-6,
    .col-7,
    .col-8,
    .col-9,
    .col-10,
    .col-11,
    .col-12 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Content wrapper minimal padding */
    .content-wrapper {
        padding: 0.75rem !important;
    }

    /* Topbar compact */
    .topbar {
        padding: 0.75rem !important;
    }

    .topbar-title {
        font-size: 0.875rem;
    }

    /* Typography extra small screens */
    h1 {
        font-size: 1.5rem !important;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.375rem !important;
    }

    h3 {
        font-size: 1.125rem !important;
    }

    h4,
    h5,
    h6 {
        font-size: 1rem !important;
    }

    /* Buttons touch-friendly */
    .btn {
        padding: 0.75rem 1.25rem !important;
        font-size: 0.9375rem;
        min-height: 44px;
        width: 100%;
    }

    .btn-sm {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 40px;
    }

    .btn-lg {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        min-height: 48px;
    }

    /* Touch-friendly form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    select,
    textarea,
    .form-control,
    .form-select {
        min-height: 44px !important;
        font-size: 16px !important;
        /* Prevent iOS zoom */
        padding: 0.75rem;
    }

    textarea.form-control {
        min-height: 120px !important;
    }

    .form-label {
        font-size: 0.9375rem;
        margin-bottom: 0.375rem;
    }

    /* Checkboxes and radios touch-friendly */
    .form-check-input {
        width: 20px;
        height: 20px;
        margin-right: 0.75rem;
    }

    /* Cards compact */
    .card {
        padding: 0.875rem !important;
        margin-bottom: 0.875rem !important;
        border-radius: 8px;
    }

    .card-header {
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .card-title {
        font-size: 1.125rem;
    }

    .card-footer {
        padding-top: 0.75rem;
        margin-top: 0.75rem;
    }

    /* Stat cards mobile optimized */
    .stat-card {
        padding: 1rem !important;
        gap: 0.875rem;
        flex-direction: row;
    }

    .stat-icon {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.125rem !important;
        border-radius: 10px;
    }

    .stat-value {
        font-size: 1.375rem !important;
    }

    .stat-label {
        font-size: 0.8125rem !important;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    /* Tables - mobile card view */
    .table {
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.625rem 0.375rem;
        font-size: 0.8125rem;
    }

    .table-responsive .table td:before {
        font-size: 0.8125rem;
    }

    /* Badges smaller */
    .badge {
        padding: 0.25rem 0.625rem;
        font-size: 0.8125rem;
    }

    /* Alerts compact */
    .alert {
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }

    /* Modal full screen on mobile */
    .modal {
        padding: 0 !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0;
        min-height: 100vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem !important;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* User avatar smaller */
    .user-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.875rem;
    }

    /* Sidebar mobile full width option */
    .sidebar {
        width: 85vw !important;
        max-width: 300px !important;
    }

    .sidebar-logo {
        font-size: 1.25rem;
        margin-bottom: 1.5rem;
    }

    .sidebar-menu a {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    .sidebar-menu .menu-icon {
        margin-right: 0.625rem;
        font-size: 1.125rem;
    }

    /* Utility spacing adjustments */
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }

    .mb-3 {
        margin-bottom: 1rem !important;
    }

    .mt-4 {
        margin-top: 1.5rem !important;
    }

    .mt-3 {
        margin-top: 1rem !important;
    }

    .p-4 {
        padding: 1.5rem !important;
    }

    .p-3 {
        padding: 1rem !important;
    }

    /* Dashboard welcome */
    .dashboard-welcome h1 {
        font-size: 1.5rem !important;
    }

    .dashboard-welcome p {
        font-size: 0.875rem;
    }

    /* User badges */
    .user-badges {
        gap: 0.5rem;
    }

    .user-badges .badge {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }

    /* Dashboard update indicator */
    .dashboard-update-indicator {
        bottom: 10px;
        right: 10px;
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }
}

/* ==================== Touch Device Optimizations ==================== */
@media (hover: none) and (pointer: coarse) {

    /* Larger clickable areas for touch devices */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.625rem 1.25rem;
    }

    /* Increase sidebar menu item size */
    .sidebar-menu a {
        padding: 1rem 1.25rem;
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .card:hover {
        transform: none !important;
    }

    /* Better spacing for dropdowns */
    .dropdown-menu a {
        padding: 0.875rem 1rem;
        min-height: 44px;
    }

    /* Touch-friendly checkboxes */
    .form-check-input {
        width: 22px;
        height: 22px;
    }

    /* Stat cards no hover */
    .stat-card:hover {
        transform: none !important;
    }

    /* Links have better touch targets */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* ==================== Landscape Orientation (Mobile) ==================== */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        overflow-y: auto;
        max-height: 100vh;
    }

    .modal-content {
        max-height: 95vh;
        overflow-y: auto;
    }

    .topbar {
        position: static;
    }
}

/* ==================== Print Styles ==================== */
@media print {

    .sidebar,
    .topbar,
    .menu-toggle,
    .btn,
    .modal,
    .alert {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd;
    }

    .content-wrapper {
        padding: 0 !important;
    }

    body {
        background: white !important;
    }
}