/* Shared phone and small-tablet layout rules for SmartLab pages. */
@media (max-width: 767.98px) {
    html { -webkit-text-size-adjust: 100%; }
    body { min-width: 320px; overflow-x: hidden; }
    img, video, canvas, svg { max-width: 100%; }
    .container, .container-fluid { --bs-gutter-x: 1.25rem; }

    .navbar .container,
    .navbar .container-fluid {
        flex-wrap: wrap !important;
        row-gap: .55rem;
    }
    .navbar .navbar-brand { max-width: 100%; margin-right: 0; white-space: normal; }
    .navbar-custom .navbar-brand img { max-width: 42vw; object-fit: contain; }
    .navbar-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: .45rem !important;
    }
    .navbar-actions > button,
    .navbar-actions > a,
    .navbar-actions > .dropdown > button { min-height: 40px; }
    .navbar-custom .navbar-actions .dropdown { position: static; }
    .navbar-custom .navbar-actions .dropdown-menu {
        position: absolute;
        z-index: 1080;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        top: calc(100% + 4px) !important;
        max-width: calc(100vw - 24px);
    }
    .navbar-custom .navbar-actions .notification-menu {
        width: min(300px, calc(100vw - 24px)) !important;
        max-height: min(400px, 55vh) !important;
        overflow-y: auto;
    }
    .navbar .container-fluid > .navbar-brand { flex: 1 1 auto; }
    .navbar .container-fluid > .btn { white-space: normal; }

    .table-responsive { max-width: 100%; -webkit-overflow-scrolling: touch; }
    .table-responsive > .table { min-width: 620px; }
    .modal-dialog { margin: .5rem; }
    .modal-content { max-height: calc(100dvh - 1rem); overflow-y: auto; }
    .card-table { padding: 14px !important; }

    .admin-filter-form { width: 100%; }
    .admin-filter-form .form-control,
    .admin-filter-form .form-select { width: 100% !important; max-width: none !important; }
    .admin-quick-actions { width: 100%; display: flex; flex-wrap: wrap; }
    .admin-quick-actions > * { flex: 1 1 145px; justify-content: center; }

    .report-container { width: 100%; margin: 16px auto !important; padding: 20px !important; }
    .report-container .report-header img { height: 48px !important; }
    .report-container .row.text-center > [class*="col-3"] {
        width: 50%;
        padding: .75rem .35rem;
        border-right: 0 !important;
        border-bottom: 1px solid rgba(148,163,184,.35);
    }
    .report-container .row.text-center > [class*="col-3"] h6 { font-size: .62rem; }
    .report-container .row.text-center > [class*="col-3"] h3 { font-size: 1.35rem; }

    .scanner-card { width: 100%; margin: 20px auto !important; padding: 20px !important; }
    #reader { width: 100% !important; max-width: 100%; }
    .receipt-card { width: calc(100% - 24px) !important; margin: 12px; padding: 24px !important; }
    .return-card .card-body { padding: 1.25rem !important; }
}

@media (max-width: 575.98px) {
    .container, .container-fluid { --bs-gutter-x: 1rem; }
    .admin-quick-actions > * { flex-basis: 100%; }
    .report-container { padding: 16px !important; }
    .report-container .report-header .d-flex { gap: 1rem !important; }
    .report-container .report-header img { height: 42px !important; }
    .report-container .table-responsive > .table { min-width: 720px; }
}

