/* Shared portal tokens — navy #1a3a52 (builder + admin) */
:root {
    --portal-navy: #1a3a52;
    --portal-navy-deep: #132c3f;
    --portal-navy-soft: #e8f1f8;
    --portal-navy-mid: #c5d8e8;
    --portal-ink: #1e2a35;
    --portal-muted: #5a6a7a;
    --portal-bg: #f4f6f8;
    --portal-card-shadow: 0 8px 24px rgba(26, 58, 82, 0.08);
    --portal-radius: 10px;
}

body.portal-body {
    background: var(--portal-bg);
    color: var(--portal-ink);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.portal-topbar {
    background: var(--portal-navy);
    color: #fff;
    padding: 0.85rem 0;
    margin-bottom: 1.25rem;
    box-shadow: 0 2px 10px rgba(26, 58, 82, 0.18);
}

.portal-topbar a {
    color: #cfe3f5;
    text-decoration: none;
}

.portal-topbar a:hover {
    color: #fff;
}

.portal-topbar a.active-tab {
    color: #fff;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 0.25em;
}

.portal-card {
    border: none;
    border-radius: var(--portal-radius);
    box-shadow: var(--portal-card-shadow);
}

.portal-card .card-header {
    background: #fff;
    border-bottom: 1px solid #e6edf3;
}

.btn-portal,
.portal-body .btn-primary {
    background-color: var(--portal-navy);
    border-color: var(--portal-navy);
}

.btn-portal:hover,
.portal-body .btn-primary:hover {
    background-color: var(--portal-navy-deep);
    border-color: var(--portal-navy-deep);
}

.portal-body .btn-outline-primary {
    color: var(--portal-navy);
    border-color: var(--portal-navy);
}

.portal-body .btn-outline-primary:hover {
    background-color: var(--portal-navy);
    border-color: var(--portal-navy);
    color: #fff;
}

.portal-body .form-control:focus,
.portal-body .form-select:focus {
    border-color: #7aa8c7;
    box-shadow: 0 0 0 0.2rem rgba(26, 58, 82, 0.18);
}

/* Academic filter chips */
.filter-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.filter-chip {
    appearance: none;
    border: 1px solid var(--portal-navy-mid);
    background: #fff;
    color: var(--portal-navy);
    border-radius: 999px;
    padding: 0.28rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.filter-chip:hover {
    border-color: var(--portal-navy);
    background: var(--portal-navy-soft);
}

.filter-chip.active {
    background: var(--portal-navy);
    border-color: var(--portal-navy);
    color: #fff;
}

.filter-chip:focus-visible {
    outline: 2px solid #7aa8c7;
    outline-offset: 2px;
}

/* Builder table polish */
.portal-body #course-table {
    font-size: 0.9rem;
}

.portal-body #course-table thead th {
    font-weight: 600;
    color: var(--portal-navy);
    border-bottom-width: 1px;
}

.portal-body #course-table tbody tr:nth-child(even):not(.selected) {
    background: #fafbfc;
}

.portal-body .course-row:hover {
    background: #f0f7fc;
}

.portal-body .course-row.selected {
    background: #dceefb;
}

.portal-body .sticky-panel {
    position: sticky;
    top: 0.75rem;
}

.portal-body .stat-pill {
    display: inline-block;
    background: var(--portal-navy-soft);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    margin-right: 0.5rem;
    font-weight: 600;
}

.portal-body .search-input-emphasis {
    min-width: 200px;
    border-color: var(--portal-navy-mid);
}

/* Builder: taller LHP list to balance right sidebar (actions + TKB) */
.portal-body .lhp-table-scroll {
    max-height: 78vh;
    min-height: 58vh;
}

/* Bootstrap-styled searchable select (course filter) */
.portal-body .searchable-select {
    position: relative;
}

