/*
  SPDX-FileCopyrightText: 2026 Lukas Körber
  SPDX-License-Identifier: AGPL-3.0-only
*/

/* Buttons */
.btn-primary {
    background: var(--accent-fill);
    color: var(--on-accent);
    border-radius: 8px;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    display: inline-block;
}
.btn-primary:hover { opacity: 0.9; color: var(--on-accent); }
.btn-primary.saved { background: var(--success); color: var(--bg); }

.btn-secondary {
    background: var(--bg3);
    color: var(--text2);
    border: 1px solid var(--control-border);
    border-radius: 8px;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    transition: var(--transition);
}
.btn-secondary:hover { color: var(--text); border-color: var(--text3); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    transition: var(--transition);
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-focus {
    display: inline-block;
    background: var(--accent-fill);
    color: var(--on-accent);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.825rem;
    font-weight: 500;
    margin-top: 0.5rem;
    transition: var(--transition);
}
.btn-focus:hover { opacity: 0.9; color: var(--on-accent); }

/* Form elements */
.field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.field label { font-size: 0.8rem; color: var(--text2); }
.field-row { display: flex; gap: 0.75rem; }
.field-repeat { flex-direction: row; align-items: flex-start; flex-wrap: wrap; gap: 0.6rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text2); cursor: pointer; }
.field-row > .field { flex: 1 1 0; min-width: 0; }
.repeat-options { display: flex; flex-direction: column; gap: 0.6rem; width: 100%; }
.weekday-picker { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.weekday-chip {
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text2);
    cursor: pointer;
    font-size: 0.78rem;
    transition: var(--transition);
}
.weekday-chip:hover { border-color: var(--accent); }
.weekday-chip.selected { background: var(--accent-fill); color: var(--on-accent); border-color: var(--accent-fill); }

.input {
    background: var(--bg3);
    border: 1px solid var(--control-border);
    border-radius: 8px;
    padding: 0.6rem 0.875rem;
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--text);
    outline: none;
    transition: var(--transition);
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}
.input:focus { border-color: var(--accent); }
.input-sm { width: 80px; }

/* iOS Safari sizes date/time inputs from the native widget's intrinsic width as
   long as their native -webkit-appearance is active - author width/min-width/
   max-width (and the earlier -webkit-min-logical-width attempt) are simply not
   honored, so the control still overflowed narrow flex children (e.g. Planner's
   exam-date field). Dropping the native appearance turns them into normal
   boxes that obey the .input width:100%/border-box chain. */
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"] {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
    max-width: 100%;
}

/* With appearance:none iOS centers the value text and collapses the inner shadow
   div to zero height when the input is empty (e.g. unset Setup course goal). */
input::-webkit-date-and-time-value {
    text-align: inherit;
    min-height: 1.2em;
}

.select {
    background: var(--bg3);
    border: 1px solid var(--control-border);
    border-radius: 8px;
    padding: 0.6rem 0.875rem;
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--text);
    outline: none;
    transition: var(--transition);
    width: 100%;
    cursor: pointer;
}
.select:focus { border-color: var(--accent); }

/* iOS Safari/WKWebView auto-zooms the whole page on focus of any input/select whose computed
   font-size is below 16px, and the viewport meta tag here has no maximum-scale to undo it -
   the page stays zoomed in until the user manually pinches back out. .input/.select's base
   0.875rem (14px) triggers this; bump to 16px on mobile only, so desktop keeps the smaller
   size. Elements that set their own font-size on top of .input (e.g. .note-textarea) need
   their own override - this rule alone won't win that specificity/source-order tie. */
@media (max-width: 768px) {
    .input, .select { font-size: 16px; }
}

