/* ==========================================================================
   Accessibility layer (WCAG 2.1 AA) — loaded AFTER style.css, avocloud-branding.css
   and mobile.css. Everything colour-related that was changed for contrast lives
   here so it can be tuned or reverted in one place (delete the <link>).

   Colour changes (old -> new), light mode unless noted. Ratios are against the
   worst surface the colour sits on (white card / #faf8f5 page / #f1ede6 muted).
   test_contrast.py recomputes every pair below from this file.

     text-gray-400/500  #99a1af / #6a7282  -> #6b6357 (= --muted-foreground)   2.2:1 -> 5.1:1
     text-red-400/500/600                  -> #b91c1c (= --destructive)         2.5:1 -> 5.5:1
     text-blue-400/500/600                 -> #1d4ed8                           2.3:1 -> 5.9:1
     text-yellow/amber-500/600             -> #854d0e                           1.6:1 -> 5.5:1
     text-orange-400..700                  -> #9a3412                           2.5:1 -> 5.5:1
     text-green-500/600/700                -> #166534                           1.9:1 -> 5.5:1
     grade 1 / 2 / 3 / 4 / 5 text (on tint)  #16a34a #059669 #ca8a04 #ea580c #dc2626
                                           -> #116931 #066f4c #845a06 #9b3c08 #a41919   2.5-3.8 -> >=4.6
     grade 1/+, 4, 5/- text (dark)           #22c55e #f97316 #ef4444 -> #4ade80 #fdba74 #fca5a5  3.6-4.2 -> >=4.5
     grade +/neutral/- text                  #16a34a #ca8a04 #dc2626
                                           -> #116931 #7f5705 #a91919
     attendance segments (light)  bg+white: #10b981 2.5 / #f59e0b 2.2 / #ef4444 3.8
                                           -> #047857 / #b45309 / #b91c1c (white, >=5.0)
     attendance segments (dark)   white on same bg -> #0a0a0a text (>=5.2)
     input / checkbox / select borders  #e4ddd0 / rgba(255,255,255,.15)
                                           -> #8a8174 (light, >=3.1:1) / #7f766b (dark, >=3.4:1)
     --ring (focus colour)        accent @ .4 alpha -> opaque --primary-ink (light) / accent 65% (dark)
     --primary-foreground (light, orange/yellow/green accent) white -> #0a0a0a
     --primary-ink (new)          accent colour darkened to <=30% lightness for text on light surfaces;
                                  dark mode: accent lightened to 70% for tonal-button text (3.3-4.4 -> >=4.8)
     #save-indicator (dark)       #1d4ed8 -> #93c5fd                                   2.4:1 -> 8.2:1
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */
:root {
    /* Accent as TEXT on light surfaces: lightness capped so every preset keeps 4.5:1. */
    --primary-ink: hsl(var(--accent-h) var(--accent-s) min(var(--accent-l), 30%));
    --focus-ring: var(--primary-ink);
    --ring: var(--focus-ring);

    --field-border: #8a8174;          /* input/checkbox/select outlines, >= 3:1 (WCAG 1.4.11) */
    --field-placeholder: #6b6357;

    --text-danger: #b91c1c;
    --text-success: #166534;
    --text-warning: #854d0e;
    --text-caution: #9a3412;
    --text-info: #1d4ed8;
}

html.dark {
    /* accent text on the dark tonal buttons: --primary (60%) is only 3.3-4.4:1 there */
    --primary-ink: hsl(var(--accent-h) var(--accent-s) 70%);
    --focus-ring: hsl(var(--accent-h) var(--accent-s) 65%);
    --ring: var(--focus-ring);

    --field-border: #7f766b;
    --field-placeholder: #9c948a;
}

/* White text on the light-mode accent fails for these presets (3.4 / 2.5 / 3.6:1);
   dark text, same fix the dark theme already uses (avocloud-branding.css). */
html:not(.dark)[data-accent="orange"],
html:not(.dark)[data-accent="yellow"],
html:not(.dark)[data-accent="green"] {
    --primary-foreground: #0a0a0a;
}

/* Accent used as text colour on soft tonal buttons / links. */
.btn-primary { color: var(--primary-ink) !important; }
.btn-primary.is-cta,
.btn-cta { color: var(--primary-foreground) !important; }
.student-name-link:hover,
#students-table tr:hover .student-name-link { color: var(--primary-ink); }
#mobile-bottom-nav .mnav-btn[aria-current="page"] { color: var(--primary-ink); }

