/* =========================================================================
   CoolSchool — global UI legibility & form-field enhancements
   -------------------------------------------------------------------------
   Goals (applied app-wide, every layout / every role):
     1. Every form field (input / select / textarea) carries a visible shadow.
     2. Buttons, labels and text are always readable against their background
        (no invisible / unstyled controls).

   Design rule: this file is loaded LAST in every layout's <head>, but it is
   built almost entirely from *element* selectors (specificity 0,0,1). Any
   existing utility/framework class (Tailwind `bg-*`/`text-*`, Bootstrap
   `.btn-primary`/`.form-control`, etc. — specificity 0,1,0) therefore STILL
   WINS. So this only ever raises a floor for controls that were otherwise
   unstyled; it never overrides an element that already has an explicit
   colour/background. Framework class hooks below use matching specificity and
   are ordered so variants keep their colours.

   Plain static asset (no Vite/Tailwind build step) so it reaches the
   Tailwind-CDN admin layout and the Vite layouts alike, and ships via a
   simple file copy.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. FORM FIELD SHADOWS  (all forms, all layouts)
   Text-like inputs, selects and textareas get a soft resting shadow and a
   stronger, focus-ring-style shadow when active. Non-text controls
   (checkbox/radio/range/color/file/hidden and button-type inputs) are
   excluded so they are not visually distorted.
   ------------------------------------------------------------------------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
select,
textarea,
.form-control,
.form-select,
.form-input {
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(15, 23, 42, 0.06);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):focus,
select:focus,
textarea:focus,
.form-control:focus,
.form-select:focus,
.form-input:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25), 0 1px 2px rgba(15, 23, 42, 0.10);
    outline: none;
}

/* File inputs get a lighter shadow on the control itself (kept subtle). */
input[type="file"] {
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Placeholder text — guarantee a readable (not too-faint) grey on any field. */
::placeholder { color: #6b7280; opacity: 1; }
:-ms-input-placeholder { color: #6b7280; }

/* -------------------------------------------------------------------------
   2. LABEL & TEXT LEGIBILITY  (safe floor only)
   Element-level defaults so a label / small print that has NO explicit colour
   class is never left as invisible or near-invisible text. Any Tailwind
   `text-*` or Bootstrap colour utility still overrides these (higher
   specificity), so coloured/inverse text is untouched.
   ------------------------------------------------------------------------- */
label,
.form-label {
    color: #374151;            /* slate-700 — readable on white/light cards */
}

.form-text,
small.text-muted,
.help-text {
    color: #4b5563;            /* slate-600 — meets contrast on light bg */
}

/* Required-field asterisks stay visibly red even with no colour class. */
.required,
.text-danger-asterisk { color: #dc2626; }

/* -------------------------------------------------------------------------
   3. BUTTON VISIBILITY & CONTRAST  (unstyled controls only)
   The admin layout loads Tailwind (CDN) but NOT Bootstrap, so a bare
   `.btn` there renders as unstyled/near-invisible text. Give any button that
   has neither a Bootstrap `.btn-*` variant NOR a Tailwind `bg-*` background a
   filled, high-contrast default. Buttons that already declare a background
   (variant class or `bg-*`) are matched by `[class*="btn-"]` / `[class*="bg-"]`
   and left exactly as-is.
   ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

/* Filled default ONLY for buttons with no variant and no bg utility. */
.btn:not([class*="btn-"]):not([class*="bg-"]) {
    background-color: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}
.btn:not([class*="btn-"]):not([class*="bg-"]):hover {
    background-color: #1d4ed8;
    color: #ffffff;
}

/* Bare <button>/submit controls with no framework class at all. */
button:not([class]),
input[type="submit"]:not([class]),
input[type="button"]:not([class]),
input[type="reset"]:not([class]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #2563eb;
    background-color: #2563eb;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

/* Bootstrap outline buttons render as invisible text when Bootstrap CSS is
   absent (admin layout). Give them a readable filled-on-hover safety net
   while keeping their intended coloured text where Bootstrap IS present
   (Bootstrap's own rules have equal specificity but load earlier, so when
   present they win; when absent, these apply). */
.btn-outline-primary { color: #1d4ed8; border: 1px solid #1d4ed8; }
.btn-outline-secondary { color: #374151; border: 1px solid #6b7280; }
.btn-outline-success { color: #15803d; border: 1px solid #15803d; }
.btn-outline-danger { color: #b91c1c; border: 1px solid #b91c1c; }
.btn-outline-warning { color: #b45309; border: 1px solid #d97706; }
.btn-outline-info { color: #0e7490; border: 1px solid #0e7490; }

/* Guarantee filled Bootstrap variants have contrasting text even if Bootstrap
   CSS didn't load in this layout (matches Bootstrap's own foreground choices). */
.btn-primary { background-color: #2563eb; color: #fff; border-color: #2563eb; }
.btn-secondary { background-color: #6b7280; color: #fff; border-color: #6b7280; }
.btn-success { background-color: #16a34a; color: #fff; border-color: #16a34a; }
.btn-danger { background-color: #dc2626; color: #fff; border-color: #dc2626; }
.btn-warning { background-color: #f59e0b; color: #1f2937; border-color: #f59e0b; }
.btn-info { background-color: #0891b2; color: #fff; border-color: #0891b2; }
.btn-light { background-color: #f8fafc; color: #1f2937; border-color: #e5e7eb; }
.btn-dark { background-color: #1f2937; color: #fff; border-color: #1f2937; }

/* =========================================================================
   SECTION 4+ — global UX additions (append after existing sections 1–3)
   Same contract as above: element-level floors, framework classes still win.
   ========================================================================= */

/* 4. KEYBOARD FOCUS VISIBILITY (WCAG 2.4.7)
   Section 1 replaces input outlines with a ring shadow, but links, buttons
   and other controls currently have NO focus indicator. :focus-visible fires
   for keyboard navigation only, so mouse users and framework styles are
   untouched. */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible,
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.65);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* 5. DISABLED / LOADING BUTTON STATES
   Pure floor — variant colours preserved (only opacity/cursor change).
   aria-busy is opt-in: JS setting aria-busy="true" on submit gets a spinner. */
button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled,
.btn:disabled,
.btn.disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}
button[aria-busy="true"],
.btn[aria-busy="true"] {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}
button[aria-busy="true"]::after,
.btn[aria-busy="true"]::after {
    content: "";
    width: 1em;
    height: 1em;
    margin-inline-start: 0.5em;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: 50%;
    display: inline-block;
    vertical-align: -0.15em;
    animation: uie-spin 0.7s linear infinite;
}
@keyframes uie-spin { to { transform: rotate(360deg); } }

/* 6. TABLE LEGIBILITY FLOOR + ZEBRA + ROW HOVER
   Element selectors give every table readable padding, a distinct header, a
   whisper-light zebra and a hover highlight. Bootstrap's class-level rules
   still win where loaded; rgba tints are subtle over coloured rows. */
table { border-collapse: collapse; }
th, td {
    padding: 0.5rem 0.75rem;
    text-align: start;                 /* logical: correct in RTL too */
    vertical-align: middle;
}
thead th {
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    background-color: #f9fafb;
}
tbody tr { border-bottom: 1px solid #f1f5f9; }
tbody tr:nth-child(even) { background-color: rgba(15, 23, 42, 0.025); }
tbody tr:hover { background-color: rgba(37, 99, 235, 0.055); }

/* Opt-in sticky header: add .sticky-thead to any scrolling table wrapper.
   Inert until the class is used, so 100% safe to ship. */
.sticky-thead { max-height: 70vh; overflow-y: auto; }
.sticky-thead thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: #f9fafb;
    box-shadow: 0 1px 0 #e5e7eb;
}

/* 7. RESPONSIVE TABLE OVERFLOW
   ~110 files wrap tables in .table-responsive, but the class is a no-op in
   layouts that don't load Bootstrap. This makes every existing wrapper work;
   identical to Bootstrap's own rule where it loads. */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 8. ALERT / CARD / BADGE FLOORS (Bootstrap markup in Bootstrap-less layouts)
   Colours match Bootstrap 5, so Bootstrap pages are visually unchanged. */
.alert {
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background-color: #f8fafc;
    color: #1f2937;
}
.alert-success { background-color: #d1e7dd; border-color: #a3cfbb; color: #0a3622; }
.alert-danger  { background-color: #f8d7da; border-color: #f1aeb5; color: #58151c; }
.alert-warning { background-color: #fff3cd; border-color: #ffe69c; color: #664d03; }
.alert-info    { background-color: #cff4fc; border-color: #9eeaf9; color: #055160; }

.card {
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.card-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
    font-weight: 600;
    border-radius: 0.5rem 0.5rem 0 0;
}
.card-body { padding: 1rem; }
/* Gentle elevation only for cards that ARE links (never plain cards). */
a > .card { transition: box-shadow 0.15s ease, transform 0.15s ease; }
a > .card:hover {
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
    transform: translateY(-2px);
}

.badge {
    display: inline-block;
    padding: 0.3em 0.6em;
    font-size: 0.75em;
    font-weight: 600;
    line-height: 1;
    border-radius: 0.375rem;
    background-color: #6b7280;   /* readable default; bg-* utilities override */
    color: #ffffff;
}

/* 9. FORM VALIDATION VISIBILITY
   Guarantees the red ring and readable message everywhere. Display of
   .invalid-feedback is NOT forced, so Bootstrap's show/hide is preserved. */
.is-invalid,
input.is-invalid:focus,
select.is-invalid:focus,
textarea.is-invalid:focus {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.22) !important;
}
.invalid-feedback, .text-danger { color: #dc2626; }
.invalid-feedback { font-size: 0.875em; margin-top: 0.25rem; }

/* 10. RESPONSIVE MEDIA FLOOR
   Brings Bootstrap layouts to parity with Tailwind's preflight so images
   never blow out cards or table cells on mobile. */
img, svg, video, canvas { max-width: 100%; height: auto; }

/* 11. PRINT STYLES (rosters, report cards, payslips)
   Hide chrome, drop shadows/dark backgrounds, remove the admin sidebar
   offset, keep table rows intact. */
@media print {
    aside, nav, footer, header,
    .btn, button, .sidebar,
    .no-print {
        display: none !important;
    }
    [class*="lg:pl-64"], [class*="lg:pr-64"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    body { background: #ffffff !important; color: #000000 !important; }
    * { box-shadow: none !important; text-shadow: none !important; }
    .card, .alert { border: 1px solid #9ca3af; }
    tr, img { break-inside: avoid; }
    a { text-decoration: none; color: inherit; }
    .table-responsive, .sticky-thead { overflow: visible; max-height: none; }
}

/* 12. REDUCED MOTION (WCAG 2.3.3)
   Layouts ship infinite float/shimmer animations with no opt-out. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* -------------------------------------------------------------------------
   13. TAILWIND v3 → v4 OPACITY COMPAT SHIM
   Tailwind v4 REMOVED the `bg-opacity-*` / `text-opacity-*` utilities (the
   replacement is slash syntax, e.g. `bg-white/20`). ~90 views still use the
   old two-class form `bg-white bg-opacity-20`, which under v4 renders as a
   SOLID `bg-white` box (the opacity class does nothing). The RUBIX AI
   Insights cards put white text on those boxes → white-on-white, i.e. text
   "the same colour as the background", unreadable; modal backdrops
   (`bg-black bg-opacity-50`) went fully opaque black. This layer restores the
   intended translucency for the exact colour+opacity pairs the views use, so
   the fix ships as one static file with no Tailwind rebuild. These compound
   selectors (0,2,0) out-specify the bare `.bg-white` utility and, being
   un-layered, also beat any `@layer` utility, so no !important is needed for
   the base state; hover variants keep !important to win over the base rule.
   Forward-compatible: once the views migrate to slash syntax these rules
   simply match nothing. ------------------------------------------------- */
.bg-white.bg-opacity-0   { background-color: rgba(255, 255, 255, 0);    }
.bg-white.bg-opacity-10  { background-color: rgba(255, 255, 255, 0.10); }
.bg-white.bg-opacity-20  { background-color: rgba(255, 255, 255, 0.20); }
.bg-white.bg-opacity-25  { background-color: rgba(255, 255, 255, 0.25); }
.bg-white.bg-opacity-30  { background-color: rgba(255, 255, 255, 0.30); }
.bg-white.bg-opacity-50  { background-color: rgba(255, 255, 255, 0.50); }
.bg-white.bg-opacity-75  { background-color: rgba(255, 255, 255, 0.75); }
.bg-white.bg-opacity-90  { background-color: rgba(255, 255, 255, 0.90); }

.bg-black.bg-opacity-25  { background-color: rgba(0, 0, 0, 0.25); }
.bg-black.bg-opacity-30  { background-color: rgba(0, 0, 0, 0.30); }
.bg-black.bg-opacity-40  { background-color: rgba(0, 0, 0, 0.40); }
.bg-black.bg-opacity-50  { background-color: rgba(0, 0, 0, 0.50); }
.bg-black.bg-opacity-60  { background-color: rgba(0, 0, 0, 0.60); }
.bg-black.bg-opacity-75  { background-color: rgba(0, 0, 0, 0.75); }

.bg-gray-500.bg-opacity-75 { background-color: rgba(107, 114, 128, 0.75); }
.bg-gray-600.bg-opacity-50 { background-color: rgba(75, 85, 99, 0.50);   }

.text-white.text-opacity-90 { color: rgba(255, 255, 255, 0.90); }
.text-white.text-opacity-75 { color: rgba(255, 255, 255, 0.75); }

/* Hover variants used by the AI panels (base is bg-white/bg-opacity-20). */
.bg-white.hover\:bg-opacity-30:hover { background-color: rgba(255, 255, 255, 0.30) !important; }
.hover\:bg-white.hover\:bg-opacity-20:hover { background-color: rgba(255, 255, 255, 0.20) !important; }

/* ==========================================================================
   RTL support (dir="rtl" is set on <html> for ar/ur/fa/he locales).
   The browser mirrors text flow and flexbox automatically; these overrides
   flip the PHYSICAL Bootstrap utilities the compiled LTR build leaves
   pointing the wrong way. Scoped under [dir="rtl"] so LTR is untouched.
   ========================================================================== */
[dir="rtl"] body { text-align: right; }

/* Spacing utilities: ms-*/me-* compile to physical left/right in the LTR
   build — swap them so "margin-end" really means the end. */
[dir="rtl"] .me-1 { margin-right: 0 !important; margin-left: .25rem !important; }
[dir="rtl"] .me-2 { margin-right: 0 !important; margin-left: .5rem !important; }
[dir="rtl"] .me-3 { margin-right: 0 !important; margin-left: 1rem !important; }
[dir="rtl"] .ms-1 { margin-left: 0 !important; margin-right: .25rem !important; }
[dir="rtl"] .ms-2 { margin-left: 0 !important; margin-right: .5rem !important; }
[dir="rtl"] .ms-3 { margin-left: 0 !important; margin-right: 1rem !important; }
[dir="rtl"] .ms-auto { margin-left: 0 !important; margin-right: auto !important; }
[dir="rtl"] .me-auto { margin-right: 0 !important; margin-left: auto !important; }
[dir="rtl"] .ps-3 { padding-left: 0 !important; padding-right: 1rem !important; }
[dir="rtl"] .pe-3 { padding-right: 0 !important; padding-left: 1rem !important; }

/* Text alignment utilities. */
[dir="rtl"] .text-start { text-align: right !important; }
[dir="rtl"] .text-end { text-align: left !important; }

/* Accent borders (used on guidance cards, exam review, lesson visuals). */
[dir="rtl"] .border-start {
    border-left: 0 !important;
    border-right: var(--bs-border-width, 1px) var(--bs-border-style, solid) var(--bs-border-color, #dee2e6) !important;
}
[dir="rtl"] .border-start.border-4 { border-right-width: 4px !important; }
[dir="rtl"] .border-end { border-right: 0 !important; }

/* Dropdowns + list bullets + form checks mirror. */
[dir="rtl"] .dropdown-menu-end { right: auto; left: 0; }
[dir="rtl"] ul, [dir="rtl"] ol { padding-left: 0; padding-right: 2rem; }
[dir="rtl"] .form-check { padding-left: 0; padding-right: 1.5em; }
[dir="rtl"] .form-check .form-check-input { float: right; margin-left: 0; margin-right: -1.5em; }

/* Breadcrumb divider direction. */
[dir="rtl"] .breadcrumb-item + .breadcrumb-item { padding-left: 0; padding-right: .5rem; }
[dir="rtl"] .breadcrumb-item + .breadcrumb-item::before { float: right; padding-right: 0; padding-left: .5rem; }

/* ==========================================================================
   Content protection (paired with public/js/content-protection.js).
   Blocks selection/printing of page content. NOTE: nothing here — or in any
   browser — can stop the PrintScreen key, the OS snipping tool, a phone
   camera or a screen recorder. This raises effort; it is not DRM.
   ========================================================================== */
.protect-content body,
html.protect-content body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* stops the iOS long-press save/copy sheet */
}

/* Anything the user types into must stay selectable, or the app is unusable. */
.protect-content input,
.protect-content textarea,
.protect-content select,
.protect-content [contenteditable="true"],
.protect-content .allow-select,
.protect-content .allow-select * {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* Images: no long-press/drag-to-desktop. */
.protect-content img:not(.allow-select) {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}
/* …except where the image is the control (avatars, clickable thumbnails). */
.protect-content a img,
.protect-content button img,
.protect-content label img {
    pointer-events: auto;
}

/* Printing: replace the page rather than let it onto paper or a PDF. */
@media print {
    .protect-content body * { visibility: hidden !important; }
    .protect-content body::before {
        content: attr(data-print-notice);
        visibility: visible !important;
        display: block;
        position: fixed;
        inset: 0;
        padding: 4rem 2rem;
        font: 600 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
        text-align: center;
        color: #111;
    }
}

/* Strict mode: conceal the content while the window is not focused. */
.protection-shield {
    position: fixed;
    inset: 0;
    z-index: 2147483646;
    display: none;
    align-items: center;
    justify-content: center;
    background: #0f172a;
    color: #fff;
    text-align: center;
}
.protection-shield-message { max-width: 32rem; padding: 2rem; }
.protection-shield-icon { font-size: 3rem; margin-bottom: .5rem; }
html.is-concealed .protection-shield { display: flex; }
/* Blur the page underneath too, so a screenshot of the moment of switching
   still catches nothing readable. */
html.is-concealed body > *:not(.protection-shield) {
    filter: blur(18px);
    transition: filter .05s linear;
}