/* Modal */
.modal {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 16px;
    width: 440px;
    max-width: 92vw;
    /* Never taller than the viewport (minus a margin and the safe areas): a long dialog (e.g. the
       AI consent with its disclosures) keeps header and footer visible and scrolls its body, so
       the buttons always stay reachable. Same pattern as .program-modal. */
    max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

.modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 500; }
.modal-close { color: var(--text3); font-size: 1rem; width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; background: var(--bg3); }
.modal-close:hover { color: var(--text); }

.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.modal-footer { flex-shrink: 0; padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; justify-content: flex-end; }

/* Native modal dialog (Shared/ModalDialog.razor). The <dialog> element is only a transparent frame
   around the .modal panel, exactly its size: a click on the <dialog> itself is a click on its
   ::backdrop. The browser centres it in the top layer, above everything (no z-index needed).
   The backdrop is a dim with a blur; ::backdrop does not inherit custom
   properties in every WebKit the app supports, so its colours are written out here. */
dialog.sl-modal {
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    max-width: none;
    max-height: none;
    overflow: visible;
    margin: auto;
}
dialog.sl-modal::backdrop {
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}
/* The page behind an open dialog does not scroll (it is inert, but a touch or wheel on the
   backdrop could still move it). studylifeModal (interop.js) sets the class. */
html.sl-modal-open .main-content { overflow: hidden; }

/* Increase Contrast: a darker, unblurred backdrop and a solid panel edge, so the dialog stands
   clearly apart from the page behind it. */
@media (prefers-contrast: more) {
    dialog.sl-modal::backdrop { background: rgba(0,0,0,0.85); backdrop-filter: none; }
    dialog.sl-modal > .modal { border: 2px solid var(--text); }
}
@media (forced-colors: active) {
    dialog.sl-modal > .modal { border: 2px solid CanvasText; }
}

/* Opening fades and lifts the panel a little. Only for users who did not ask for reduced motion;
   closing is instant (the element leaves the page as soon as the dialog closes). */
@media (prefers-reduced-motion: no-preference) {
    dialog.sl-modal[open] > .modal { animation: sl-modal-in 160ms ease-out; }
    dialog.sl-modal[open]::backdrop { animation: sl-modal-fade 160ms ease-out; }
}
@keyframes sl-modal-in {
    from { opacity: 0; transform: translateY(0.5rem) scale(0.98); }
}
@keyframes sl-modal-fade {
    from { opacity: 0; }
}

/* Device management (PushDeviceManager, FAB bell) - somewhat wider than the standard .modal
   (440px) so label + "X days ago" + button don't wrap. The list itself scrolls instead of
   letting the modal grow arbitrarily tall when many devices are registered. */
.pdm-modal { width: 520px; }
.pdm-list { display: flex; flex-direction: column; gap: 0.6rem; max-height: 50vh; overflow-y: auto; }
.pdm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.pdm-row-main { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.pdm-row-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; color: var(--text); }
.pdm-row-meta { font-size: 0.8rem; color: var(--text3); }
.pdm-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-tint-text);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
}
/* An additional passkey still awaiting approval (PasskeyDeviceManager) - amber instead of the
   accent color, so a new/unknown entry stands out visually right away instead of looking like a
   normal, already-approved device. */
.pdm-row-pending { border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.pdm-pending-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--warning);
    background: var(--warning-bg);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
}

/* AI chat/agent (AgentChatModal, FAB) - wider than the standard .modal, same reasoning as
   .pdm-modal (message bubbles need more room than a settings list). */
.acm-modal { width: 480px; }
.acm-empty { display: flex; flex-direction: column; gap: 0.75rem; align-items: center; text-align: center; padding: 1rem 0; }

