/*
 * Open Loans — Apple-inspired design system (extensions)
 * Adds: responsive utilities, form patterns, step indicators, breadcrumbs,
 * skeletons, toasts, empty states, avatars, tab bars, scroll reveal helper.
 *
 * Composed on top of apple-system.css tokens. Safe to include globally.
 */

/* -----------------------------------------------------------
 * Responsive rhythm helpers
 * --------------------------------------------------------- */
.al-scope .al-show-md {
    display: none;
}

.al-scope .al-hide-md {
    display: initial;
}

@media (min-width: 768px) {
    .al-scope .al-show-md {
        display: initial;
    }

    .al-scope .al-hide-md {
        display: none;
    }
}

.al-scope .al-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.al-scope .al-stack--sm {
    gap: var(--space-2);
}

.al-scope .al-stack--lg {
    gap: var(--space-6);
}

.al-scope .al-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.al-scope .al-row--tight {
    gap: var(--space-2);
}

.al-scope .al-row--between {
    justify-content: space-between;
}

.al-scope .al-spacer {
    flex: 1 1 auto;
}

.al-scope .al-muted {
    color: var(--ink-500);
}

.al-scope .al-emphasis {
    color: var(--ink-900);
    font-weight: 500;
}

.al-scope .al-numeric {
    font-variant-numeric: tabular-nums;
}

.al-scope .al-text-sm {
    font-size: 0.875rem;
}

.al-scope .al-text-xs {
    font-size: 0.8125rem;
}

.al-scope .al-text-lg {
    font-size: 1.125rem;
}

.al-scope .al-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.al-scope .al-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.al-scope .al-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* -----------------------------------------------------------
 * Form patterns
 * --------------------------------------------------------- */
.al-scope .al-fieldset {
    display: grid;
    gap: var(--space-4);
}

.al-scope .al-fieldset>.al-field {
    margin: 0;
}

.al-scope .al-form-row {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.al-scope .al-field__hint {
    font-size: 0.8125rem;
    color: var(--ink-500);
    margin-top: 4px;
}

.al-scope .al-field__error {
    font-size: 0.8125rem;
    color: var(--tint-critical);
    margin-top: 4px;
}

.al-scope .al-field--invalid input,
.al-scope .al-field--invalid select,
.al-scope .al-field--invalid textarea,
.al-scope .al-input--invalid {
    border-color: var(--tint-critical) !important;
    box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.12);
}

/* Input addon layout (prefix/suffix text e.g., $, %) */
.al-scope .al-input-group {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--hairline-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
    overflow: hidden;
}

.al-scope .al-input-group:focus-within {
    border-color: var(--accent-500);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
}

.al-scope .al-input-group input {
    border: 0 !important;
    box-shadow: none !important;
    padding: 12px 14px;
    flex: 1 1 auto;
    background: transparent;
    font: inherit;
    color: var(--ink-900);
    min-width: 0;
}

.al-scope .al-input-group__addon {
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    color: var(--ink-500);
    background: var(--surface-sunken);
    font-size: 0.9375rem;
    border-left: 1px solid var(--hairline);
}

.al-scope .al-input-group__addon--leading {
    border-left: 0;
    border-right: 1px solid var(--hairline);
}

/* Segmented pill control (two or more) */
.al-scope .al-segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    background: var(--surface-sunken);
    border-radius: var(--radius-pill);
    border: 1px solid var(--hairline-soft);
}

.al-scope .al-segmented__option {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--ink-700);
    font: 500 0.9375rem var(--font-text);
    padding: 8px 18px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.al-scope .al-segmented__option:hover {
    color: var(--ink-900);
}

.al-scope .al-segmented__option.is-active,
.al-scope .al-segmented__option[aria-selected="true"] {
    background: var(--surface-raised);
    color: var(--ink-900);
    box-shadow: var(--shadow-xs);
}

/* Toggle switch */
.al-scope .al-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.al-scope .al-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.al-scope .al-switch__track {
    width: 42px;
    height: 26px;
    border-radius: var(--radius-pill);
    background: var(--ink-200);
    position: relative;
    transition: background var(--dur-base) var(--ease-out);
}

.al-scope .al-switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur-base) var(--ease-out);
}

.al-scope .al-switch input:checked+.al-switch__track {
    background: var(--accent-500);
}

.al-scope .al-switch input:checked+.al-switch__track::after {
    transform: translateX(16px);
}

.al-scope .al-switch input:focus-visible+.al-switch__track {
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.2);
}

