/* ==========================================================================
   SimplyMerit Data Dictionary - Table Layout

   Browser Support:
   - Chrome 80+, Firefox 75+, Safari 13+, Edge 80+ (full support)
   - IE11: Not supported (uses CSS custom properties, sticky positioning)

   Features:
   - Responsive design (breakpoints: 1200px, 992px, 768px)
   - Accessibility: WCAG 2.1 AA compliant
   - Print styles included
   - High contrast mode support
   - Reduced motion support
   ========================================================================== */

/* ---------------------------
   1) Root theme & spacing
   --------------------------- */
:root {
    /* SimplyMerit Brand Colors */
    --sm-teal: #73bdce;
    --sm-teal-dark: #257996;
    --sm-navy: #273867;

    /* MorganHR Brand Colors */
    --mhr-green-dark: #0b6c37;
    --mhr-green-light: #8ac53f;
    --mhr-brown: #7d684a;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-900: #111827;

    --radius-sm: 6px;
    --radius-md: 8px;
    --focus: 0 0 0 3px rgba(115, 189, 206, 0.25);

    --row-even: #ffffff;
    --row-odd: #f3f7f9;
}

/* ---------------------------
   2) Base
   --------------------------- */
* {
    box-sizing: border-box;
}
html:focus-within {
    scroll-behavior: smooth;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--gray-900);
    background: var(--gray-50);
    margin: 0;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

:focus-visible {
    outline: 2px solid var(--sm-teal);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ---------------------------
   3) Skip link & noscript
   --------------------------- */
.skip-link {
    position: absolute;
    left: -9999px;
    top: -9999px;
    background: var(--sm-teal-dark);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus,
.skip-link:focus-visible {
    left: 1rem;
    top: 1rem;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.noscript-warning {
    background: #fef3c7;
    color: #92400e;
    padding: 0.375rem 0.625rem;
    text-align: center;
    font-size: 0.875rem;
    border-bottom: 1px solid #f59e0b;
}

/* ---------------------------
   4) Header & search
   --------------------------- */
.site-header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 0;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.header-logo {
    height: auto;
    max-width: 200px;
    max-height: 50px;
}
.header-brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.search-hero {
    flex: 1;
    max-width: 400px;
    position: relative;
}
.search-hero input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: #fff;
}
.search-hero input:focus {
    outline: none;
    border-color: var(--sm-teal);
    box-shadow: var(--focus);
}
.search-hero .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 0.875rem;
}
.search-clear-btn {
    position: absolute;
    right: 4.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gray-200);
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    color: var(--gray-600);
}
.search-clear-btn.visible {
    display: flex;
}
.search-results-badge {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: var(--gray-600);
    font-weight: 600;
}

/* ---------------------------
   5) Layout
   --------------------------- */
.main-wrapper {
    max-width: 2200px;
    margin: 0.75rem auto;
    padding: 0 2rem;
    /* Ensure no overflow that would break sticky children */
    overflow: visible;
}

/* Main content area */
main#main-content {
    overflow: visible;
}

.sidebar {
    position: -webkit-sticky;
    position: sticky;
    top: 80px;
    height: fit-content;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: #fff;
    border-radius: var(--radius-md);
    padding: 0.75rem;
    border: 1px solid var(--gray-200);
    font-size: 0.8125rem;
}
.sidebar h3 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--sm-navy);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--sm-teal);
}

/* Search box at bottom of sidebar in pill */
.sidebar-search-wrap {
    margin-top: 0.5rem;
    padding-top: 0.375rem;
    border-top: 1px solid var(--gray-200);
}
.sidebar-search {
    position: relative;
    background: #fff;
    border-radius: 25px;
    border: 1px solid var(--gray-200);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}
