/* ============================================================================
   RESPONSIVE DESIGN OVERRIDES
   ============================================================================ */

/* Navigation Breakpoint (up to 1200px) */
@media (max-width: 1200px) {
    .navbar-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 0.75rem 1rem;
    }

    .navbar-brand {
        width: 100%;
        justify-content: space-between;
    }

    .navbar-menu {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
        background: var(--bg-white);
        padding-top: 1rem;
        border-top: 1px solid var(--border-color);
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-link {
        width: 100%;
        text-align: center;
        padding: 0.75rem;
        background: var(--bg-main);
    }

    .user-menu {
        width: 100%;
        justify-content: space-between;
        margin-top: 1rem;
        margin-left: 0;
        border-top: 1px solid var(--border-color);
        padding-top: 1rem;
    }

    .navbar-toggle {
        display: block !important;
    }
}

/* Mobile & Tablet (up to 768px) */
@media (max-width: 768px) {

    /* --- Typography & Layout --- */
    body {
        font-size: 13px;
    }

    .container {
        padding: 1rem;
    }

    /* --- Dashboard Grids --- */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    /* --- Forms --- */
    .auth-card {
        padding: 1.5rem;
    }

    .form-actions {
        flex-direction: column;
        gap: 1rem;
    }

    .form-actions .btn {
        width: 100%;
    }

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

    .table {
        min-width: 600px;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    /* --- Modals --- */
    .modal {
        width: 95% !important;
        max-width: 95% !important;
        margin: 0.5rem auto !important;
        padding: 1.25rem;
        background: var(--bg-white);
    }
}

/* Fix dark mode for mobile inputs/navigation if overridden */
@media (max-width: 768px) {
    :root[data-theme="dark"] .navbar-menu {
        background: var(--bg-white);
        border-top-color: var(--border-color);
    }

    :root[data-theme="dark"] .navbar-link {
        background: var(--bg-main);
        color: var(--text-secondary);
    }

    :root[data-theme="dark"] .navbar-link:hover,
    :root[data-theme="dark"] .navbar-link.active {
        color: var(--primary);
    }
}

/* Tablet Landscape / Small Laptops (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Hide the subtitle on smaller desktop screens to save space */
@media (max-width: 1450px) {
    .navbar-brand div div:last-child {
        display: none;
    }
}

/* ============================================================================
   OVERRIDE INLINE GRID STYLES ON SMALL SCREENS
   (Inline styles have high specificity, so !important is required)
   ============================================================================ */

@media (max-width: 768px) {
    /* Collapse multi-column inline grids to 2 columns */
    [style*="grid-template-columns: repeat(5"],
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    /* Collapse 2-column inline grids to single column */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns: 1fr 2.5fr"],
    [style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* Allow action rows to wrap */
    .action-row {
        white-space: normal !important;
    }
    [style*="white-space: nowrap"] {
        white-space: normal !important;
    }
    /* Ensure table containers scroll horizontally */
    .table-container[style*="overflow: hidden"] {
        overflow-x: auto !important;
    }
}

@media (max-width: 480px) {
    [style*="grid-template-columns: repeat(5"],
    [style*="grid-template-columns: repeat(4"],
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }
}

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.25rem;
}