/* ---- Focus (WCAG 2.4.7 / 1.4.11) ---------------------------------------
   Basecoat sets `*{outline-color: ring @ 50%}`, so the browser's default ring on
   plain <button>/<input>/<a> was half transparent. Make it opaque everywhere and
   make the custom focus rules use the same token. */
:focus-visible { outline-color: var(--focus-ring); }

a:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible,
.class-exam-overview-card:focus-visible,
[tabindex]:not([tabindex="-1"]):not(input):not(select):not(textarea):not(button):focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* Fields that drew their own focus style and then removed the outline. */
.class-exam-note-field:focus-visible,
.att-note-inline:focus-visible,
.mobile-sheet--picker .m-picker-search:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 1px;
}

/* Volksschul grade tiles: the radio is visually hidden, so the tile shows focus. */
.primary-grade-btn:has(input:focus-visible),
.class-exam-grade-btn:focus-visible,
.accent-swatch:focus-visible,
.att-seg-btn:focus-visible,
.att-day:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}
.att-seg-btn:focus-visible { outline-offset: -2px; }

/* ---- Form fields (WCAG 1.4.11) ----------------------------------------- */
:is(.form, .field) input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([role="combobox"]),
.input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([role="combobox"]),
:is(.form, .field) select,
select.select,
:is(.form, .field) textarea,
.textarea,
:is(.form, .field) input[type="checkbox"]:not([role="switch"]),
.input[type="checkbox"]:not([role="switch"]),
:is(.form, .field) input[type="radio"],
.input[type="radio"],
.att-note-inline,
.class-exam-note-field,
.mobile-sheet--picker .m-picker-search {
    border-color: var(--field-border);
}
.att-note-inline:not(:placeholder-shown) { border-color: var(--field-border); }

/* Unchecked switch track (Basecoat paints it with the pale --input colour). */
html:not(.dark) :is(.form, .field) input[role="switch"]:not(:checked),
html:not(.dark) .input[role="switch"]:not(:checked) {
    background-color: var(--field-border);
}

::placeholder { color: var(--field-placeholder); opacity: 1; }
.class-exam-note-field::placeholder { color: var(--field-placeholder); }

/* ---- Text colours (light mode only; dark mode already passes) ----------- */
html:not(.dark) .text-gray-400,
html:not(.dark) .text-gray-500 { color: var(--muted-foreground); }
html:not(.dark) .text-red-400,
html:not(.dark) .text-red-500,
html:not(.dark) .text-red-600 { color: var(--text-danger); }
html:not(.dark) .text-blue-400,
html:not(.dark) .text-blue-500,
html:not(.dark) .text-blue-600 { color: var(--text-info); }
html:not(.dark) .text-yellow-500,
html:not(.dark) .text-yellow-600,
html:not(.dark) .text-amber-500 { color: var(--text-warning); }
html:not(.dark) .text-orange-400,
html:not(.dark) .text-orange-500,
html:not(.dark) .text-orange-600,
html:not(.dark) .text-orange-700 { color: var(--text-caution); }
html:not(.dark) .text-green-500,
html:not(.dark) .text-green-600,
html:not(.dark) .text-green-700 { color: var(--text-success); }

/* Hard-wired mid greys (oklch .556 = #737373 is 4.46:1 on the page colour, .708 is 2.6:1). */
.att-cal-weekdays,
.att-legend-item,
.att-date-sub,
.att-no-date-msg,
.class-exam-progress,
.class-exam-absent-btn,
.exam-absent-label,
.exam-summary-note { color: var(--muted-foreground); }
.att-seg-btn { color: var(--muted-foreground); }

/* Muted labels that were faded with opacity instead of a colour. */
.qsb-stat-label,
.qsb-section-title { opacity: 1; color: var(--muted-foreground); }

