/**
 * ShiftHandler Accessibility Styles
 * Provides enhanced focus states, high contrast support, and reduced motion
 */

/* ============================================================
   SKIP LINKS
   ============================================================ */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0056b3; /* ~5.9:1 on white — WCAG AA for normal text */
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ============================================================
   FOCUS STYLES
   ============================================================ */

/* Enhanced focus visible for keyboard navigation */
:focus-visible {
    outline: 3px solid #3699FF !important;
    outline-offset: 2px !important;
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* High visibility focus for important interactive elements */
.btn:focus-visible,
.nav-link:focus-visible,
.menu-link:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 3px solid #3699FF !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(54, 153, 255, 0.25) !important;
}

/* Card focus indicator */
.card:focus-within {
    box-shadow: 0 0 0 2px #3699FF;
}

/* ============================================================
   SCREEN READER ONLY
   ============================================================ */
.visually-hidden,
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Allow visually hidden content to be focusable */
.visually-hidden-focusable:not(:focus):not(:focus-within) {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@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;
    }
}

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ============================================================
   HIGH CONTRAST MODE
   ============================================================ */
@media (forced-colors: active) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .card {
        border: 1px solid currentColor;
    }
    
    .badge {
        border: 1px solid currentColor;
    }
    
    .form-control,
    .form-select {
        border: 2px solid currentColor;
    }
    
    /* Ensure icons are visible */
    .ki-outline::before,
    .ki-duotone::before {
        forced-color-adjust: none;
    }
}

/* ============================================================
   FORM ACCESSIBILITY
   ============================================================ */

/* Error state visibility */
.is-invalid,
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #F1416C !important;
    border-width: 2px !important;
}

.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(241, 65, 108, 0.25) !important;
}

/* Required field indicator */
.form-label.required::after {
    content: " *";
    color: #F1416C;
}

/* Disabled state clarity */
.form-control:disabled,
.form-select:disabled,
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================================
   LINK ACCESSIBILITY
   ============================================================ */

/* Ensure links are distinguishable */
a:not(.btn):not(.nav-link):not(.menu-link) {
    text-decoration: underline;
    text-decoration-skip-ink: auto;
}

a:not(.btn):not(.nav-link):not(.menu-link):hover {
    text-decoration-thickness: 2px;
}