.sidebar-search .search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 0.875rem;
    pointer-events: none;
}
.sidebar-search input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 2.5rem;
    border: none;
    border-radius: 25px;
    font-size: 0.875rem;
    background: transparent;
}
.sidebar-search input:focus {
    outline: none;
}
.sidebar-search input:focus + .search-icon {
    color: var(--sm-teal);
}
.sidebar-search .search-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gray-100);
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    transition:
        background 0.15s,
        color 0.15s;
}
.sidebar-search .search-clear-btn:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}
.sidebar-search .search-clear-btn.visible {
    display: flex;
}
.search-results-wrap {
    text-align: center;
    margin-top: 0.25rem;
    min-height: 0.875rem;
}
.search-results-badge {
    font-size: 0.75rem;
    color: var(--sm-teal-dark);
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.625rem 0.75rem;
    color: var(--gray-700);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}
.nav-link:hover {
    background: linear-gradient(90deg, rgba(115, 189, 206, 0.15), transparent);
    color: var(--sm-teal-dark);
    border-left-color: var(--sm-teal);
    transform: translateX(4px);
}
.nav-link i {
    width: 20px;
    margin-right: 0.5rem;
    font-size: 0.875rem;
    transition: transform 0.2s ease;
}
.nav-link:hover i {
    transform: scale(1.1);
}

/* ---------------------------
   6) Info banner & resources
   --------------------------- */
.info-banner {
    background: linear-gradient(
        135deg,
        var(--sm-teal-dark) 0%,
        var(--sm-teal) 50%,
        var(--sm-navy) 100%
    );
    color: #fff;
    padding: 1.25rem 1.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.875rem;
    box-shadow: 0 4px 20px rgba(39, 56, 103, 0.25);
}
.info-banner h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0 0 0.625rem;
    letter-spacing: -0.02em;
}
.info-banner p {
    font-size: 1rem;
    margin: 0 0 0.75rem;
    opacity: 0.95;
    line-height: 1.6;
}
.info-banner p:last-child {
    margin-bottom: 0;
}
.info-banner a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
}
.info-banner a:hover {
    text-decoration: none;
}

.resources-section {
    margin-bottom: 1.25rem;
}
.resources-title {
    font-size: 1.0625rem;
    font-weight: 700;
    margin-bottom: 0.875rem;
    text-align: center;
}
.resources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.875rem;
}
.resource-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    text-decoration: none;
    color: var(--gray-900);
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}
.resource-card:hover {
    border-color: var(--sm-teal);
    box-shadow: 0 2px 8px rgba(37, 121, 150, 0.1);
}
.resource-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--sm-teal-dark), var(--sm-teal));
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.resource-icon i {
    font-size: 1.125rem;
    color: #fff;
}
.resource-content h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
}
.resource-content p {
    font-size: 0.8125rem;
    color: var(--gray-600);
    margin: 0;
}
.resource-arrow {
    color: var(--gray-400);
    font-size: 0.875rem;
    margin-left: auto;
}

/* ---------------------------
   7) Sections & tables
   --------------------------- */
.section {
    margin-bottom: 1.75rem;
    scroll-margin-top: 80px;
    /* Ensure no overflow that would break sticky children */
    overflow: visible;
}
.section-header {
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--sm-teal-dark), var(--sm-teal));
    color: #fff;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    position: -webkit-sticky;
    position: sticky;
    top: 70px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.section-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
}
.section-header i {
    font-size: 1.25rem;
}
.field-count {
    font-size: 0.8rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
}
.section-description {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
    background: #fff;
    padding: 0.25rem 0;
    position: -webkit-sticky;
    position: sticky;
    top: 107px;
    z-index: 95;
}

/* Subheaders for Dynamic Fields */
.subheader {
    color: var(--sm-teal-dark);
    font-size: 1rem;
    font-weight: 600;
    margin: 0.5rem 0 0.375rem 0;
    padding: 0.25rem 0 0.25rem 0.625rem;
    border-left: 4px solid var(--sm-teal);
    background: #fff;
    position: -webkit-sticky;
    position: sticky;
    top: 130px;
    z-index: 92;
}

/* Table styles */
.table-responsive {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: #fff;
    margin-bottom: 0.75rem;
    /* CRITICAL: overflow must be visible for sticky to work */
    overflow: visible;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
}

