body {
    overflow-x: hidden;
    background: #f6f8fb;
}

body.dark-mode {
    background: #0f172a;
    color: #e5e7eb;
}

* {
    box-sizing: border-box;
}

/* Top navigation layout */
.navbar {
    background: #ffffff !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #0f172a !important;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0;
}

.topnav-faculty-logo {
    display: block;
    width: 190px;
    max-width: min(32vw, 190px);
    height: 48px;
    object-fit: contain;
    object-position: left center;
}

.auth-faculty-logo-link {
    display: block;
    width: min(520px, calc(100vw - 32px));
}

.auth-faculty-logo {
    display: block;
    width: 100%;
    max-height: 132px;
    object-fit: contain;
}

.navbar .nav-link {
    margin-right: 4px;
    padding: 8px 14px !important;
    border-radius: 8px;
    color: #475569 !important;
    font-weight: 500;
    transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
    font-size: 0.85rem;
}

.navbar .nav-link:hover {
    background: #eef4ff;
    color: #0d6efd !important;
}

.navbar .active-link,
.active-link {
    background: #0d6efd !important;
    color: #ffffff !important;
    font-weight: 700;
}

.navbar .active-link:hover {
    background: #0d6efd !important;
    color: #ffffff !important;
}

.navbar-toggler {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.topnav-container {
    gap: 4px;
}

.topnav-content {
    width: 100%;
    max-width: 100%;
    padding: 0 20px 20px;
}

.topnav-header {
    gap: 12px;
}

.topnav-brand-group {
    min-width: 0;
    gap: 12px;
}

.topnav-actions {
    min-width: 0;
}

.navbar-collapse {
    min-width: 0;
}

.topnav-user-link {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topnav-logout-form {
    margin: 0;
}

.topnav-logout-button {
    white-space: nowrap;
}

.language-switch-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.language-flag {
    display: inline-block;
    width: 22px;
    height: 15px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.18);
    object-fit: cover;
}

.topnav-menu {
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 100%;
    min-width: 0;
}

.topnav-menu .nav-item {
    display: flex;
    max-width: 100%;
}

.topnav-menu .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    max-width: 100%;
    margin-right: 0;
    white-space: nowrap;
}

/* Shared Bootstrap refinements */
.card {
    border: 0;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

.btn {
    border-radius: 8px;
    font-weight: 500;
}

.settings-section-toggle {
    color: #0f172a;
    font-weight: 700;
    text-align: left;
}

.settings-section-toggle-icon {
    transition: transform 0.15s ease-in-out;
}

.settings-section-toggle[aria-expanded="true"] .settings-section-toggle-icon {
    transform: rotate(180deg);
}

.auth-bootstrap-card {
    width: 100%;
}

.auth-bootstrap-card .btn,
.guest-action-button {
    white-space: nowrap;
}

@media (max-width: 380px) {
    .auth-bootstrap-card .btn,
    .guest-action-button {
        padding-right: 0.65rem;
        padding-left: 0.65rem;
        font-size: 0.88rem;
    }
}

.table {
    background: #ffffff;
}

body.dark-mode .navbar,
body.dark-mode .card,
body.dark-mode .table,
body.dark-mode .modal-content,
body.dark-mode .dropdown-menu,
body.dark-mode .list-group-item {
    background: #1e293b !important;
    color: #e5e7eb;
}

body.dark-mode .navbar {
    border-color: #334155 !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
}

body.dark-mode .navbar-brand,
body.dark-mode .navbar .nav-link,
body.dark-mode .topnav-user-link,
body.dark-mode .card-header,
body.dark-mode .settings-section-toggle,
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
    color: #f8fafc !important;
}

body.dark-mode .card-header,
body.dark-mode .settings-section-toggle {
    background: #1e293b !important;
    border-color: #334155 !important;
}

body.dark-mode .navbar .nav-link:hover {
    background: #334155;
    color: #ffffff !important;
}

body.dark-mode .form-control,
body.dark-mode .form-select,
body.dark-mode textarea,
body.dark-mode input {
    border-color: #475569;
    background-color: #0f172a;
    color: #e5e7eb;
}