/* External link indicator */
a[target="_blank"]::after {
    content: " (opens in new tab)";
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   TABLE ACCESSIBILITY
   ============================================================ */
table {
    border-collapse: collapse;
}

th {
    text-align: left;
    font-weight: 600;
}

/* Row hover for better tracking */
.table-hover tbody tr:hover {
    outline: 2px solid #3699FF;
    outline-offset: -2px;
}

/* ============================================================
   TOUCH TARGETS
   ============================================================ */
@media (pointer: coarse) {
    /* Ensure minimum touch target size of 44x44px */
    .btn,
    .nav-link,
    .menu-link,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Increase spacing between interactive elements */
    .btn + .btn,
    .nav-link + .nav-link {
        margin-left: 8px;
    }
}

/* ============================================================
   COLOR CONTRAST HELPERS
   ============================================================ */

/*
 * Metronic light greys used as text fail WCAG 2.1 AA on white:
 *   --bs-text-muted / gray-500 #99A1B7 = 2.58:1
 *   --bs-text-gray-400          #C4CADA = 1.64:1
 *   --bs-text-gray-600          #78829D = 3.83:1 (large text only)
 * Dark-theme muted #636674 is 2.98:1 on cards (#1B1C22) and 3.14:1 on
 * body (#15171C). Surface greys (gray-100..300, borders) are unchanged.
 *
 * Targets (normal text AA = 4.5:1):
 *   light muted/400/500 #5e6278 on #fff = 6.01:1
 *   light 600           #4B5675 on #fff = 7.27:1
 *   dark muted/400/500  #9A9CAE on #1B1C22 = 6.26:1
 *   dark 600            #B5B7C8 on #1B1C22 = 8.55:1
 */
:root,
[data-bs-theme=light] {
    --bs-text-muted: #5e6278;
    --bs-text-gray-400: #5e6278;
    --bs-text-gray-500: #5e6278;
    --bs-text-gray-600: #4B5675;
    --bs-input-solid-placeholder-color: #5e6278;
    /* Brand text on white: Metronic defaults fail AA (primary 3.63, success 2.27, warning 1.69). */
    --bs-text-primary: #0062cc; /* 5.80:1 — same as badge-light-primary */
    --bs-text-success: #0c7f49; /* 5.06:1 */
    --bs-text-warning: #9a6700; /* 4.87:1 — same as badge-light-warning */
    --bs-text-danger: #b02a37; /* 6.50:1 — same as badge-light-danger */
}

[data-bs-theme=dark] {
    --bs-text-muted: #9A9CAE;
    --bs-text-gray-400: #9A9CAE;
    --bs-text-gray-500: #9A9CAE;
    --bs-text-gray-600: #B5B7C8;
    --bs-input-solid-placeholder-color: #9A9CAE;
    /* Brand text on dark cards (#1B1C22). Defaults: primary 3.40, danger 3.83. */
    --bs-text-primary: #1B84FF; /* 4.69:1 */
    --bs-text-success: #00A261; /* 5.13:1 — Metronic dark success */
    --bs-text-warning: #C59A00; /* 6.47:1 — Metronic dark warning */
    --bs-text-danger: #FF3767; /* 4.85:1 — Metronic danger-active */
}

.text-muted,
.text-gray-400,
.text-gray-500 {
    color: var(--bs-text-muted) !important;
}

.text-gray-600 {
    color: var(--bs-text-gray-600) !important;
}

/* .text-* utilities use --bs-*-rgb (fills), not --bs-text-*. Force the AA text tokens. */
.text-primary {
    color: var(--bs-text-primary) !important;
}

.text-success {
    color: var(--bs-text-success) !important;
}

.text-warning {
    color: var(--bs-text-warning) !important;
}

.text-danger {
    color: var(--bs-text-danger) !important;
}

.form-control::placeholder,
.form-control-solid::placeholder,
.form-select::placeholder,
textarea::placeholder {
    color: var(--bs-text-muted) !important;
    opacity: 1;
}

/*
 * Dashboard stat cards: stock Metronic white-on-pink/green/yellow fails AA.
 *   #F1416C / white = 3.68:1; #50CD89 / white = 2.01:1; #FFC700 / white = 1.56:1
 * Darken fills so white (including labels, no opacity fade) is >= 4.5:1.
 *   danger  #C01048 = 6.16:1
 *   info    #7239EA = 6.02:1 (unchanged)
 *   success #157347 = 5.87:1
 *   warning #8A5A00 = 5.93:1
 */
.sh-stat-card,
.sh-stat-card .text-white {
    color: #fff !important;
}

.sh-stat-card-danger {
    background-color: #C01048;
}

.sh-stat-card-info {
    background-color: #7239EA;
}

.sh-stat-card-success {
    background-color: #157347;
}

.sh-stat-card-warning {
    background-color: #8A5A00;
}

/* Badge contrast improvements */
.badge.badge-light-primary {
    background-color: #E1F0FF;
    color: #0062cc; /* Higher contrast */
}

.badge.badge-light-success {
    background-color: #E8FFF3;
    color: #0d8a50; /* Higher contrast */
}

.badge.badge-light-warning {
    background-color: #FFF8DD;
    color: #9a6700; /* Higher contrast */
}

.badge.badge-light-danger {
    background-color: #FFF5F8;
    color: #b02a37; /* Higher contrast */
}

/* ============================================================
   LOADING STATE ACCESSIBILITY
   ============================================================ */
.spinner-border,
.spinner-grow {
    /* Provide text alternative */
}

.spinner-border::after {
    content: "";
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

/* ============================================================
   MODAL ACCESSIBILITY
   ============================================================ */
.modal {
    /* Ensure modal is properly announced */
}

.modal-dialog {
    /* Center content for screen magnifier users */
    margin: 1.75rem auto;
}

/* ============================================================
   NOTIFICATION ACCESSIBILITY
   ============================================================ */
.alert {
    /* Ensure alerts have proper role */
}

.alert[role="alert"] {
    /* Assertive alerts */
}

.alert[role="status"] {
    /* Polite notifications */
}


/* ============================================================
   MOBILE LAYOUT (390px phones — Metronic xs <576px)
   Keep setup, shifts, and /time usable: overflow, wrap, stack.
   ============================================================ */
@media (max-width: 575.98px) {
    .form-control,
    .form-select,
    input[type="datetime-local"],
    input[type="date"],
    input[type="time"],
    textarea {
        max-width: 100%;
    }

    /* Company signup + onboarding wizard */
    .sh-setup-wizard,
    #kt_onboarding_wizard,
    #kt_create_account_stepper {
        max-width: 100%;
        overflow-x: hidden;
    }

    .sh-setup-wizard .p-10,
    #kt_onboarding_wizard .p-10,
    #kt_create_account_stepper .p-10 {
        padding: 1.25rem !important;
    }

    .sh-setup-footer-links {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 0.5rem;
    }

    .sh-setup-footer-links a {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .sh-setup-actions {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .sh-setup-actions > div {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .sh-setup-actions .btn {
        width: 100%;
        min-height: 44px;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .sh-setup-wizard .notice,
    #kt_onboarding_wizard .notice,
    #kt_create_account_stepper .notice {
        flex-wrap: wrap;
    }

    .sh-setup-wizard .notice .flex-stack,
    #kt_onboarding_wizard .notice .flex-stack {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .sh-setup-wizard .notice .btn,
    #kt_onboarding_wizard .notice .btn {
        width: 100%;
        min-height: 44px;
    }

    /* /time clock */
    .sh-time-clock #currentTime,
    .sh-time-clock .display-1 {
        font-size: 2.5rem !important;
        line-height: 1.2;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .sh-time-clock #currentDate {
        font-size: 1rem !important;
        overflow-wrap: anywhere;
    }

    .sh-time-clock-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem !important;
    }

    .sh-time-clock-actions form,
    .sh-time-clock-actions .btn {
        width: 100%;
    }

    .sh-time-clock-actions .btn {
        min-height: 44px;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Shifts list / data tables */
    .sh-table-scroll,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .card:has(.sh-table-scroll) .card-header,
    .card:has(#kt_shifts_table) .card-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .card:has(.sh-table-scroll) .form-control.w-250px,
    .card:has(#kt_shifts_table) .form-control.w-250px {
        width: 100% !important;
        max-width: 100%;
    }

    #kt_app_toolbar_container {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
}