.data-table thead {
    position: -webkit-sticky;
    position: sticky;
    top: 130px;
    z-index: 90;
    background: #fff;
    box-shadow: 0 -20px 0 0 #fff;
}

/* When a subheader precedes the table, push thead down further */
.subheader + .table-responsive .data-table thead {
    top: 155px;
}

.data-table th {
    text-align: left;
    padding: 0.375rem 0.625rem;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--gray-700);
    border-bottom: 3px solid var(--sm-teal);
    white-space: nowrap;
    background: var(--gray-100);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table td {
    padding: 0.375rem 0.625rem;
    border-bottom: 2px solid var(--gray-200);
    vertical-align: top;
}

/* Zebra striping */
.data-table tbody tr:nth-child(odd) {
    background: var(--row-odd);
}
.data-table tbody tr:nth-child(even) {
    background: var(--row-even);
}

.data-table tbody tr:hover {
    background: #e8f4f8;
}

.data-table tbody tr.highlight {
    background: #d4eef4 !important;
}

/* Column widths - 4 columns now */
.col-name {
    width: 20%;
    min-width: 160px;
}
.col-legacy {
    width: 17%;
    min-width: 185px;
    white-space: nowrap;
}
.col-desc {
    width: 43%;
    min-width: 260px;
}
.col-values {
    width: 20%;
    min-width: 130px;
}

.field-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--sm-navy);
    display: block;
    letter-spacing: -0.01em;
}

.field-badge-wrap {
    margin-top: 0.25rem;
}

/* Legacy name with copy button outside */
.legacy-name-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}
.legacy-name {
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 0.8rem;
    background: #e8ecef;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: var(--sm-navy);
    display: inline-block;
    cursor: pointer;
    transition:
        background 0.15s,
        color 0.15s;
    border: 1px solid var(--gray-200);
}
.legacy-name:hover {
    background: #d1d9e0;
    color: var(--sm-teal-dark);
}
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition:
        opacity 0.15s,
        background 0.15s,
        color 0.15s;
    font-size: 0.75rem;
}
.legacy-name-wrap:hover .copy-btn {
    opacity: 1;
}
.copy-btn:hover {
    background: var(--gray-100);
    color: var(--sm-teal-dark);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge.required {
    background: #dcfce7;
    color: #166534;
}
.badge.optional {
    background: var(--gray-200);
    color: var(--gray-700);
}
.badge.system {
    background: #dbeafe;
    color: #1e40af;
}
.badge.insights {
    background: #fef3c7;
    color: #92400e;
}

/* Notes inside table cells */
.field-note {
    margin-top: 0.375rem;
    padding: 0.3rem 0.5rem;
    background: #fffbeb;
    border-left: 2px solid #f59e0b;
    border-radius: 3px;
    font-size: 0.8rem;
    color: #92400e;
}
.field-note i {
    color: #f59e0b;
    margin-right: 0.25rem;
    font-size: 0.7rem;
}
.field-note a {
    color: #92400e;
    text-decoration: underline;
}

/* Example values */
.example-value {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--gray-600);
    font-style: italic;
}

/* ---------------------------
   8) Footer & misc
   --------------------------- */
.footer {
    background: #fff;
    border-top: 1px solid var(--gray-200);
    padding: 0.875rem 0;
    margin-top: 1.25rem;
}
.footer-text {
    color: var(--gray-600);
    font-size: 0.75rem;
    margin: 0;
}
.footer a {
    color: var(--sm-teal-dark);
}

/* ---------------------------
   9) Responsive
   --------------------------- */
@media (max-width: 1200px) {
    .main-wrapper {
        padding: 0 1rem;
    }
    /* Don't use overflow-x on table-responsive - it breaks sticky */
    /* Instead, let the table scroll within body if needed */
}

