/* Bootstrap 5 compatibility overrides for Otika (Bootstrap 4) theme */

/* Form select styling */
.form-select {
    display: block;
    width: 100%;
    padding: .375rem .75rem;
    font-size: .875rem;
    line-height: 1.6;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    height: calc(2.2rem + 2px);
}
.form-select:focus {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(0,123,255,.25);
}

/* BS5 btn-close as BS4 close button */
.btn-close {
    float: right;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    color: #000;
    text-shadow: 0 1px 0 #fff;
    opacity: .5;
    padding: 0;
    background: transparent;
    border: 0;
    -webkit-appearance: none;
}
.btn-close:hover {
    opacity: .75;
    text-decoration: none;
}

/* Data attributes (BS5 data-bs-* fallback) */
[data-bs-toggle="dropdown"] { cursor: pointer; }
[data-bs-dismiss="alert"] { cursor: pointer; }
[data-bs-toggle="modal"] { cursor: pointer; }
[data-bs-target] { cursor: pointer; }
[data-bs-theme] { display: none; }

/* RTL utility classes for BS5 names */
.float-end { float: right !important; }
.text-end { text-align: right !important; }
.ms-auto { margin-left: auto !important; }
.me-2 { margin-right: .5rem !important; }
.me-3 { margin-right: 1rem !important; }
.ps-0 { padding-left: 0 !important; }
.pe-0 { padding-right: 0 !important; }
.g-2 > .col, .g-2 > [class*="col-"] { padding: .25rem; }
.g-3 > .col, .g-3 > [class*="col-"] { padding: .5rem; }
.row.g-2 { margin: -.25rem; }
.row.g-3 { margin: -.5rem; }

/* Page header compatibility */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid #f1f1f1;
}
.page-header h4 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #34395e;
    margin: 0;
}
.page-header h4 i {
    margin-right: .5rem;
}