.portal-body .searchable-select-toggle {
    min-width: 220px;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.portal-body .searchable-select-panel {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 1080;
    min-width: 260px;
    max-width: min(420px, 90vw);
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(26, 58, 82, 0.12);
    padding: 0.4rem;
}

.portal-body .searchable-select-query {
    margin-bottom: 0.35rem;
    border-color: var(--portal-navy-mid);
}

.portal-body .searchable-select-list {
    max-height: 240px;
    overflow-y: auto;
}

.portal-body .searchable-select-option {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 0.35rem 0.55rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    color: var(--portal-ink);
    cursor: pointer;
    white-space: normal;
}

.portal-body .searchable-select-option:hover,
.portal-body .searchable-select-option:focus {
    background: var(--portal-navy-soft);
    outline: none;
}

.portal-body .searchable-select-option.is-active {
    background: var(--portal-navy);
    color: #fff;
}

.portal-body .searchable-select-empty {
    padding: 0.5rem 0.55rem;
    font-size: 0.8125rem;
    color: var(--portal-muted);
}

/* Landing */
.landing-page {
    min-height: 100vh;
    background: linear-gradient(165deg, #e8f1f8 0%, #f4f6f8 42%, #eef2f6 100%);
    color: var(--portal-ink);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.landing-wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 3rem;
}

.landing-brand {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--portal-navy);
}

.landing-disclaimer {
    background: #fff8e6;
    border: 1px solid #f0d78c;
    border-radius: var(--portal-radius);
    padding: 0.9rem 1.1rem;
    color: #5c4a12;
}

.landing-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: step;
}

.landing-steps li {
    position: relative;
    padding: 0.65rem 0 0.65rem 2.75rem;
    border-bottom: 1px solid #e6edf3;
    counter-increment: step;
}

.landing-steps li:last-child {
    border-bottom: none;
}

.landing-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0.55rem;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 50%;
    background: var(--portal-navy);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.landing-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.landing-features li {
    padding: 0.45rem 0 0.45rem 1.5rem;
    position: relative;
}

.landing-features li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--portal-navy);
    font-weight: 700;
}

.landing-footer {
    color: var(--portal-muted);
    font-size: 0.9rem;
}

.landing-footer a {
    color: var(--portal-navy);
    text-decoration: none;
    font-weight: 600;
}

.landing-footer a:hover {
    text-decoration: underline;
}

/* A1: flash the timetable cells of a conflicting LHP */
.timetable td.cell-conflict {
    animation: cell-conflict-flash 0.5s ease-in-out 0s 4;
    outline: 2px solid #dc3545;
    outline-offset: -2px;
}

@keyframes cell-conflict-flash {
    0%, 100% { background: #dc3545 !important; color: #fff !important; }
    50% { background: #ffe08a !important; color: #842029 !important; }
}

/* Admin bulk bar / badges shared polish */
.portal-body .bulk-bar {
    background: var(--portal-navy);
}

.portal-body .cohort-chips .btn-cohort.active {
    background: var(--portal-navy);
    border-color: var(--portal-navy);
    color: #fff;
}

.portal-login-admin {
    min-height: 100vh;
    background: linear-gradient(160deg, #1a3a52 0%, #2c5364 50%, #0f2027 100%);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

/* Lightweight onboarding tour (no external libs) */
#tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    pointer-events: auto;
    background: transparent;
}

#tour-hole {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(15, 30, 45, 0.62);
    outline: 3px solid #ffc107;
    outline-offset: 2px;
    transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
    pointer-events: none;
}

#tour-pop {
    position: fixed;
    z-index: 20001;
    max-width: 320px;
    width: calc(100vw - 24px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.32);
    padding: 0.85rem 1rem;
    font-size: 0.9rem;
}

#tour-pop .tour-pop-title {
    font-weight: 700;
    color: #1a3a52;
    margin-bottom: 0.25rem;
}

#tour-pop .tour-pop-body {
    color: #333;
    margin-bottom: 0.6rem;
    line-height: 1.35;
}

#tour-pop .tour-pop-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

#tour-pop .tour-pop-count {
    color: #6c757d;
    font-size: 0.8rem;
    white-space: nowrap;
}

#tour-pop .tour-pop-btns {
    display: flex;
    gap: 0.35rem;
}

/* Interactive "TKB đã chọn" blocks (hover, click-to-deselect, jump-to-row) */
.portal-body .timetable td.filled.interactive {
    cursor: pointer;
    position: relative;
    transition: filter 0.12s ease, box-shadow 0.12s ease;
}

.portal-body .timetable td.filled.interactive:hover,
.portal-body .timetable td.filled.interactive:focus {
    filter: brightness(1.22);
    box-shadow: inset 0 0 0 2px #7fb3d5;
    outline: none;
}

.portal-body .timetable td.filled .tt-code {
    display: inline-block;
}

.portal-body .timetable td.filled.interactive .tt-remove {
    position: absolute;
    top: 0;
    right: 2px;
    font-size: 0.62rem;
    line-height: 1.1;
    color: #ffd7d7;
    opacity: 0;
    transition: opacity 0.12s ease;
    pointer-events: none;
}

.portal-body .timetable td.filled.interactive:hover .tt-remove,
.portal-body .timetable td.filled.interactive:focus .tt-remove {
    opacity: 1;
}