/* ---- Grade badges ------------------------------------------------------- */
/* Dark mode: same hues, one step lighter where the tint pushed them under 4.5:1. */
html.dark .grade-1,
html.dark .grade-plus { color: #4ade80 !important; }
html.dark .grade-4 { color: #fdba74 !important; }
html.dark .grade-5,
html.dark .grade-minus { color: #fca5a5 !important; }
html.dark .class-exam-grade-btn.g1 { color: #4ade80; }
html.dark .class-exam-grade-btn.g2 { color: #60a5fa; }
html.dark .class-exam-grade-btn.g4 { color: #fdba74; }
html.dark .class-exam-grade-btn.g5 { color: #fca5a5; }
/* Light mode */
html:not(.dark) .grade-1 { color: #116931 !important; }
html:not(.dark) .grade-2 { color: #066f4c !important; }
html:not(.dark) .grade-3 { color: #845a06 !important; }
html:not(.dark) .grade-4 { color: #9b3c08 !important; }
html:not(.dark) .grade-5 { color: #a41919 !important; }
html:not(.dark) .grade-plus { color: #116931 !important; }
html:not(.dark) .grade-neutral { color: #7f5705 !important; }
html:not(.dark) .grade-minus { color: #a91919 !important; }

html:not(.dark) .class-exam-grade-btn.g1 { color: #116931; }
html:not(.dark) .class-exam-grade-btn.g2 { color: #1e40af; }
html:not(.dark) .class-exam-grade-btn.g3 { color: #845a06; }
html:not(.dark) .class-exam-grade-btn.g4 { color: #9b3c08; }
html:not(.dark) .class-exam-grade-btn.g5 { color: #a41919; }

html:not(.dark) .trend-badge.declining { color: #a91919; }

/* Volksschul tiles (Beurteilung 1-5): colours come from classes now, not inline
   styles, so light and dark mode can differ. Selected = coloured border + tint. */
.primary-grade-btn { border-color: var(--field-border); }
.primary-grade-btn:has(input:checked) { border-color: var(--pg-fg); background: var(--pg-bg); }
.pg-label,
.pg-chip { background: var(--pg-bg); color: var(--pg-fg); }
.pg-1 { --pg-fg: #22c55e; --pg-bg: rgba(34, 197, 94, 0.12); }
.pg-2 { --pg-fg: #60a5fa; --pg-bg: rgba(59, 130, 246, 0.12); }
.pg-3 { --pg-fg: #eab308; --pg-bg: rgba(234, 179, 8, 0.12); }
.pg-4 { --pg-fg: #fdba74; --pg-bg: rgba(249, 115, 22, 0.12); }
.pg-5 { --pg-fg: #fca5a5; --pg-bg: rgba(239, 68, 68, 0.12); }
html:not(.dark) .pg-1 { --pg-fg: #116931; }
html:not(.dark) .pg-2 { --pg-fg: #1e40af; }
html:not(.dark) .pg-3 { --pg-fg: #845a06; }
html:not(.dark) .pg-4 { --pg-fg: #9b3c08; }
html:not(.dark) .pg-5 { --pg-fg: #a41919; }
.school-type-card:has(input:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ---- Attendance segments ------------------------------------------------ */
html:not(.dark) .att-seg-btn.sel-present { background: #047857; color: #fff; }
html:not(.dark) .att-seg-btn.sel-late    { background: #b45309; color: #fff; }
html:not(.dark) .att-seg-btn.sel-absent  { background: #b91c1c; color: #fff; }
html.dark .att-seg-btn.sel-present,
html.dark .att-seg-btn.sel-late,
html.dark .att-seg-btn.sel-absent { color: #0a0a0a; }
.att-day.att-day-selected { background-color: #1d4ed8; color: #fff; } /* was oklch(.585 .217 258.1) = 4.3:1, also dark */
.att-day.att-day-selected:hover { background-color: #1e40af; }

/* ---- Swipe actions (white on #3b82f6 = 3.7:1, white on #ef4444 = 3.8:1) -- */
.swipe-action-left  { background: #1d4ed8; }
.swipe-action-right { background: #b91c1c; }
/* Names and grades in the mobile cards must be selectable / copyable. */
.swipe-content { user-select: auto; -webkit-user-select: auto; }

/* ---- Persistent save-error banner -------------------------------------- */
#save-error-banner { color: #b91c1c !important; }
html.dark #save-error-banner { color: #fca5a5 !important; }
#save-error-banner-msg { opacity: 1 !important; }

/* ---- Minimum text size: 0.75rem (12px) ---------------------------------- */
#mobile-bottom-nav .mnav-btn,
#mobile-bottom-nav .mnav-btn span { font-size: 0.75rem; }
.att-cal-weekdays,
.att-legend-item,
.att-date-sub,
.att-initials-circle,
.trend-badge,
.qsb-stat-label,
.qsb-section-title,
.swipe-action { font-size: 0.75rem; }
#student-detail-view.compact-detail .stat-card p:first-child { font-size: 0.75rem !important; }
kbd.kbd { font-size: 0.75rem !important; opacity: 1 !important; }

/* ---- Status text / badges that used inline hex colours ------------------- */
.txt-ok   { color: #22c55e; }
.txt-warn { color: #eab308; }
.txt-bad  { color: #f87171; }
html:not(.dark) .txt-ok   { color: #116931; }
html:not(.dark) .txt-warn { color: #7f5705; }
html:not(.dark) .txt-bad  { color: #a91919; }

.exam-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.exam-badge-draft { color: #f59e0b; background: rgba(245, 158, 11, 0.13); border-color: rgba(245, 158, 11, 0.4); }
.exam-badge-done  { color: #22c55e; background: rgba(34, 197, 94, 0.13);  border-color: rgba(34, 197, 94, 0.4); }
html:not(.dark) .exam-badge-draft { color: #854d0e; }
html:not(.dark) .exam-badge-done  { color: #166534; }

/* ---- Reduced motion (WCAG 2.3.3 / 2.2.2) -------------------------------- */
/* style.css already collapses animation/transition durations globally, but the
   tutorial spotlight sets `animation: ... infinite !important` with ID-level
   specificity and kept pulsing. `:not(#id)` raises specificity to match those
   ID rules; this file is later, so it wins. */
@media (prefers-reduced-motion: reduce) {
    html,
    *, *::before, *::after { scroll-behavior: auto !important; }
    .tutorial-spotlight:not(#a11y-reduced-motion) { animation: none !important; }
}

/* ---- Skip link (WCAG 2.4.1) --------------------------------------------- */
.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 100002;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    background: var(--card);
    color: var(--foreground);
    border: 2px solid var(--focus-ring);
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-300%);
}
.skip-link:focus { transform: none; outline: none; }
main:focus { outline: none; }

/* ---- Sortable table headers: real buttons inside <th> --------------------- */
.sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.25rem;
    margin: -0.125rem -0.25rem;
    border: 0;
    border-radius: 0.25rem;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.sort-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

/* Selected accent colour: a check mark, not only a thicker ring (WCAG 1.4.1). */
.accent-swatch.is-active::after {
    content: "\2713";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* Offline pill: #a16207 on its yellow tint is 4.3:1 in light mode. */
html:not(.dark) #offline-indicator { color: #854d0e !important; }

/* ---- Basecoat solid buttons ---------------------------------------------- */
/* .btn-primary is restyled tonal in style.css, but .btn-sm-primary / .btn-lg-primary
   keep Basecoat's bg-primary/90: white on that is 4.46:1 (light, coral). Opaque
   accent instead (5.2:1); same family as .btn-cta. */
.btn-sm-primary,
.btn-lg-primary { background-color: var(--primary); }
.btn-sm-primary:hover,
.btn-lg-primary:hover { background-color: var(--primary); filter: brightness(0.95); }

/* ---- Avatar initials (white text on a random gradient) -------------------- */
#profile-avatar,
#profile-avatar-preview {
    box-shadow: inset 0 0 0 100px rgba(0, 0, 0, 0.5);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ---- Behaviour badges (light): #16a34a 3.0, #64748b 4.0, #dc2626 4.1 on their tint ---- */
html:not(.dark) .behavior-positive { --behavior-color: #166534; }
html:not(.dark) .behavior-neutral  { --behavior-color: #475569; }
html:not(.dark) .behavior-negative { --behavior-color: #b91c1c; }

/* Saving pill: inline #1d4ed8 on the dark surface is 2.4:1. */
html.dark #save-indicator { color: #93c5fd !important; }

.pw-toggle-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-radius: 0.25rem; }

/* ---- View titles are <h1> now (were <h2>): keep the mobile rules that targeted h2 ---- */
:where(html[data-layout="mobile"]) .card>header.flex.justify-between.items-center.mb-4 h1 {
    width: 100% !important;
    margin-bottom: 0 !important;
    font-size: 1.25rem !important;
}
:where(html[data-layout="mobile"]) #class-view h1 { font-size: 1rem !important; }