body.dark-mode .form-control::placeholder {
    color: #94a3b8;
}

body.dark-mode .form-text,
body.dark-mode .text-muted {
    color: #94a3b8 !important;
}

body.dark-mode .table-bordered,
body.dark-mode .table-bordered > :not(caption) > * {
    border-color: #334155;
}

body.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-bg-type: #172033;
    color: #e5e7eb;
}

body.dark-mode .table-dark {
    --bs-table-bg: #020617;
    --bs-table-color: #f8fafc;
}

body.dark-mode .report-table th:first-child,
body.dark-mode .report-table td:first-child {
    background: #1e293b;
}

body.dark-mode .report-table thead th:first-child {
    background: #020617;
}

body.dark-mode .table-preferences-menu,
body.dark-mode .procurement-status-card,
body.dark-mode .chemical-profile-kpi,
body.dark-mode .chemical-profile-meta span {
    border-color: #334155;
    background: #172033;
    color: #e5e7eb;
}

body.dark-mode .table-preference-item:hover {
    background: #334155;
}

body.dark-mode .dashboard-kpi strong,
body.dark-mode .procurement-status-card strong,
body.dark-mode .chemical-profile-kpi strong {
    color: #f8fafc;
}

body.dark-mode .btn-light,
body.dark-mode .btn-outline-secondary {
    border-color: #475569;
    background: #1e293b;
    color: #e5e7eb;
}

body.dark-mode .btn-light:hover,
body.dark-mode .btn-outline-secondary:hover {
    background: #334155;
    color: #ffffff;
}

.table-responsive {
    width: 100%;
}

.table thead th {
    font-size: 0.85rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.table-preferences {
    position: relative;
    display: inline-flex;
}

.table-preferences-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 100;
    display: none;
    width: min(280px, calc(100vw - 24px));
    max-height: 320px;
    padding: 8px;
    overflow-y: auto;
    border: 1px solid #d9e2ef;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.table-preferences:hover .table-preferences-menu,
.table-preferences:focus-within .table-preferences-menu {
    display: block;
}

.table-preference-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    font-size: 0.92rem;
    cursor: pointer;
}

.table-preference-item:hover {
    background: #f1f5f9;
}

.table-preference-item span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.table-preference-divider {
    height: 1px;
    margin: 6px 0;
    background: #e2e8f0;
}

.table.table-compact > :not(caption) > * > * {
    padding: 0.35rem 0.45rem;
    font-size: 0.86rem;
}

.app-toast-container {
    z-index: 2500;
}

.app-toast {
    min-width: min(360px, calc(100vw - 24px));
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
}

.chemicals-table {
    min-width: 720px;
}

.chemicals-table th,
.chemicals-table td {
    vertical-align: middle;
}

.chemicals-table td {
    overflow-wrap: anywhere;
}

.chemicals-table .chemicals-actions-column,
.chemicals-table .chemicals-actions-cell {
    width: 1%;
    min-width: 230px;
    white-space: nowrap;
}

.chemical-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.chemical-row-actions form {
    display: inline-flex;
    margin: 0;
}

.chemical-action-label {
    pointer-events: none;
    white-space: nowrap;
}

.chemicals-actions,
.chemicals-filter-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.chemicals-import-form,
.chemicals-filter-form {
    max-width: 100%;
}

.chemicals-filter-form .form-control,
.chemicals-import-form .form-control {
    min-height: 38px;
}

.dashboard-kpi {
    display: flex;
    min-height: 112px;
    flex-direction: column;
    justify-content: space-between;
    padding: 18px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

.dashboard-kpi span {
    color: #64748b;
    font-size: 0.88rem;
    font-weight: 700;
    text-transform: uppercase;
}

.dashboard-kpi strong {
    color: #0f172a;
    font-size: 2rem;
    line-height: 1;
}

.dashboard-kpi .dashboard-date-range {
    font-size: 1.35rem;
}

.dashboard-kpi-warning strong {
    color: #dc3545;
}

.dashboard-chart {
    height: 320px;
}

.dashboard-reorder-table {
    min-width: 760px;
}

.dashboard-stock-meter {
    width: 110px;
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}

.dashboard-stock-meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: #dc3545;
}