.acm-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: -0.5rem 0 0; }
.acm-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 0.9rem;
    font-size: 0.875rem;
    color: var(--text3);
    cursor: pointer;
    transition: var(--transition);
}
.acm-tab:hover { color: var(--text2); }
.acm-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.acm-messages { display: flex; flex-direction: column; gap: 0.6rem; max-height: 45vh; overflow-y: auto; padding-right: 0.15rem; }
.acm-msg { display: flex; }
.acm-msg-user { justify-content: flex-end; }
.acm-msg-assistant { justify-content: flex-start; }
.acm-msg-bubble {
    max-width: 82%;
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
.acm-msg-user .acm-msg-bubble { background: var(--accent-fill); color: var(--on-accent); border-bottom-right-radius: 4px; }
.acm-msg-assistant .acm-msg-bubble { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.acm-sources { font-size: 0.75rem; color: var(--text3); }

.acm-input-row { display: flex; gap: 0.5rem; }
.acm-input-row .input { flex: 1; }

.acm-pending {
    background: color-mix(in srgb, var(--warning) 10%, var(--bg3));
    border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.acm-pending-title { font-weight: 500; color: var(--text); font-size: 0.875rem; margin: 0; }
.acm-pending-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* Progressive-render skeletons (2026-09, all pages): a placeholder block shown in place of a
   section whose data is still loading, so the page shell paints immediately and nothing ever
   shows a zero/empty value that flips to real data a moment later. Lives in shared.css because
   per-page sheets are deferred (boot-loading.js) and the skeleton must be styled from the very
   first paint. Same look as .dash-card.is-loading in dashboard.css. */
.sl-skeleton {
    position: relative;
    overflow: hidden;
    min-height: 6.5rem;
    border-radius: 12px;
    background: var(--bg2);
}
.sl-skeleton-sm { min-height: 3rem; }
.sl-skeleton-lg { min-height: 14rem; }
.sl-skeleton-xl { min-height: 24rem; }
.sl-skeleton-row { display: flex; flex-direction: column; gap: 0.75rem; }
/* SkeletonRegion: the aria-busy wrapper with the one hidden "Loading" status. It takes no box, so
   the blocks inside stay direct children of the page's flex or grid. */
.sl-skeleton-region { display: contents; }

/* FormField (Components/Forms): the wrapper around label, control, hint and error takes no box, so
   they lay out exactly like the bare label and input did. */
.form-field { display: contents; }
.form-field-hint { font-size: 0.8rem; margin: 0; }

/* FormMessage (Shared): the result of what the user did. The icon and the text carry the kind, the
   colour only backs it up (WCAG 1.4.1). --danger/--success/--text2 are >= 4.5:1 on every surface. */
.form-message {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
}
.form-message::before { flex: none; font-weight: 700; }
.form-message-error::before { content: "⚠" / ""; }
.form-message-success::before { content: "✓" / ""; }
.form-message-info::before { content: "ℹ" / ""; }
.form-message-error { color: var(--danger); }
.form-message-success { color: var(--success); }
.form-message-info { color: var(--text2); }
.form-field-error { font-size: 0.8rem; }

.sl-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, var(--bg3), transparent);
    animation: sl-skeleton-sweep 1.6s ease-in-out infinite;
}

@keyframes sl-skeleton-sweep {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
    .sl-skeleton::after { animation: none; opacity: 0.6; }
}

/* Form controls must never be wider than their column. A <select> takes the width of its
   longest <option> - a long course name ("Objektorientierte Programmierung im 1. Semester")
   made the notes editor and the planner's course row wider than a phone screen on iOS. */
.select, .input {
    max-width: 100%;
    min-width: 0;
}
.field, .field-row, .field-row > * {
    min-width: 0;
}

/* Accessibility baseline (CONTRIBUTING.md "Accessibility").
   Keyboard focus is always visible: :focus-visible only matches keyboard (and programmatic
   keyboard-like) focus, so mouse and touch users see no change. The form controls above set
   outline: none and only change their border colour on focus; the rules below restore a real
   focus ring for keyboard users there too. :where() keeps the generic rule at zero specificity,
   so a component that draws its own focus style still wins. */
:where(a, button, summary, [role="button"], [role="tab"], [role="switch"], [tabindex]:not([tabindex="-1"])):focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}
.input:focus-visible, .select:focus-visible, .gs-input:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 1px;
}