@media (max-width: 992px) {
    .sidebar {
        position: static;
        margin-bottom: 1rem;
        max-height: none;
        overflow-y: visible;
    }
    .site-header .container {
        flex-direction: column;
        gap: 0.75rem;
    }
    .search-hero {
        max-width: 100%;
    }
    /* When sidebar is static, section headers stick to top of viewport */
    .section-header {
        position: -webkit-sticky;
        position: sticky;
        top: 70px;
        z-index: 100;
    }
    .section-description {
        top: 107px;
    }
    .subheader {
        top: 130px;
    }
    .data-table thead {
        position: -webkit-sticky;
        position: sticky;
        top: 130px;
        z-index: 90;
    }
    .subheader + .table-responsive .data-table thead {
        top: 155px;
    }
}

@media (max-width: 768px) {
    .header-logo {
        max-width: 160px;
    }
    .header-brand h1 {
        font-size: 1rem;
    }
    .resources-grid {
        grid-template-columns: 1fr;
    }
    .section-header {
        top: 55px;
        padding: 0.375rem 0.625rem;
    }
    .section-header h2 {
        font-size: 1.1rem;
    }
    .section-description {
        position: static;
    }
    .subheader {
        position: static;
    }

    /* Stack table cells on mobile */
    .data-table thead {
        display: none;
    }
    .data-table tbody tr {
        display: block;
        padding: 0.75rem;
        border-bottom: 2px solid var(--gray-200);
    }
    .data-table td {
        display: block;
        padding: 0.25rem 0;
        border: none;
    }
    .data-table td.col-name {
        font-size: 0.9375rem;
        padding-bottom: 0.375rem;
    }
    .data-table td.col-legacy {
        font-size: 0.75rem;
        color: var(--gray-600);
    }
    .data-table td.col-desc {
        padding-top: 0.5rem;
    }
    .data-table td.col-values:not(:empty) {
        padding-top: 0.375rem;
        font-size: 0.8rem;
        color: var(--gray-600);
    }
    .data-table td.col-values .example-value {
        margin-top: 0.125rem;
    }
    .col-name,
    .col-legacy,
    .col-desc,
    .col-values {
        width: 100%;
        min-width: 0;
    }
    .subheader {
        font-size: 1rem;
        margin-top: 1rem;
    }
}

/* ---------------------------
   10) Print
   --------------------------- */
@media print {
    .site-header,
    .sidebar,
    .return-top-btn {
        position: static !important;
    }
    .search-hero,
    .return-top-btn,
    .resources-section,
    .noscript-warning {
        display: none !important;
    }
    .data-table {
        font-size: 9pt;
    }
    .data-table th,
    .data-table td {
        padding: 0.25rem 0.375rem;
    }
    .main-wrapper {
        max-width: 100%;
        padding: 0;
    }
    .section-header {
        background: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    a[href]::after {
        content: none;
    }
    .badge {
        border: 1px solid currentColor;
    }
}

/* ---------------------------
   11) High contrast / forced colors
   --------------------------- */
@media (forced-colors: active) {
    .skip-link,
    .return-top-btn,
    .badge,
    .resource-card,
    .data-table th,
    .data-table td {
        border: 1px solid CanvasText;
    }
    .section-header,
    .info-banner {
        border: 2px solid CanvasText;
    }
    .field-note {
        border: 1px solid CanvasText;
        border-left-width: 3px;
    }
}

/* ---------------------------
   12) Vendor prefixes for older browsers
   --------------------------- */
.site-header {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

@supports not (
    (-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))
) {
    .site-header {
        background: rgba(255, 255, 255, 0.98);
    }
}

/* Repeat notes for fields that repeat */
.repeat-note {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 0.625rem 0.875rem;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--gray-600);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.repeat-note i {
    color: var(--sm-teal-dark);
    font-size: 0.875rem;
}

/* Return to Top button */
.return-top-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.75rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--sm-teal-dark);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: all 0.15s ease;
}
.return-top-btn:hover {
    background: var(--sm-teal);
    color: white;
    border-color: var(--sm-teal);
}
.return-top-btn:focus {
    outline: none;
    box-shadow: var(--focus);
}
.return-top-btn i {
    font-size: 0.6875rem;
}