.dashboard-department-risk {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #eef2f7;
}

.dashboard-department-risk:last-child {
    border-bottom: 0;
}

.dashboard-department-risk span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.dashboard-department-risk strong {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 0.9rem;
}

.report-filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.procurement-status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.procurement-status-card {
    padding: 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.procurement-status-card span {
    display: block;
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.procurement-status-card strong {
    color: #0f172a;
    font-size: 1.35rem;
}

.procurement-status-badge {
    text-transform: capitalize;
}

.procurement-status-requested {
    background: #0d6efd;
}

.procurement-status-ordered {
    background: #6f42c1;
}

.procurement-status-received {
    background: #198754;
}

.procurement-status-cancelled {
    background: #6c757d;
}

.procurement-workflow-cell {
    min-width: 280px;
}

.procurement-inline-form,
.procurement-row-actions,
.procurement-row-actions form {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.procurement-row-actions {
    flex-wrap: wrap;
}

.report-table {
    min-width: 920px;
}

.department-audit-table {
    min-width: 1080px;
}

.report-table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}

.report-table {
    width: max-content;
    min-width: 100%;
    margin-bottom: 0;
}

.report-table th,
.report-table td {
    min-width: 110px;
    white-space: nowrap;
}

.report-table th:first-child,
.report-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 220px;
    max-width: 280px;
    white-space: normal;
    background: #ffffff;
    box-shadow: 1px 0 0 #dee2e6;
}

.report-table thead th:first-child {
    z-index: 3;
    background: #212529;
}

.report-scroll-hint {
    display: none;
    margin-bottom: 8px;
    color: #64748b;
    font-size: 0.88rem;
}

.import-preview-table {
    min-width: 980px;
}

.chemical-profile {
    max-width: 100%;
}

.chemical-profile-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.chemical-profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: #64748b;
    font-size: 0.92rem;
}

.chemical-profile-meta span {
    padding: 4px 8px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.05);
}

.chemical-profile-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.chemical-profile-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.chemical-profile-kpi {
    display: flex;
    min-height: 96px;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

.chemical-profile-kpi span {
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.chemical-profile-kpi strong {
    color: #0f172a;
    font-size: 1.65rem;
    line-height: 1;
}

.chemical-profile-kpi-warning strong {
    color: #dc3545;
}

.chemical-profile-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
    gap: 18px;
    margin-bottom: 18px;
}

.chemical-profile-card {
    height: 100%;
}

.chemical-detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.chemical-detail-list > div {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eef2f7;
}

.chemical-detail-list > div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.chemical-detail-list dt {
    color: #64748b;
    font-weight: 700;
}

.chemical-detail-list dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

/* Floating scan button */
.fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 65px;
    height: 65px;
    padding: 0 18px;
    gap: 8px;
    border-radius: 30px;
    background: #ffc107;
    color: #000000;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    font-size: 28px;
    text-decoration: none;
    touch-action: none;
    user-select: none;
    cursor: grab;
    transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
}

.fab:hover {
    background: #ffca2c;
    color: #000000;
    transform: scale(1.05);
}

.fab.fab-dragging {
    cursor: grabbing;
    transform: scale(1.03);
}

.fab-text {
    font-size: 14px;
    font-weight: 600;
}

/* Scanner views */
#reader {
    max-width: 100%;
}

#reader video,
#reader__scan_region video {
    width: 100% !important;
    border-radius: 8px;
    object-fit: cover;
}

.scanner-reader {
    width: 100%;
}