/* Checkbox / radio — minimal */
.al-scope .al-check {
    display: inline-flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}

.al-scope .al-check input {
    margin-top: 2px;
    accent-color: var(--accent-500);
}

/* -----------------------------------------------------------
 * Step indicator (for multi-step flows like OpenSwitch)
 * --------------------------------------------------------- */
.al-scope .al-steps {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    font-size: 0.875rem;
    color: var(--ink-500);
}

.al-scope .al-step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-sunken);
    color: var(--ink-500);
    font-weight: 500;
    letter-spacing: -0.003em;
}

.al-scope .al-step.is-current {
    background: var(--ink-900);
    color: var(--ink-000);
}

.al-scope .al-step.is-done {
    background: var(--accent-050);
    color: var(--accent-600);
}

.al-scope .al-step__index {
    font-variant-numeric: tabular-nums;
    font-size: 0.8125rem;
    opacity: 0.8;
}

.al-scope .al-step__sep {
    color: var(--ink-300);
    font-size: 0.875rem;
}

/* Progress bar */
.al-scope .al-progress {
    height: 4px;
    width: 100%;
    background: var(--surface-sunken);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.al-scope .al-progress__fill {
    height: 100%;
    background: var(--accent-500);
    border-radius: inherit;
    transition: width var(--dur-slow) var(--ease-out);
}

/* -----------------------------------------------------------
 * Breadcrumbs
 * --------------------------------------------------------- */
.al-scope .al-breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    font-size: 0.875rem;
    color: var(--ink-500);
    align-items: center;
}

.al-scope .al-breadcrumbs a {
    color: var(--ink-600);
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-out);
}

.al-scope .al-breadcrumbs a:hover {
    color: var(--ink-900);
}

.al-scope .al-breadcrumbs__sep {
    color: var(--ink-300);
}

.al-scope .al-breadcrumbs__current {
    color: var(--ink-900);
    font-weight: 500;
}

/* -----------------------------------------------------------
 * Skeletons (loading placeholders)
 * --------------------------------------------------------- */
.al-scope .al-skeleton {
    background: linear-gradient(90deg, var(--ink-100) 0%, var(--ink-050) 50%, var(--ink-100) 100%);
    background-size: 200% 100%;
    animation: al-skeleton-shimmer 1.4s linear infinite;
    border-radius: var(--radius-sm);
}

.al-scope .al-skeleton--line {
    height: 14px;
}

.al-scope .al-skeleton--line.is-short {
    width: 40%;
}

.al-scope .al-skeleton--line.is-medium {
    width: 70%;
}

.al-scope .al-skeleton--block {
    height: 120px;
    border-radius: var(--radius-md);
}

.al-scope .al-skeleton--circle {
    border-radius: 50%;
}

@keyframes al-skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* -----------------------------------------------------------
 * Toast / inline notices
 * --------------------------------------------------------- */
.al-scope .al-notice {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
    color: var(--ink-800);
    font-size: 0.9375rem;
    line-height: 1.45;
    border: 1px solid var(--hairline-soft);
}

.al-scope .al-notice--positive {
    background: var(--tint-positive-050);
    color: var(--tint-positive);
    border-color: transparent;
}

.al-scope .al-notice--warning {
    background: var(--tint-warning-050);
    color: var(--tint-warning);
    border-color: transparent;
}

.al-scope .al-notice--critical {
    background: var(--tint-critical-050);
    color: var(--tint-critical);
    border-color: transparent;
}

.al-scope .al-notice__title {
    font-weight: 600;
    color: inherit;
    margin-right: 6px;
}

/* -----------------------------------------------------------
 * Empty state
 * --------------------------------------------------------- */
.al-scope .al-empty {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    max-width: 520px;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    align-items: center;
}

.al-scope .al-empty h3 {
    font-size: 1.5rem;
    letter-spacing: -0.018em;
}

.al-scope .al-empty p {
    color: var(--ink-500);
}

/* -----------------------------------------------------------
 * Avatar
 * --------------------------------------------------------- */
.al-scope .al-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-sunken);
    color: var(--ink-700);
    font-weight: 600;
    letter-spacing: 0.02em;
    font-size: 0.9375rem;
    border: 1px solid var(--hairline-soft);
    overflow: hidden;
}

.al-scope .al-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.al-scope .al-avatar--lg {
    width: 56px;
    height: 56px;
    font-size: 1.125rem;
}

