/* ===================================================================
 * AI Smart Bidding System - Responsive Design
 * Breakpoints: 992px (tablet), 768px (mobile), 576px (small mobile)
 * =================================================================== */

/* ============= Tablet (<= 992px) ============= */
@media (max-width: 991.98px) {
    /* Navigation: hide inline links, show hamburger */
    .main-nav .navbar-brand span {
        font-size: 0.95rem;
    }

    #navUserArea {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background: #fff;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 12px 16px;
        gap: 4px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        z-index: 1030;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    #navUserArea.show {
        max-height: 600px;
        overflow-y: auto;
    }

    #navUserArea .nav-link-custom {
        padding: 10px 12px;
        border-radius: 8px;
        margin: 0;
        width: 100%;
        justify-content: flex-start;
    }

    #navUserArea .nav-link-custom:hover {
        background: var(--primary-light);
    }

    #navUserArea .dropdown {
        width: 100%;
    }

    #navUserArea .dropdown-menu {
        position: static;
        min-width: 100%;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--gray-200);
    }

    /* Mobile nav toggle button */
    .nav-toggle-btn {
        display: inline-flex !important;
    }

    /* Container: reduce padding */
    .container-fluid.px-4 {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Editor layout: hide right sidebar, full-width editor */
    .editor-layout {
        flex-direction: column;
        height: auto !important;
    }

    .sidebar-left {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 280px;
        border-right: none !important;
        border-bottom: 1px solid var(--gray-200);
    }

    .sidebar-right {
        display: none !important;
    }

    .editor-main {
        width: 100%;
        min-height: 400px;
    }

    /* Editor toolbar: wrap buttons */
    .editor-toolbar {
        flex-wrap: wrap;
        gap: 4px;
    }

    .editor-toolbar button {
        padding: 4px 6px;
        font-size: 0.8rem;
    }

    .editor-toolbar button .btn-label {
        display: none;
    }

    /* Editor main header */
    .editor-main-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
    }

    .editor-main-header .chapter-meta {
        width: 100%;
        flex-wrap: wrap;
    }

    /* Project detail header */
    .project-detail-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
    }

    .project-detail-header .btn-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .project-detail-header .btn-group .btn {
        flex: 1;
        font-size: 0.8rem;
    }

    /* Dashboard charts: adjust heights */
    canvas {
        max-height: 180px !important;
    }

    /* Knowledge base layout */
    .kb-layout {
        flex-direction: column;
    }

    .kb-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 240px;
        margin-bottom: 12px;
    }

    /* Login page */
    .login-container {
        max-width: 100% !important;
        margin: 16px !important;
    }
}