/* Mobile and collapsed tablet layout */
@media (max-width: 991.98px) {
    .topnav-content {
        padding: 0 12px 16px;
    }

    .chemicals-actions .btn,
    .chemicals-filter-actions .btn,
    .chemicals-import-form .btn {
        width: 100%;
    }

    .chemicals-filter-actions .chemicals-reset-button {
        width: auto;
        min-width: 92px;
        align-self: flex-start;
        padding-right: 12px;
        padding-left: 12px;
        margin-left: auto;
    }

    .chemicals-filter-actions {
        align-items: stretch;
    }

    .report-filter-actions .btn {
        width: 100%;
    }

    .report-scroll-hint {
        display: block;
    }

    .procurement-status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chemical-profile-header,
    .chemical-profile-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .chemical-profile-actions .btn {
        width: 100%;
    }

    .chemical-profile-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chemical-profile-grid {
        grid-template-columns: 1fr;
    }

    .chemical-detail-list > div {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .dashboard-chart {
        height: 260px;
    }

    .chemicals-filter-form {
        margin-right: 0;
        margin-left: 0;
    }

    .chemicals-filter-form > [class*="col-"] {
        padding-right: 0;
        padding-left: 0;
    }

    .table-responsive {
        margin-right: -8px;
        margin-left: -8px;
        width: calc(100% + 16px);
    }

    .alert {
        margin-bottom: 16px;
    }

    .navbar-collapse {
        max-height: calc(100dvh - 130px);
        margin-top: 10px;
        padding: 12px;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-top: 1px solid #dddddd;
        background: #ffffff;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-menu {
        width: 100%;
        margin-top: 15px;
    }

    .mobile-menu .nav-item {
        width: 100%;
        border-bottom: 1px solid #eeeeee;
    }

    .navbar .nav-link,
    .navbar-nav .nav-link,
    .navbar-nav .btn {
        display: block !important;
        width: 100% !important;
        margin-right: 0;
        margin-bottom: 6px;
        padding: 14px 16px !important;
        border-radius: 8px;
        font-size: 1.1rem !important;
        text-align: left !important;
    }

    .topnav-menu {
        align-items: stretch;
        gap: 0;
    }

    .topnav-menu .nav-item {
        display: block;
    }

    .navbar .nav-link:hover,
    .mobile-menu .nav-link:hover {
        background: #f2f6ff;
        color: #0d6efd !important;
    }

    .navbar-toggler {
        padding: 10px 14px !important;
        border: 1px solid #cccccc !important;
    }

    .navbar-toggler-icon {
        width: 2.4rem !important;
        height: 2.4rem !important;
    }

    .navbar-brand {
        font-size: 1.35rem;
    }

    .topnav-faculty-logo {
        width: 138px;
        max-width: 38vw;
        height: 42px;
    }

    .topnav-container {
        align-items: stretch !important;
    }

    .topnav-header {
        flex-wrap: wrap;
        align-items: flex-start !important;
    }

    .topnav-brand-group {
        width: 100%;
        flex-wrap: nowrap;
    }

    .topnav-actions {
        display: grid !important;
        width: 100%;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
    }

    .topnav-user-link {
        display: block !important;
        width: auto !important;
        max-width: none;
        margin: 0 !important;
        padding: 8px 10px !important;
        overflow: hidden;
        text-align: left !important;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topnav-language,
    .topnav-logout-button {
        min-height: 38px;
    }

    .topnav-logout-form {
        margin: 0;
    }

    #reader {
        min-height: 420px;
    }

    #reader__scan_region {
        padding: 10px;
    }

    .scanner-reader,
    #reader video {
        min-height: 65vh;
    }
}

@media (min-width: 992px) {
    .fab {
        height: 55px;
        min-width: 55px;
        font-size: 22px;
    }
}

@media (max-width: 575.98px) {
    .procurement-status-grid {
        grid-template-columns: 1fr;
    }

    .chemical-profile-kpis {
        grid-template-columns: 1fr;
    }

    .topnav-actions {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .topnav-logout-button {
        width: auto;
        padding-right: 10px;
        padding-left: 10px;
    }

    .fab {
        right: 14px;
        bottom: 14px;
        height: 56px;
        min-width: 56px;
        padding: 0 14px;
        font-size: 24px;
    }

    .fab-text {
        font-size: 13px;
    }
}