.al-scope .al-avatar--sm {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

/* -----------------------------------------------------------
 * Tab bar (inline, underlined)
 * --------------------------------------------------------- */
.al-scope .al-tabs {
    display: flex;
    gap: var(--space-4);
    border-bottom: 1px solid var(--hairline);
    overflow-x: auto;
    scrollbar-width: none;
}

.al-scope .al-tabs::-webkit-scrollbar {
    display: none;
}

.al-scope .al-tabs__item {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 14px 2px;
    font: 500 0.9375rem var(--font-text);
    color: var(--ink-500);
    cursor: pointer;
    position: relative;
    transition: color var(--dur-fast) var(--ease-out);
    white-space: nowrap;
    text-decoration: none;
}

.al-scope .al-tabs__item:hover {
    color: var(--ink-900);
}

.al-scope .al-tabs__item.is-active {
    color: var(--ink-900);
}

.al-scope .al-tabs__item.is-active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--ink-900);
    border-radius: 2px;
}

/* -----------------------------------------------------------
 * Accordion (disclosure)
 * --------------------------------------------------------- */
.al-scope .al-disclosure {
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    overflow: hidden;
}

.al-scope .al-disclosure+.al-disclosure {
    margin-top: 8px;
}

.al-scope .al-disclosure>summary {
    list-style: none;
    padding: 18px 20px;
    font-weight: 500;
    color: var(--ink-900);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition: background var(--dur-fast) var(--ease-out);
}

.al-scope .al-disclosure>summary::-webkit-details-marker {
    display: none;
}

.al-scope .al-disclosure>summary::after {
    content: "+";
    font-size: 1.25rem;
    color: var(--ink-500);
    transition: transform var(--dur-base) var(--ease-out);
}

.al-scope .al-disclosure[open]>summary::after {
    content: "–";
}

.al-scope .al-disclosure>summary:hover {
    background: var(--surface-sunken);
}

.al-scope .al-disclosure>div {
    padding: 0 20px 20px;
    color: var(--ink-600);
}

/* -----------------------------------------------------------
 * Scroll reveal helper (opt-in via JS that toggles .is-visible)
 * Already declared in apple-system.css; re-asserted here for safety.
 * --------------------------------------------------------- */

/* -----------------------------------------------------------
 * Mobile polish
 * --------------------------------------------------------- */
@media (max-width: 640px) {
    .al-scope h1 {
        font-size: clamp(2rem, 1.2rem + 3vw, 2.5rem);
    }

    .al-scope .al-hero {
        padding-block: clamp(56px, 14vw, 96px);
    }

    .al-scope .al-section {
        padding-block: clamp(40px, 10vw, 72px);
    }

    .al-scope .al-button {
        padding: 12px 20px;
        width: 100%;
        justify-content: center;
    }

    .al-scope .al-hero__cta {
        flex-direction: column;
        align-items: stretch;
    }

    .al-scope .al-hero__cta .al-link-chevron {
        justify-content: center;
    }

    .al-scope .al-stickybar {
        padding-inline: 16px;
    }
}

/* -----------------------------------------------------------
 * Motion utilities
 * --------------------------------------------------------- */
.al-scope .al-fade-in {
    animation: al-fade-in var(--dur-slow) var(--ease-out) both;
}

@keyframes al-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.al-scope .al-pulse {
    animation: al-pulse 1.4s var(--ease-standard) infinite;
}

@keyframes al-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.55;
    }
}

/* -----------------------------------------------------------
 * Overlays, dialogs
 * --------------------------------------------------------- */
.al-scope .al-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 12, 0.48);
    backdrop-filter: blur(6px);
    z-index: 1000;
}

.al-scope .al-dialog {
    background: var(--surface-raised);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 560px;
    width: calc(100% - 32px);
    padding: var(--space-6);
    border: 1px solid var(--hairline-soft);
}

/* -----------------------------------------------------------
 * Focus visibility
 * --------------------------------------------------------- */
.al-scope a:focus-visible,
.al-scope button:focus-visible,
.al-scope [role="button"]:focus-visible {
    outline: 2px solid var(--accent-500);
    outline-offset: 3px;
    border-radius: var(--radius-xs);
}

/* -----------------------------------------------------------
 * Scrollbar polish (webkit)
 * --------------------------------------------------------- */
.al-scope ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.al-scope ::-webkit-scrollbar-thumb {
    background: var(--ink-200);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.al-scope ::-webkit-scrollbar-thumb:hover {
    background: var(--ink-300);
    background-clip: padding-box;
    border: 2px solid transparent;
}

.al-scope ::-webkit-scrollbar-track {
    background: transparent;
}