/* =============================================================
   Base layer — reset, document defaults and accessibility
   primitives shared by every page (auth, member, admin, care
   manager). Loaded straight after var.css in every layout.
   Anything here must be safe on all four shells.
   ============================================================= */

* {
    box-sizing: border-box;
}

html {
    font-size: var(--root-font-size);
}

body {
    margin: 0;
    min-width: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    font-size: var(--text-base);
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

    button,
    select,
    input[type="checkbox"] {
        cursor: pointer;
    }

button {
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    z-index: 1000;
    top: 8px;
    left: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    min-height: 44px;
    color: var(--surface);
    background: var(--ink);
    border-radius: var(--radius-xs);
    transform: translateY(-150%);
}

    .skip-link:focus {
        transform: translateY(0);
    }

/* One focus treatment everywhere. Keyboard users get a visible ring;
   pointer users do not. */
:focus-visible {
    outline: 2px solid var(--accent-hover);
    outline-offset: 2px;
}

/* Keep focused/anchored content clear of the sticky topbar (WCAG 2.4.11). */
html {
    scroll-padding-top: calc(var(--topbar) + 16px);
}

/* 16px remove buttons: grow the hit area to 24px without changing the look
   (WCAG 2.5.8 Target Size). */
.chip-multi-remove,
.activity-subtype-tag button {
    position: relative;
}

.chip-multi-remove::after,
.activity-subtype-tag button::after {
    content: "";
    position: absolute;
    inset: -4px;
}

/* Borderless inputs inside a styled wrapper drop their own outline; ring the
   wrapper instead so focus stays visible (WCAG 2.4.7). */
.cm-search:focus-within,
.search-box:focus-within,
.chatbot-input-area:focus-within,
.mco-period select:focus-visible {
    outline: 3px solid var(--accent-hover);
    outline-offset: 2px;
}

/* Keep focused content clear of bottom-fixed UI: the member chat button, sticky
   action bars and toasts (WCAG 2.4.11 Focus Not Obscured). */
html {
    scroll-padding-bottom: 96px;
}

/* Honour the operating-system "reduce motion" setting on every page
   (WCAG 2.3.3 Animation from Interactions; also helps 2.2.2 Pause, Stop, Hide). */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Session-timeout warning (WCAG 2.2.1) ------------------------------- */
.session-timeout-dialog {
    width: min(440px, calc(100vw - 32px));
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-2xl);
}

.session-timeout-dialog::backdrop {
    background: rgba(16, 24, 40, .55);
}

.session-timeout-dialog h2 {
    margin: 0 0 8px;
    color: var(--ink-strong);
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
}

.session-timeout-dialog p {
    margin: 0;
    color: var(--ink);
    font-size: var(--text-md);
    line-height: 1.5;
}

.session-timeout-dialog p span {
    display: block;
}

.session-timeout-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.session-timeout-actions button {
    min-height: 44px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    cursor: pointer;
}

.session-timeout-secondary {
    border: 2px solid var(--blue-700);
    background: var(--surface);
    color: var(--blue-800);
}

/* Upload areas: the real <input type="file"> is visually hidden and its <label> is the visible drop zone.
   Show the focus ring on the label when the hidden input has keyboard focus (WCAG 2.4.7). */
label:has(+ input[type="file"].visually-hidden:focus-visible),
label:has(input[type="file"].visually-hidden:focus-visible) {
    outline: 3px solid var(--accent-hover);
    outline-offset: 2px;
}

label.is-file-input-focused {
    outline: 3px solid var(--accent-hover);
    outline-offset: 2px;
}

/* ==========================================================================
   Buttons and links: one system for every role, taken from the Member
   dashboard (the style source). Loaded by every layout, so site.css and
   site-auth.css carry no button looks of their own.

   Kind                              Look
   .btn-primary, .button-primary     flat solid accent fill, white text, no border. One per section.
   .btn, .btn-secondary, .button,    white fill, 2px blue-700 border, blue-800 text; hover = blue-50 fill
   .btn-outline-*, .btn-dark,        and blue-900 border. The default for bulk and utility actions.
   .button-secondary                 (the same look as .btn.dash-action in member-ai.css)
   .btn-plain, .btn-link             link: blue-800, underlined 2px, 3px on hover (as a.dash-link).
   .btn-danger, .btn-outline-danger  the secondary look in red; solid red only in a confirm step.
   .btn-green, .btn-success          the secondary look in green.
   .btn-sm                           tighter padding, same 44px target.

   No gradients and no navy fills. Target size stays 44px (a11y.css), 14px /
   600 text, 8px radius. Focus ring: a11y.css (3px, offset 2px, never removed).
   Contrast: blue-800 on white about 7:1; white on blue-600 4.5:1.
   ========================================================================== */