/* ============= Mobile (<= 768px) ============= */
@media (max-width: 767.98px) {
    /* Navigation brand */
    .main-nav .navbar-brand img.brand-logo {
        height: 28px;
    }

    .main-nav .navbar-brand span {
        font-size: 0.85rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }

    /* Container: minimal padding */
    .container-fluid.px-4,
    .container-fluid.py-3 {
        padding-left: 8px !important;
        padding-right: 8px !important;
        padding-top: 8px !important;
    }

    /* Cards: reduce padding */
    .card {
        margin-bottom: 12px;
    }

    .card-body {
        padding: 12px;
    }

    .card-header {
        padding: 10px 12px;
    }

    /* Stat cards: single column */
    .stat-card {
        padding: 12px;
    }

    .stat-card .stat-number {
        font-size: 1.5rem;
    }

    .stat-card .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    /* Project cards: full width */
    .project-card {
        margin-bottom: 10px;
    }

    .project-card .card-body {
        padding: 10px 12px;
    }

    /* Tables: ensure horizontal scroll */
    .table {
        font-size: 0.8rem;
    }

    .table th,
    .table td {
        padding: 6px 8px;
        white-space: nowrap;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Modal: full screen on mobile */
    .modal-dialog {
        margin: 8px;
        max-width: calc(100% - 16px);
    }

    .modal-body {
        padding: 12px;
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Forms: stack labels and inputs */
    .form-label {
        margin-bottom: 4px;
        font-size: 0.85rem;
    }

    .form-control,
    .form-select {
        font-size: 0.9rem;
    }

    /* Button groups: full width */
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    .d-flex.gap-2 .btn {
        flex: 1;
        min-width: 80px;
    }

    /* Dashboard: stack all charts */
    .col-lg-3,
    .col-lg-4,
    .col-lg-5,
    .col-lg-6,
    .col-lg-7 {
        width: 100%;
    }

    canvas {
        max-height: 160px !important;
    }

    /* Chapter editor: minimal padding */
    .editor-content {
        padding: 12px;
        font-size: 0.9rem;
    }

    .editor-content h1 { font-size: 1.3rem; }
    .editor-content h2 { font-size: 1.1rem; }
    .editor-content h3 { font-size: 1rem; }

    /* Chapter tree: compact */
    .chapter-tree .chapter-node {
        padding: 4px 8px;
        font-size: 0.85rem;
    }

    /* Knowledge base: compact */
    .kb-folder-item {
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    /* Page titles */
    h1, h2, h3 {
        word-break: break-word;
    }

    /* Alert messages: full width */
    .alert {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* Badges: smaller */
    .badge {
        font-size: 0.7rem;
        padding: 3px 6px;
    }

    /* Dropdown menus: full width */
    .dropdown-menu {
        min-width: 200px;
    }

    /* Footer */
    footer {
        text-align: center;
        font-size: 0.8rem;
    }
}

/* ============= Small Mobile (<= 576px) ============= */
@media (max-width: 575.98px) {
    /* Navigation: even smaller brand */
    .main-nav .navbar-brand span {
        display: none;
    }

    .main-nav .navbar-brand img.brand-logo {
        height: 32px;
    }

    /* Container: minimal padding */
    .container-fluid {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    /* Cards: minimal padding */
    .card-body {
        padding: 8px 10px;
    }

    /* Stat cards: very compact */
    .stat-card {
        padding: 8px;
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .stat-card .stat-number {
        font-size: 1.2rem;
    }

    .stat-card .stat-label {
        font-size: 0.7rem;
    }

    .stat-card .stat-icon {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    /* Tables: very compact */
    .table {
        font-size: 0.75rem;
    }

    .table th,
    .table td {
        padding: 4px 6px;
    }

    /* Modal: near full screen */
    .modal-dialog {
        margin: 4px;
        max-width: calc(100% - 8px);
    }

    .modal-header {
        padding: 8px 12px;
    }

    .modal-title {
        font-size: 0.95rem;
    }

    /* Editor content: very compact */
    .editor-content {
        padding: 8px;
        font-size: 0.85rem;
    }

    /* Buttons: compact */
    .btn {
        padding: 4px 10px;
        font-size: 0.8rem;
    }

    .btn-sm {
        padding: 2px 8px;
        font-size: 0.75rem;
    }

    /* Chapter tree: very compact */
    .chapter-tree .chapter-node {
        padding: 3px 6px;
        font-size: 0.8rem;
    }

    .chapter-tree .chapter-node .chapter-icon {
        font-size: 0.8rem;
    }

    /* Canvas charts: very small */
    canvas {
        max-height: 140px !important;
    }

    /* Project header buttons: stack */
    .project-detail-header .btn-group {
        flex-direction: column;
    }

    .project-detail-header .btn-group .btn {
        width: 100%;
        border-radius: 6px !important;
        margin-bottom: 4px;
    }

    /* Tabs: scrollable */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 6px 10px;
    }
}

/* ============= Print styles ============= */
@media print {
    .main-nav,
    .nav-toggle-btn,
    .sidebar-left,
    .sidebar-right,
    .editor-toolbar,
    .btn-group,
    .no-print {
        display: none !important;
    }

    .editor-layout {
        display: block;
        height: auto !important;
    }

    .editor-main {
        width: 100%;
        overflow: visible !important;
    }

    .editor-content {
        overflow: visible !important;
    }
}

/* ============= Landscape phone fix ============= */
@media (max-width: 991.98px) and (orientation: landscape) {
    #navUserArea.show {
        max-height: 400px;
    }

    .sidebar-left {
        max-height: 200px;
    }
}