/* Small-screen polish shared across the borrower, admin and account pages. */
@media (max-width: 767.98px) {
    body { overflow-x: clip; }

    /* Comfortable touch targets and readable form text on phones. */
    .btn, .form-control, .form-select { min-height: 44px; }
    input.form-control, select.form-select, textarea.form-control { font-size: 16px; }
    .form-label { margin-bottom: .4rem; }

    /* Keep the two institutional marks and navbar controls from pushing the page wide. */
    .navbar .container,
    .navbar .container-fluid { min-width: 0; column-gap: .5rem; }
    .navbar .navbar-brand { min-width: 0; overflow: hidden; }
    .navbar-custom .navbar-brand img { flex: 0 0 auto; }
    .navbar-actions { row-gap: .5rem; }
    .navbar-actions > button,
    .navbar-actions > a,
    .navbar-actions > .dropdown > button { flex-shrink: 0; }

    /* Stack content cleanly while keeping dense data inside its own swipe area. */
    .card-table { min-width: 0; padding: 16px !important; border-radius: 16px; }
    .table-responsive { border-radius: 10px; scrollbar-width: thin; }
    .table-responsive > .table { margin-bottom: 0; }
    .table-responsive > .table th,
    .table-responsive > .table td { vertical-align: middle; }
    .report-container { border-radius: 16px; }

    /* Admin filters and shortcuts become an easy-to-scan touch layout. */
    .admin-filter-form {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .6rem !important;
    }
    .admin-filter-form input[type="search"],
    .admin-filter-form button[type="submit"],
    .admin-filter-form > a { grid-column: 1 / -1; }
    .admin-filter-form .form-control,
    .admin-filter-form .form-select { min-width: 0; }
    .admin-quick-actions { flex-direction: column; gap: .6rem !important; }
    .admin-quick-actions > * { width: 100%; flex-basis: auto; min-height: 44px; }
    .stat-card { min-height: 132px; padding: 18px; border-radius: 16px; }
    .stat-card .icon-bg { font-size: 5rem; }
    .dashboard-hero { margin-bottom: 20px; }

    /* Prevent long names, codes and modal content from stretching the viewport. */
    .dashboard-hero h1,
    .card h1, .card h2, .card h3, .card h4, .card h5,
    .card-table h1, .card-table h2, .card-table h3, .card-table h4, .card-table h5 {
        overflow-wrap: anywhere;
    }
    .modal-dialog { width: auto; max-width: none; }
    .modal-content { border-radius: 16px; }
    .dropdown-menu { max-width: calc(100vw - 24px); }
    .dropdown-item { white-space: normal; }

    /* Give the long admin charts less empty height on a phone. */
    #trendChart, #pieChart { max-width: 100%; }
    .card-table canvas { max-width: 100%; }
}

@media (max-width: 575.98px) {
    body.login-page > .container.p-3 { padding: 4.5rem 1rem 1.25rem !important; }
    .login-card, .login-card > .row { width: 100%; min-height: 0 !important; }
    .login-card .left-panel { min-height: 136px; }
    .login-card .right-panel { padding: 24px 18px !important; }
    .login-card .form-control, .login-card .btn-custom { min-height: 48px; }
    .auth-menu-icon { top: 12px; left: 12px; width: 42px; height: 42px; }
    .welcome-card { width: calc(100% - 28px); padding: 28px 20px !important; border-radius: 22px; }
    .welcome-card h2 { font-size: clamp(1.35rem, 6vw, 1.8rem); overflow-wrap: anywhere; }

    .dashboard-hero { padding: 20px 16px; }
    .dashboard-hero h1 { font-size: clamp(1.45rem, 7vw, 2rem); }
    .hero-date { padding: 8px 11px; font-size: .82rem; }
    .summary-card { min-height: 76px; }
    .borrowed-section-header { flex-wrap: wrap; }
    .borrowed-section-header .receipt-button { min-height: 40px; }
    .borrowed-asset-card { grid-template-columns: 50px minmax(0, 1fr) 40px; gap: 8px !important; padding: 10px !important; }
    .borrowed-asset-card > img { width: 50px !important; height: 50px !important; }
    .borrowed-asset-info { font-size: .9rem; }
    .borrowed-asset-info .badge { white-space: normal; text-align: left; }

    .catalog-filter { padding: .6rem !important; border-radius: 16px !important; }
    .catalog-filter .form-control,
    .catalog-filter .form-select,
    .catalog-filter .btn { min-height: 46px; }
    .catalog-filter .col-6 { min-width: 0; }
    .card-asset { height: 100%; border-radius: 17px; overflow: hidden; }
    .card-asset .card-body { padding: 14px !important; }
    .card-asset h5 { font-size: 1rem; }
    .card-asset .btn { min-height: 44px; }

    .card-custom { padding: 16px !important; }
    .report-container { margin: 12px auto !important; padding: 16px !important; }
    .report-container .report-header h4 { font-size: 1rem; }
    .report-container .report-header h5 { font-size: .95rem; }
    .report-container .report-header img { max-width: 40vw; }
    .scanner-card { margin: 16px auto !important; padding: 18px !important; border-radius: 18px; }
    .receipt-card { width: calc(100% - 20px) !important; margin: 10px; padding: 18px !important; }
    .return-card { border-radius: 18px; }
    .smartlab-contact-footer .contact-card { padding: 14px; }
    .smartlab-contact-footer .footer-bottom { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