.btn,
.button,
.btn-primary,
.btn-secondary {
    /* Tokens: the secondary (outline) look is the default; the kinds below override them. */
    --btn-fg: var(--blue-800);
    --btn-bg: var(--surface);
    --btn-bd: var(--blue-700);
    --btn-fg-h: var(--blue-900);
    --btn-bg-h: var(--blue-50);
    --btn-bd-h: var(--blue-900);
    --btn-bg-a: var(--blue-100);
    /* Bootstrap's own hover, active and disabled rules read these, so they stay on-system. */
    --bs-btn-color: var(--btn-fg);
    --bs-btn-bg: var(--btn-bg);
    --bs-btn-border-color: var(--btn-bd);
    --bs-btn-hover-color: var(--btn-fg-h);
    --bs-btn-hover-bg: var(--btn-bg-h);
    --bs-btn-hover-border-color: var(--btn-bd-h);
    --bs-btn-active-color: var(--btn-fg-h);
    --bs-btn-active-bg: var(--btn-bg-a);
    --bs-btn-active-border-color: var(--btn-bd-h);
    --bs-btn-disabled-color: var(--btn-fg);
    --bs-btn-disabled-bg: var(--btn-bg);
    --bs-btn-disabled-border-color: var(--btn-bd);
    --bs-btn-focus-box-shadow: none;
    min-height: 44px;
    max-width: 100%;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 2px solid var(--btn-bd);
    border-radius: var(--radius-sm);
    color: var(--btn-fg);
    background: var(--btn-bg);
    box-shadow: none;
    font-size: var(--text-base);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.btn,
.button {
    display: inline-flex;
    white-space: nowrap;
}

/* Standalone .btn-primary and .btn-secondary keep their long-standing block-level flex box. */
.btn-primary,
.btn-secondary {
    display: flex;
}

.btn:hover,
.button:hover,
.btn-primary:hover,
.btn-secondary:hover {
    color: var(--btn-fg-h);
    background: var(--btn-bg-h);
    border-color: var(--btn-bd-h);
}

.btn:active,
.button:active,
.btn-primary:active,
.btn-secondary:active {
    background: var(--btn-bg-a);
}

/* Icons are decorative and never shrink; a component class that sets its own icon size wins (zero specificity). */
:where(.btn, .button, .btn-primary, .btn-secondary) svg {
    flex: none;
    width: 18px;
    height: 18px;
}

/* Primary: the one main action in a section or card. Flat, no gradient. */
.btn-primary,
.button-primary {
    --btn-fg: var(--surface);
    --btn-bg: var(--accent);
    --btn-bd: var(--accent);
    --btn-fg-h: var(--surface);
    --btn-bg-h: var(--accent-hover);
    --btn-bd-h: var(--accent-hover);
    --btn-bg-a: var(--blue-800);
    padding: 10px 20px;
    border-width: 0;
}

/* Link kind: the Member underlined blue link (a.dash-link). */
.btn-plain,
.btn-link {
    --btn-fg: var(--blue-800);
    --btn-bg: transparent;
    --btn-bd: transparent;
    --btn-fg-h: var(--blue-900);
    --btn-bg-h: transparent;
    --btn-bd-h: transparent;
    --btn-bg-a: transparent;
    padding: 8px;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.btn-plain:hover,
.btn-link:hover {
    text-decoration-thickness: 3px;
}

/* Danger: the outline look in red; solid red is reserved for the confirm step (.delete-rule-modal-confirm). */
.btn-danger,
.btn-outline-danger {
    --btn-fg: var(--red-600);
    --btn-bd: var(--red-600);
    --btn-fg-h: var(--red-700);
    --btn-bg-h: var(--red-50);
    --btn-bd-h: var(--red-700);
    --btn-bg-a: var(--red-100);
}

/* Success: the outline look in green. */
.btn-green,
.btn-success,
.btn-outline-success {
    --btn-fg: var(--green-700);
    --btn-bd: var(--green-700);
    --btn-fg-h: var(--green-700);
    --btn-bg-h: var(--green-50);
    --btn-bd-h: var(--green-700);
    --btn-bg-a: var(--green-100);
}

/* Small: tighter padding, same 44px target. */
.btn-sm {
    padding: 4px 12px;
    font-size: var(--text-sm);
}

/* Disabled (the Member .dash-action look: muted slate, still readable). */
.btn:disabled,
.btn.disabled,
.btn[aria-disabled="true"],
fieldset:disabled .btn,
.button:disabled,
.button[aria-disabled="true"],
.btn-secondary:disabled {
    --btn-fg: var(--slate-600);
    --btn-bd: var(--slate-600);
    color: var(--btn-fg);
    background: var(--btn-bg);
    border-color: var(--btn-bd);
    opacity: .7;
    cursor: not-allowed;
}

.btn-primary:disabled,
.btn-primary.disabled,
.button-primary:disabled {
    --btn-fg: var(--surface);
    --btn-bg: var(--accent);
    --btn-bd: var(--accent);
    color: var(--btn-fg);
    background: var(--btn-bg);
    opacity: .65;
    cursor: not-allowed;
}

/* A loading (Ladda) button is disabled but must stay fully visible. */
.btn[data-loading],
.button[data-loading],
.btn-primary[data-loading],
.btn-secondary[data-loading] {
    opacity: 1;
    cursor: wait;
}