/* Button reset: the one place that turns a native <button> into a control that looks like the
   element it replaces (a calendar block, a list row, a pill). The global "button" rule in base.css
   already clears border and background; this adds what the browser still applies to buttons
   (own font, own colour, centred text). :where() keeps the specificity at zero, so the component
   class that is combined with it (.cal-session, .note-row, .topic-pill, ...) always decides the
   look. The keyboard focus ring is the global :focus-visible rule above - nothing to add here. */
:where(.btn-plain) {
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    color: inherit;
    text-align: inherit;
    touch-action: manipulation;
}

/* Text for assistive technology only (state words, long names that are drawn as a glyph). */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* "Skip to main content" (Shared/SkipLink.razor): off-screen until it takes keyboard focus. */
.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 2000;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius, 8px);
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    text-decoration: underline;
    transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* Hint text in every field (the browser default, #757575, is 3.6-3.8:1 on both themes). The
   theme's own tertiary text colour is the one place that decides it; opacity: 1 because Firefox
   dims the colour of placeholders by default. .gs-input (base.css) uses the same colour. */
::placeholder { color: var(--text3); opacity: 1; }

/* Text on a course colour (WCAG 1.4.3). Course colours are user data and can be anything from black
   to white, so no text is ever drawn in --c and no text colour is derived from it. The colour only
   tints the surface (--tint of it, --tint-muted for past and done items) and the text on it is
   --text or --text2, the colours of the theme. The tint is small enough that these stay >= 4.5:1 on
   it for every possible course colour: tools/check-contrast.py proves it for black, white and the
   whole course palette, on every surface, theme and contrast mode, so this is the single place that
   decides it. --tint-base is the surface under the tint (default: transparent, the element's own
   surface shows through). ":root" in front beats the component rules whatever order the per-page
   sheets load in. */
:root .on-tint {
    background: color-mix(in srgb, var(--c) var(--tint), var(--tint-base, transparent));
    color: var(--text);
}

/* Users who ask the OS for reduced motion get no animations or transitions anywhere, not only
   in the skeleton loaders that already had their own rule. Durations are shortened instead of
   removed so transitionend/animationend handlers still fire. */
@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;
    }
}

/* === Bar charts (stats cards, dashboard trend) ===
   Every column chart shares these three classes, so axis labels behave the same everywhere:
   - .chart-plot: the row of columns. Inner horizontal padding, so the first and last column's
     centered label never touches or runs past the card edge (or the scroll edge of a
     scrolling chart, where the last label used to end flush against the clip line).
   - .chart-scroll: the wrapper of a chart that may be wider than its card (many weeks/months).
     It scrolls sideways; its .chart-plot is as wide as its columns need, at least the card.
     Scrolling happens here, never on the row itself, because WebKit drops a flex scroll
     container's end padding and the last column would be clipped again.
   - .chart-axis-label: a column's axis label (date, month, weekday). Never wrapped, ellipsized
     or clipped: each column is at least as wide as its label (flex min-width: auto), and the
     row's edge padding covers the outermost ones. */
:root { --chart-edge-pad: 0.5rem; }
.chart-plot { padding-inline: var(--chart-edge-pad); }
.chart-scroll { overflow-x: auto; padding-bottom: 0.25rem; scroll-padding-inline: var(--chart-edge-pad); }
.chart-scroll > .chart-plot { width: max-content; min-width: 100%; }
.chart-axis-label { text-align: center; white-space: nowrap; overflow: visible; text-overflow: clip; }

/* Source caption under cards that show Apple Health data (HealthSourceLabel.razor); --text3 is the
   AA-checked muted text colour in both themes. */
.health-source { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.6rem; font-size: 0.7rem; color: var(--text3); }
.health-source-icon { flex-shrink: 0; }