/* Stat cards compatibility */
.stat-card {
    display: flex;
    align-items: center;
    padding: 1.25rem;
    gap: 1rem;
    overflow: hidden;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
}
.stat-primary .stat-icon { background: #6777ef; }
.stat-success .stat-icon { background: #47c363; }
.stat-info .stat-icon { background: #3abaf4; }
.stat-warning .stat-icon { background: #ffa426; }
.stat-danger .stat-icon { background: #fc544b; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: #34395e; line-height: 1.2; }
.stat-label { font-size: .85rem; color: #98a6ad; }
.stat-card .stat-value,
.stat-card .stat-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Allow stat card flex item to shrink so text-overflow works */
.stat-card { min-width: 0; }
.stat-card > div:last-child { overflow: hidden; min-width: 0; }

/* Instructor/student dashboard stat card flex text overflow */
.card-body.d-flex.align-items-center > div:last-child {
    overflow: hidden;
    min-width: 0;
}
.card-body.d-flex.align-items-center h3,
.card-body.d-flex.align-items-center h5,
.card-body.d-flex.align-items-center .card-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.card-body.d-flex.align-items-center small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

/* Badge styles */
.badge { font-weight: 600; padding: .35rem .65rem; }

/* Table improvements */
.table td, .table th { vertical-align: middle; word-break: break-word; }
.table thead th { font-weight: 600; font-size: var(--theme-table-th-font-size, .85rem); }
.table td { font-size: var(--theme-table-td-font-size, .875rem); }
.table { table-layout: auto; width: 100%; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Alert positioning within section-body */
.alert { margin-bottom: 1.5rem; }

/* Card body overflow prevention */
.card-body { overflow-wrap: break-word; word-wrap: break-word; }
.card { min-width: 0; }

/* Uniform 3% font reduction across all pages */
html { font-size: 97%; }

/* Main content area text wrapping */
.main-content { overflow-wrap: break-word; word-wrap: break-word; }
.section-body { overflow-wrap: break-word; word-wrap: break-word; }
.widget-card .card-header h5 { font-size: .85rem !important; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: #4a5568; }

/* Ensure text in columns doesn't overflow */
.col, [class*="col-"] { min-width: 0; }

/* Badge text overflow */
.badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }

/* Form controls overflow */
.form-control { overflow: hidden; text-overflow: ellipsis; }

/* Profile/avatar */
.avatar-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #6777ef;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
}

/* Modal compatibility */
.modal.fade .modal-dialog { transition: transform .3s ease-out; }

/* Ensure modal content stays above backdrop (Otika stacking context fix) */
.modal { z-index: 1050 !important; }
.modal-backdrop { z-index: 1040 !important; }

/* Card header with h5 (existing views) */
.card-header h5 {
    font-size: 1rem;
    font-weight: 600;
    color: #34395e;
    margin: 0;
}
.card-header h5 i { margin-right: .5rem; }

/* Notification badge in navbar */
.notification-badge {
    position: absolute;
    top: 0;
    right: 0;
    padding: .15rem .35rem;
    font-size: .65rem;
    line-height: 1;
}

/* FW utility */
.fw-medium { font-weight: 500 !important; }
.fw-bold { font-weight: 700 !important; }

/* Text muted */
.text-muted { color: #98a6ad !important; }

/* Button icons */
.btn-icon {
    background: transparent;
    border: none;
    color: #98a6ad;
    font-size: 1.25rem;
    padding: .25rem;
    cursor: pointer;
}

/* Exam timer styling */
.exam-timer {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fc544b;
}
.question-card {
    border-left: 4px solid #6777ef;
    margin-bottom: 1rem;
}
.question-option {
    padding: .75rem 1rem;
    border: 1px solid #e4e6fc;
    border-radius: .25rem;
    margin-bottom: .5rem;
    cursor: pointer;
    transition: all .2s;
}
.question-option:hover {
    background: #f0f1ff;
    border-color: #6777ef;
}
.question-option.selected {
    background: #6777ef;
    color: #fff;
    border-color: #6777ef;
}

/* Online exam specific */
.question-nav-item {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    margin: .2rem;
    cursor: pointer;
    border: 1px solid #dee2e6;
}
.question-nav-item.answered {
    background: #47c363;
    color: #fff;
    border-color: #47c363;
}
.question-nav-item.not-answered {
    background: #fc544b;
    color: #fff;
    border-color: #fc544b;
}

/* Sidebar width */
.main-sidebar {
    width: 162px;
    font-size: 96%;
}
body.sidebar-gone .main-sidebar {
    left: -162px;
}

/* Main content and navbar full width (col-12), align with sidebar */
.main-content {
    width: 100%;
    padding-top: 80px;
    padding-left: 192px;
}
.navbar.main-navbar {
    left: 162px;
    min-height: 60px;
}
.sidebar-mini .navbar.main-navbar {
    left: 65px;
}
body.sidebar-gone .navbar.main-navbar {
    left: 0;
}

/* Bootstrap 5 fallback utilities */
.rounded-pill { border-radius: 50rem !important; }
.fw-semibold { font-weight: 600 !important; }
.fw-bold { font-weight: 700 !important; }
.fs-4 { font-size: 1.5rem !important; }
.fs-5 { font-size: 1.25rem !important; }
.fs-6 { font-size: 1rem !important; }

/* Full-page loader overlay */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.4s ease;
}
.loader.loader-hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}
.loader::after {
    content: '';
    width: 50px;
    height: 50px;
    border: 5px solid #e3e3e3;
    border-top-color: #6777ef;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loader.loader-hidden::after {
    animation: none;
}

/* Navbar dropdown text colors — fix white text on white background */
body .navbar.main-navbar .dropdown-menu,
body .navbar.main-navbar .dropdown-menu .dropdown-title,
body .navbar.main-navbar .dropdown-menu .dropdown-header,
body .navbar.main-navbar .dropdown-menu .dropdown-footer,
body .navbar.main-navbar .dropdown-menu .dropdown-item {
    color: #34395e !important;
    background-color: #fff !important;
}
body .navbar.main-navbar .dropdown-menu .dropdown-item i {
    color: #34395e !important;
}
body .navbar.main-navbar .dropdown-menu a {
    color: #34395e !important;
}
body .navbar.main-navbar .dropdown-menu .dropdown-item:hover,
body .navbar.main-navbar .dropdown-menu a:hover {
    color: #191d21 !important;
    background-color: #fcfcfd !important;
}
body .navbar.main-navbar .dropdown-menu .text-danger {
    color: #dc3545 !important;
}
/* Feather icons in navbar dropdown should inherit parent color */
body .navbar.main-navbar .dropdown-menu svg {
    color: inherit !important;
}

.main-wrapper-1 .section .section-header {
    margin-top: 0;
}

/* Sidebar text — inherits html {font-size:97%} */
.main-sidebar .sidebar-brand a {
    font-size: 22px;
}
.main-sidebar .sidebar-brand a .logo-name {
    font-size: 19px;
}
.main-sidebar .sidebar-menu li a .feather {
    height: 19px;
    width: 19px;
}

/* Auth wrapper for Otika auth pages */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Theme CSS variable application */
body {
    font-family: var(--theme-font-family, 'Nunito, Segoe UI, Tahoma, sans-serif');
    font-size: var(--theme-font-size, 14px);
    background: var(--theme-body-bg, #f4f6f9);
    color: var(--theme-body-text, #34395e);
}
a, a:hover { color: var(--theme-link-color, #6777ef); }
.widget-card { height: 100%; }
.widget-card, .card { background: var(--theme-card-bg, #ffffff); border-radius: var(--theme-border-radius, 4px); }
.main-sidebar { background: var(--theme-sidebar-bg, #252525); }
.main-sidebar .sidebar-menu li a { color: var(--theme-sidebar-text, #bcc1c6); font-size: var(--theme-sidebar-font-size, 14px); }
.navbar-bg, .navbar.main-navbar { background: var(--theme-header-bg, #6777ef) !important; }
.main-footer { background: var(--theme-card-bg, #ffffff); }
.btn-primary { background: var(--theme-primary, #6777ef); border-color: var(--theme-primary, #6777ef); }
.btn-primary:hover { background: var(--theme-link-hover, #5a67d8); border-color: var(--theme-link-hover, #5a67d8); }
h1, h2, h3, h4, h5, h6 { font-family: var(--theme-heading-font, 'Nunito, Segoe UI, Tahoma, sans-serif'); }

/* Sidebar active item visible highlight */
.sidebar-menu li.active > a {
    background: rgba(103, 119, 239, 0.12);
    border-radius: 0 8px 8px 0;
}
.sidebar-menu li.active > a span {
    font-weight: 600;
}
.sidebar-menu li.active > a .feather {
    stroke: #6777ef;
}

/* ===== Responsive Overrides ===== */

/* Mobile: sidebar overlays content, no left spacing */
@media (max-width: 1024px) {
    html, body, #app, .main-wrapper, .main-wrapper-1 {
        overflow-x: hidden;
        width: 100%;
    }
    body {
        margin: 0;
        padding: 0;
    }
    .main-sidebar {
        z-index: 1000;
    }
    body.sidebar-show .main-sidebar {
        left: 0 !important;
    }
    .navbar.main-navbar {
        left: 0 !important;
    }
    .main-content {
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-top: 76px !important;
        width: 100%;
    }
    .section {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .section-body {
        padding-left: 10px;
        padding-right: 10px;
    }
    .section-body > .row > [class*="col-"] {
        margin-bottom: 1rem;
    }
    .card {
        margin-bottom: 1rem;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }
    body.sidebar-gone .main-content,
    body.sidebar-show .main-content {
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100%;
    }
    body.sidebar-gone .navbar.main-navbar,
    body.sidebar-show .navbar.main-navbar {
        left: 0 !important;
    }
}

/* Tablet (768px - 1023px) */
@media (max-width: 991.98px) {
    .navbar.main-navbar .navbar-nav .nav-link {
        padding: .5rem .4rem;
    }
    .main-sidebar {
        font-size: 93%;
    }
    .stat-card {
        flex-wrap: wrap;
        gap: .5rem;
        padding: 1rem;
    }
    .stat-value {
        font-size: 1.25rem;
    }
    .table thead th,
    .table td {
        white-space: nowrap;
    }
    .table-responsive {
        margin-bottom: .5rem;
        border: 1px solid #e4e6fc;
        border-radius: .25rem;
        padding: 0;
    }
    .table-responsive .table {
        margin-bottom: 0;
    }
}

/* Phone (< 768px) */
@media (max-width: 767.98px) {
    .main-content {
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-top: 72px !important;
    }
    .main-wrapper-1 .section .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }
    .section-header .buttons,
    .section-header .buttons .btn {
        width: 100%;
    }

    /* Dashboard stat cards: 2 per row on small phones */
    .section-body > .row > .col-6 {
        padding-left: 4px;
        padding-right: 4px;
    }
    .stat-card {
        padding: .75rem .5rem;
    }
    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    .stat-value {
        font-size: 1.1rem;
    }
    .stat-label {
        font-size: .75rem;
    }

    /* Card adjustments */
    .card-header {
        padding: .75rem 1rem;
    }
    .card-body {
        padding: 1rem;
    }
    .card-header h4 {
        font-size: 1rem;
    }
    .card-header h5 {
        font-size: .85rem;
    }

    /* Tabular data scrolls horizontally */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrapper .table {
        min-width: 600px;
    }

    /* Form layout: stack col-6 fields */
    form .row > [class*="col-"],
    .form-row > [class*="col-"] {
        margin-bottom: .75rem;
    }

    /* Navbar tweaks */
    .navbar.main-navbar .navbar-brand {
        font-size: .9rem;
    }
    .navbar.main-navbar .dropdown-menu {
        width: 280px;
        right: auto;
        left: 0;
    }

    /* Auth pages */
    .auth-wrapper .card {
        margin-left: .5rem;
        margin-right: .5rem;
    }
    .auth-wrapper .card-body {
        padding: 1.25rem;
    }

    /* Modal full-screen on mobile */
    .modal-dialog {
        margin: .5rem;
    }

    /* DataTables responsive */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        float: none !important;
        margin-bottom: .5rem;
    }
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
    }

    /* Profile image in sidebar */
    .sidebar-profile {
        flex-direction: column;
        text-align: center;
    }

    /* Page header buttons stack */
    .page-header .buttons {
        display: flex;
        flex-wrap: wrap;
        gap: .25rem;
    }
    .page-header .buttons .btn {
        flex: 1;
        min-width: 0;
        font-size: .8rem;
        padding: .3rem .5rem;
    }
}

/* Small phone (< 576px) */
@media (max-width: 575.98px) {
    html {
        font-size: 95%;
    }
    .main-content {
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-top: 72px !important;
    }
    .section-body {
        padding: .5rem;
    }

    /* Make all col-6 full width */
    .section-body > .row > [class*="col-"] {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Cards collapse to full width */
    .card {
        margin-left: 0;
        margin-right: 0;
    }
    .card-header {
        padding: .65rem .85rem;
    }
    .card-body {
        padding: .85rem;
    }

    /* Stat cards: 1 per row */
    .section-body > .row > .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Widget cards stack */
    .row > [class*="col-"] .widget-card {
        margin-bottom: .75rem;
    }

    /* Auth pages */
    .auth-wrapper {
        padding: 1rem .5rem;
        min-height: 100vh;
    }
    .auth-wrapper .card .card-header h4 {
        font-size: 1.15rem;
    }

    /* Register form: stack columns */
    form .row > .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Navbar buttons/links compact */
    .navbar.main-navbar .form-inline .search-element {
        display: none;
    }
    .navbar.main-navbar .navbar-nav .nav-link {
        padding: .4rem .3rem;
    }

    /* Dropdowns full width */
    .dropdown-menu {
        max-width: calc(100vw - 1rem);
    }

    /* Modal on small screens */
    .modal-dialog {
        margin: .25rem;
    }
    .modal-body {
        padding: 1rem;
    }

    /* Button groups */
    .btn-group {
        flex-wrap: wrap;
    }
    .btn-group .btn {
        font-size: .8rem;
        padding: .3rem .6rem;
    }

    /* Section title */
    .section-title {
        font-size: 1rem;
    }
}