/* Floating tooltip for a selected-timetable block */
#tt-tooltip {
    position: fixed;
    z-index: 20050;
    max-width: 250px;
    background: #10263a;
    color: #f4f8fb;
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.35;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s ease;
}

#tt-tooltip.show {
    opacity: 1;
}

#tt-tooltip .tt-code {
    font-weight: 700;
    margin-bottom: 0.15rem;
}

#tt-tooltip .tt-muted {
    color: #b9cede;
}

#tt-tooltip .tt-slot {
    margin-top: 0.3rem;
}

#tt-tooltip .tt-hint {
    margin-top: 0.35rem;
    color: #9fd0ff;
    font-size: 0.72rem;
}

/* Brief highlight when jumping from a block to its LHP row */
.portal-body .course-row.row-flash {
    animation: row-flash-anim 1.6s ease-in-out;
}

@keyframes row-flash-anim {
    0%, 100% { background: #dceefb; }
    15%, 60% { background: #fff3cd; }
}

/* Undo toast for block deselect */
#tt-toast-wrap {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 20060;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

#tt-toast-wrap .tt-toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #10263a;
    color: #fff;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

#tt-toast-wrap .tt-toast.show {
    opacity: 1;
    transform: translateY(0);
}

#tt-toast-wrap .tt-toast button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    border-radius: 6px;
    padding: 0.15rem 0.55rem;
    font-size: 0.8rem;
    cursor: pointer;
}

#tt-toast-wrap .tt-toast button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   Responsive / mobile
   Breakpoints: 991.98px (columns stack), 768px (tablet/phone),
   480px (small phone). Desktop appearance is left unchanged.
   ============================================================ */

/* Keep the selected-timetable grid readable: it stays at least this wide
   and scrolls horizontally inside its .table-responsive wrapper on phones.
   On desktop the main column is far wider, so this has no visible effect. */
.portal-body .timetable {
    min-width: 33rem;
}

@media (max-width: 991.98px) {
    /* Once builder main + sidebar stack, sticky is more annoying than useful.
       overflow-x:hidden is only safe here because the sticky panel is static,
       so it cannot disable position:sticky on desktop. */
    html,
    body.portal-body {
        max-width: 100%;
        overflow-x: hidden;
    }

    .portal-body .sticky-panel {
        position: static;
        top: auto;
    }
}

@media (max-width: 768px) {
    .portal-topbar {
        padding: 0.6rem 0;
        margin-bottom: 0.85rem;
    }

    .portal-topbar .container-fluid {
        row-gap: 0.35rem;
    }

    .portal-topbar a {
        font-size: 0.9rem;
    }

    /* Tighter page gutters so cards can use the available width */
    .portal-body > .container-fluid.px-3 {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    /* LHP list: leave room so the timetable directly below is reachable */
    .portal-body .lhp-table-scroll {
        max-height: 62vh;
        min-height: 0;
    }

    /* Filter toolbar controls grow to fill and wrap instead of overflowing */
    .portal-body .search-input-emphasis {
        flex: 1 1 12rem;
    }

    .portal-body .searchable-select-toggle {
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    /* Roomier tap targets for the CTĐT chips */
    .portal-body .filter-chip {
        padding: 0.4rem 0.85rem;
    }

    /* Admin: fixed bulk-action bar must wrap, never overflow the viewport */
    .portal-body .bulk-bar .container,
    .portal-body .bulk-bar .container-fluid,
    .portal-body .bulk-bar > .d-flex {
        flex-wrap: wrap;
        row-gap: 0.4rem;
    }

    /* Modals: use nearly the full width on small screens, with internal scroll */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-dialog:not(.modal-fullscreen) {
        max-width: calc(100% - 1rem);
    }

    .modal-dialog-scrollable .modal-body {
        max-height: calc(100vh - 8rem);
    }
}

@media (max-width: 480px) {
    .portal-topbar a {
        font-size: 0.85rem;
    }

    .portal-body .stat-pill {
        padding: 0.35rem 0.6rem;
        margin-right: 0.35rem;
        font-size: 0.85rem;
    }

    .portal-body #course-table {
        font-size: 0.82rem;
    }

    /* Card headers holding the filter bar: let both groups take the full row */
    .portal-body .filter-bar {
        width: 100%;
    }

    /* Undo toast / tooltip never wider than the phone screen */
    #tt-toast-wrap {
        left: 0.5rem;
        right: 0.5rem;
        transform: none;
        align-items: stretch;
    }

    #tt-toast-wrap .tt-toast {
        justify-content: space-between;
    }
}
