/* ============================================================
   Display preferences: dark / light theme, text size, and
   small-screen fixes. Loaded LAST so it overrides theme.css.
   Theme = Bootstrap 5.3 data-bs-theme on <html> + our tokens.
   ============================================================ */

/* ---------------------------------------------------------- Controls */
.display-controls {
    display: inline-flex; align-items: center; gap: 2px;
    background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 2px;
}
.display-controls .dc-btn {
    border: 0; background: transparent; color: #fff; cursor: pointer;
    min-width: 30px; height: 28px; padding: 0 .45rem; border-radius: 999px;
    font-size: .8rem; font-weight: 700; line-height: 1; white-space: nowrap;
    display: inline-flex; align-items: center; justify-content: center; gap: 1px;
}
.display-controls .dc-btn:hover { background: rgba(255, 255, 255, .22); }
.display-controls .dc-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.display-controls .dc-pct { font-size: .72rem; font-weight: 600; opacity: .9; min-width: 42px; }
.display-controls .dc-sep { width: 1px; height: 16px; background: rgba(255, 255, 255, .35); margin: 0 2px; }

/* Floating variant for pages without the app top bar (landing, login, register) */
.display-controls.floating {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 1050;
    background: var(--surface, #fff); border: 1px solid var(--line, #e4ebee);
    box-shadow: 0 8px 24px rgba(15, 42, 52, .18);
}
.display-controls.floating .dc-btn { color: var(--ink, #1f2d3a); }
.display-controls.floating .dc-btn:hover { background: var(--brand-teal-050, #e9f3f4); }
.display-controls.floating .dc-sep { background: var(--line, #e4ebee); }

/* ---------------------------------------------------------- Dark theme tokens */
[data-bs-theme="dark"] {
    --surface: #152129;
    --page-bg: #0d161b;
    --ink: #e6edf1;
    --ink-soft: #a6b4bd;
    --line: #26353e;
    --brand-teal-050: #10353b;
    --brand-gold-050: #2c2517;

    --bs-body-bg: var(--page-bg);
    --bs-body-color: var(--ink);
    --bs-border-color: var(--line);
    --bs-secondary-bg: #1a2930;
    --bs-tertiary-bg: #1a2930;
    --bs-secondary-color: var(--ink-soft);
    --bs-light: #1a2930;
    --bs-light-rgb: 26, 41, 48;
    --bs-dark: #e6edf1;
    --bs-dark-rgb: 230, 237, 241;

    /* site.css legacy tokens */
    --accent-color: #10353b;
    --accent-secondary: #2c2517;
    --text-primary: #e6edf1;
    --text-secondary: #a6b4bd;
}

[data-bs-theme="dark"] body { background-image: none; color: var(--ink); }
[data-bs-theme="dark"] .card-header { background: var(--surface); }
[data-bs-theme="dark"] .card-header[class*="bg-"], [data-bs-theme="dark"] .card-header.text-white { background-color: unset; }
[data-bs-theme="dark"] .card-header.bg-primary { background-color: var(--bs-primary) !important; }
[data-bs-theme="dark"] .bg-white { background-color: var(--surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--bs-tertiary-bg) !important; color: var(--ink); }
[data-bs-theme="dark"] .text-dark { color: var(--ink) !important; }
[data-bs-theme="dark"] .text-body { color: var(--ink) !important; }
[data-bs-theme="dark"] .border { border-color: var(--line) !important; }
[data-bs-theme="dark"] .table > thead th { background: var(--brand-teal-050); color: var(--brand-on-dark-3, #bfe3e7); border-bottom-color: var(--line); }
[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * { background: #1a2930; }
[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-type: rgba(255, 255, 255, .03); }
[data-bs-theme="dark"] .table > :not(caption) > * > * { color: var(--ink); border-bottom-color: var(--line); }
[data-bs-theme="dark"] .table-active, [data-bs-theme="dark"] .table-secondary { --bs-table-bg: #1f2f37; }
[data-bs-theme="dark"] .input-group-text { color: var(--brand-on-dark-3, #bfe3e7); }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select {
    background-color: #101b21; color: var(--ink); border-color: var(--line);
}
[data-bs-theme="dark"] .form-control::placeholder { color: #6f7f89; }
[data-bs-theme="dark"] .form-control:disabled, [data-bs-theme="dark"] .form-select:disabled { background-color: #16232a; }
[data-bs-theme="dark"] .form-check-input { background-color: #101b21; border-color: #46565f; }
[data-bs-theme="dark"] .form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
[data-bs-theme="dark"] .dropdown-menu { background: var(--surface); border-color: var(--line); }
[data-bs-theme="dark"] .dropdown-item { color: var(--ink); }
[data-bs-theme="dark"] .dropdown-item:hover { background: var(--bs-tertiary-bg); }
[data-bs-theme="dark"] .modal-content { background: var(--surface); color: var(--ink); }
[data-bs-theme="dark"] .list-group-item { background: var(--surface); color: var(--ink); border-color: var(--line); }
[data-bs-theme="dark"] .accordion-item, [data-bs-theme="dark"] .accordion-button { background: var(--surface); color: var(--ink); }
[data-bs-theme="dark"] .accordion-button:not(.collapsed) { background: var(--brand-teal-050); color: var(--brand-on-dark-3, #bfe3e7); }
[data-bs-theme="dark"] .nav-tabs .nav-link.active { background: var(--surface); color: var(--brand-on-dark, #5fd3dd); }
[data-bs-theme="dark"] .page-link { background: var(--surface); color: var(--ink); border-color: var(--line); }
[data-bs-theme="dark"] .progress { background: #1a2930; }
[data-bs-theme="dark"] .footer { color: var(--ink-soft); border-top-color: var(--line) !important; }
[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.page-link) { color: var(--brand-on-dark, #5fd3dd); }
[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.page-link):hover { color: var(--brand-on-dark-2, #8fe3ea); }
[data-bs-theme="dark"] .text-primary { color: var(--brand-on-dark, #5fd3dd) !important; }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: var(--brand-on-dark, #5fd3dd); --bs-btn-border-color: var(--brand-on-dark, #5fd3dd); }
[data-bs-theme="dark"] .btn-outline-secondary { --bs-btn-color: #c9b07c; --bs-btn-border-color: #8b7a52; }
[data-bs-theme="dark"] .btn-outline-dark { --bs-btn-color: var(--ink); --bs-btn-border-color: var(--ink-soft); }
[data-bs-theme="dark"] .btn-light { --bs-btn-bg: #1f2f37; --bs-btn-border-color: #2b3c45; --bs-btn-color: var(--ink); --bs-btn-hover-bg: #27404a; --bs-btn-hover-color: #fff; }
[data-bs-theme="dark"] .alert { color: var(--ink); }
[data-bs-theme="dark"] .alert-info { background: #0f2e33; }
[data-bs-theme="dark"] .alert-warning { background: #332a0f; }
[data-bs-theme="dark"] .alert-success { background: #0f3320; }
[data-bs-theme="dark"] .alert-danger { background: #3a1419; }
[data-bs-theme="dark"] .alert-primary { background: #0f2e33; }
[data-bs-theme="dark"] .alert-secondary { background: #1f2f37; }
[data-bs-theme="dark"] .alert-light { background: #1a2930; }
[data-bs-theme="dark"] .badge.bg-light { background: #1f2f37 !important; color: var(--ink-soft) !important; }
[data-bs-theme="dark"] .toast, [data-bs-theme="dark"] .popover, [data-bs-theme="dark"] .offcanvas { background: var(--surface); color: var(--ink); }
[data-bs-theme="dark"] hr { border-color: var(--line); opacity: 1; }
[data-bs-theme="dark"] code { color: #f0a6c0; }
[data-bs-theme="dark"] ::selection { background: #1f5f66; color: #fff; }

/* Public shell (landing, login, register) */
[data-bs-theme="dark"] .lp-nav { background: rgba(21, 33, 41, .92); border-bottom-color: var(--line); }
[data-bs-theme="dark"] .lp-hero-bg,
[data-bs-theme="dark"] .app-content.no-chrome:not(.lp-page) {
    background: radial-gradient(1100px 520px at 78% -18%, rgba(0, 128, 139, .18), transparent 60%),
                linear-gradient(160deg, #0d161b 0%, #12222a 55%, #10191e 100%);
}
[data-bs-theme="dark"] .lp-brand { color: var(--brand-on-dark-2, #8fe3ea); }
[data-bs-theme="dark"] .lp-eyebrow { background: rgba(95, 211, 221, .12); color: var(--brand-on-dark-2, #8fe3ea); border-color: rgba(95, 211, 221, .3); }
[data-bs-theme="dark"] .lp-mock, [data-bs-theme="dark"] .lp-band-alt, [data-bs-theme="dark"] .lp-path, [data-bs-theme="dark"] .lp-pill { background: var(--surface) !important; border-color: var(--line) !important; }
[data-bs-theme="dark"] .lp-mock-body { background: #101b21 !important; }
[data-bs-theme="dark"] .auth-aside li { color: var(--ink-soft); }

/* Page-level <style> blocks that hard-code light surfaces */
[data-bs-theme="dark"] .oe-chat, [data-bs-theme="dark"] .chat-container, [data-bs-theme="dark"] .chat-review-container { background: #101b21 !important; border-color: var(--line) !important; }
[data-bs-theme="dark"] .oe-bubble, [data-bs-theme="dark"] .oe-avatar, [data-bs-theme="dark"] .ai-feedback-content, [data-bs-theme="dark"] .message-bubble { background: var(--surface) !important; border-color: var(--line) !important; color: var(--ink); }
[data-bs-theme="dark"] .oe-msg.student .oe-bubble { background: var(--bs-primary) !important; color: #fff; }
[data-bs-theme="dark"] .oe-system span { background: #1f2f37; color: var(--ink-soft); }
[data-bs-theme="dark"] .stage-item.clickable:hover { background-color: #1a2930; }
[data-bs-theme="dark"] .ce-tool-card:hover { background: #10353b !important; }

/* Inline styles with hard-coded light backgrounds (admin-authored views). */
[data-bs-theme="dark"] [style*="background:#fff;"], [data-bs-theme="dark"] [style$="background:#fff"],
[data-bs-theme="dark"] [style*="background: #fff;"], [data-bs-theme="dark"] [style$="background: #fff"],
[data-bs-theme="dark"] [style*="background:#ffffff"], [data-bs-theme="dark"] [style*="background: #ffffff"],
[data-bs-theme="dark"] [style*="background:white"], [data-bs-theme="dark"] [style*="background: white"],
[data-bs-theme="dark"] [style*="background-color:#fff;"], [data-bs-theme="dark"] [style$="background-color:#fff"],
[data-bs-theme="dark"] [style*="background-color: #fff;"], [data-bs-theme="dark"] [style*="background-color: white"], [data-bs-theme="dark"] [style*="background-color:white"] {
    background: var(--surface) !important; color: var(--ink);
}
[data-bs-theme="dark"] [style*="background:#f8f9fa"], [data-bs-theme="dark"] [style*="background: #f8f9fa"],
[data-bs-theme="dark"] [style*="background-color:#f8f9fa"], [data-bs-theme="dark"] [style*="background-color: #f8f9fa"],
[data-bs-theme="dark"] [style*="background:#f0faf5"], [data-bs-theme="dark"] [style*="background:#f8feff"],
[data-bs-theme="dark"] [style*="background:#f6f8f9"], [data-bs-theme="dark"] [style*="background:#f0f7ff"],
[data-bs-theme="dark"] [style*="background:#e8f7f9"], [data-bs-theme="dark"] [style*="background:#e9ecef"],
[data-bs-theme="dark"] [style*="background:#fafafa"], [data-bs-theme="dark"] [style*="background:#fbfdfd"],
[data-bs-theme="dark"] [style*="background-color:#f1f3f5"], [data-bs-theme="dark"] [style*="background-color: #f1f3f5"],
[data-bs-theme="dark"] [style*="background-color:#e8f4f5"], [data-bs-theme="dark"] [style*="background-color: #e8f4f5"],
[data-bs-theme="dark"] [style*="background-color:#e7f3f5"], [data-bs-theme="dark"] [style*="background:#fff3cd"] {
    background: var(--bs-tertiary-bg) !important; color: var(--ink);
}
[data-bs-theme="dark"] [style*="border:1px solid #e2e8f0"], [data-bs-theme="dark"] [style*="border: 1px solid #dee2e6"],
[data-bs-theme="dark"] [style*="border:1px solid #dee2e6"], [data-bs-theme="dark"] [style*="border:1px solid #e9ecef"] { border-color: var(--line) !important; }
/* Dark teal text on dark surfaces is unreadable → lighter teal */
[data-bs-theme="dark"] [style*="color:#006770"]:not([style*="background-color:#006770"]):not([style*="background:#006770"]),
[data-bs-theme="dark"] [style*="color: #006770"]:not([style*="background-color: #006770"]):not([style*="background: #006770"]),
[data-bs-theme="dark"] [style*="color:#004a50"], [data-bs-theme="dark"] [style*="color: #004a50"],
[data-bs-theme="dark"] [style*="color:#1a1a2e"], [data-bs-theme="dark"] [style*="color:#856404"],
[data-bs-theme="dark"] [style*="color:#3b2f16"], [data-bs-theme="dark"] [style*="color:#8B6F3A"] { color: #8fe3ea !important; }
[data-bs-theme="dark"] [style*="color:var(--bs-primary"], [data-bs-theme="dark"] [style*="color: var(--bs-primary"] { color: #8fe3ea !important; }
[data-bs-theme="dark"] img[style*="background:#fff"], [data-bs-theme="dark"] img[style*="background-color:#f1f3f5"] { background: #e6edf1 !important; }

/* ---------------------------------------------------------- Responsive hardening */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
.app-content, main { min-width: 0; }
img, video, canvas { max-width: 100%; height: auto; }
pre { white-space: pre-wrap; word-break: break-word; }
.table-responsive { -webkit-overflow-scrolling: touch; }
.app-brand .app-brand-text { display: inline; }

@media (max-width: 575.98px) {
    .app-topbar { padding: 0 .6rem; gap: .4rem; }
    .app-brand .app-brand-text { display: none; }             /* icon only: room for the controls */
    .topbar-right { gap: .3rem; }
    .display-controls .dc-pct { display: none; }
    .display-controls .dc-btn { min-width: 28px; height: 26px; padding: 0 .35rem; }
    .app-content > .container { padding-left: .75rem; padding-right: .75rem; }
    h1 { font-size: 1.5rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.15rem; } h4 { font-size: 1.05rem; }
    .card-body { padding: .9rem; }
    .btn-group { flex-wrap: wrap; }
    .btn-group > .btn { flex: 1 1 auto; }
    .d-flex.justify-content-between:not(.flex-nowrap) { flex-wrap: wrap; gap: .5rem; }
    .modal-dialog { margin: .5rem; }
    .display-controls.floating { right: .5rem; bottom: .5rem; }
}
@media (max-width: 767.98px) {
    .table th, .table td { white-space: normal; }
    .pagination { flex-wrap: wrap; }
}

/* Training page stage strip: dim teal labels on a dark surface */
[data-bs-theme="dark"] .stage-label.active, [data-bs-theme="dark"] .stage-item.active .text-primary { color: var(--brand-on-dark-2, #8fe3ea) !important; }
[data-bs-theme="dark"] .stage-label.pending { color: var(--ink-soft) !important; }
[data-bs-theme="dark"] .stage-item.disabled { opacity: .75; }
