/* ============================================================
   Sutton Reports — Professional Stylesheet
   Design: Institutional data product. Inter font. White background,
   dark navy accents. Color-as-signal. Dense data, spacious layout.
   ============================================================ */

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1e293b;
    background: #f8fafc;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- Focus States (keyboard accessibility) ----------------- */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
.sortable:focus-visible,
.collapsible-toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.app-nav .nav-links a:focus-visible {
    outline-color: #93c5fd;
    outline-offset: -2px;
}

.pagination button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

h1, h2, h3, h4 {
    letter-spacing: -0.02em;
}

/* --- Navigation -------------------------------------------- */
.app-nav {
    background: #0f172a;
    color: #fff;
    padding: 0 32px;
    display: flex;
    align-items: center;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #1e293b;
}

.app-nav .nav-brand {
    font-weight: 700;
    font-size: 0.8rem;
    margin-right: 40px;
    white-space: nowrap;
    color: #fff;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.app-nav .nav-brand:hover {
    text-decoration: none;
}

.app-nav .nav-links {
    display: flex;
    gap: 0;
    list-style: none;
    height: 100%;
}

.app-nav .nav-links li {
    display: flex;
    align-items: center;
    height: 100%;
}

.app-nav .nav-links a {
    color: #94a3b8;
    text-decoration: none;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    letter-spacing: 0.01em;
}

.app-nav .nav-links a:hover {
    color: #e2e8f0;
    text-decoration: none;
}

.app-nav .nav-links a.active {
    color: #fff;
    border-bottom-color: #3b82f6;
}

/* --- Layout ------------------------------------------------ */
.app-container {
    max-width: 1360px;
    margin: 0 auto;
    padding: 28px 32px;
}

/* --- Page Header ------------------------------------------- */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 2px;
}

.page-header .subtitle {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 400;
}

/* --- Stat Cards -------------------------------------------- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: border-color 0.15s;
}

.stat-card:hover {
    border-color: #cbd5e1;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    color: #0f172a;
    font-variant-numeric: tabular-nums;
}

.stat-card .label {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- Data Tables ------------------------------------------- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 24px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    cursor: default;
    user-select: none;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table th.sortable {
    cursor: pointer;
}

.data-table th.sortable:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.data-table th.sorted-asc::after {
    content: " \25B2";
    font-size: 0.6rem;
    color: #3b82f6;
}

.data-table th.sorted-desc::after {
    content: " \25BC";
    font-size: 0.6rem;
    color: #3b82f6;
}

.data-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: #334155;
}

.data-table tbody tr {
    transition: background 0.1s;
}

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

.data-table .clickable-row {
    cursor: pointer;
}

.data-table .clickable-row:hover {
    background: #eff6ff;
}

.data-table .text-right {
    text-align: right;
}

.data-table .text-center {
    text-align: center;
}

.data-table .no-results {
    text-align: center;
    padding: 32px;
    color: #94a3b8;
    font-style: italic;
}

/* --- Star Ratings ------------------------------------------ */
.star-1, .star-2, .star-3, .star-4, .star-5, .star-null {
    display: inline-block;
    min-width: 24px;
    text-align: center;
    border-radius: 3px;
    font-weight: 700;
    font-size: 0.75rem;
    padding: 2px 5px;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.star-1 {
    background: #b91c1c;
    color: #fff;
}

.star-2 {
    background: #ea580c;
    color: #fff;
}

.star-3 {
    background: #ca8a04;
    color: #fff;
}

.star-4 {
    background: #16a34a;
    color: #fff;
}

.star-5 {
    background: #15803d;
    color: #fff;
}

.star-null {
    background: #f1f5f9;
    color: #94a3b8;
}

/* --- Change Direction Badges ------------------------------- */
.badge-improved {
    display: inline-block;
    background: #dcfce7;
    color: #15803d;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
}

.badge-declined {
    display: inline-block;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
}

/* --- Data Badges ------------------------------------------- */
.data-badge-full {
    display: inline-block;
    border: 1px solid #15803d;
    color: #15803d;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 3px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-badge-limited {
    display: inline-block;
    border: 1px solid #b45309;
    color: #b45309;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 3px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --- Charts ------------------------------------------------ */
.charts-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.chart-container {
    flex: 1;
    min-width: 280px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 16px 20px;
}

.chart-container h3 {
    font-size: 0.7rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- Filter Bar -------------------------------------------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 12px;
    align-items: center;
}

.filter-bar label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-bar input,
.filter-bar select {
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 7px 10px;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    color: #1e293b;
    background: #fff;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-bar input:focus,
.filter-bar select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.filter-bar input::placeholder {
    color: #94a3b8;
}

/* --- Pagination -------------------------------------------- */
.pagination {
    display: flex;
    justify-content: center;
    gap: 3px;
    padding: 16px 0;
}

.pagination button {
    min-width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: #fff;
    color: #475569;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s;
}

.pagination button:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.pagination button.active {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}

.pagination button:disabled {
    opacity: 0.35;
    cursor: default;
}

/* --- Loading & Errors -------------------------------------- */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 48px 0;
}

.loading-spinner::after {
    content: "";
    width: 28px;
    height: 28px;
    border: 2.5px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    border: 1px solid #fca5a5;
    background: #fef2f2;
    color: #b91c1c;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.8rem;
    margin-bottom: 16px;
}

/* --- Collapsible Sections ---------------------------------- */
.collapsible-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 0;
    user-select: none;
    font-weight: 600;
    font-size: 0.85rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.collapsible-header::before {
    content: "\25B6";
    font-size: 0.55rem;
    transition: transform 0.2s;
    color: #94a3b8;
}

.collapsible-header.open::before {
    transform: rotate(90deg);
}

.collapsible-content {
    display: none;
    padding-bottom: 16px;
}

.collapsible-content.open {
    display: block;
}

/* --- Buttons ----------------------------------------------- */
.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #0f172a;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    letter-spacing: 0.01em;
}

.download-btn:hover {
    background: #1e293b;
    text-decoration: none;
    color: #fff;
}

.download-btn::before {
    content: "\2913";
    font-size: 0.95rem;
}

.downloads-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
}

/* --- Metric Cards (Operator Detail) ----------------------- */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 24px;
}

.metric-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px 14px;
}

.metric-card .metric-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.metric-card .metric-label {
    font-size: 0.65rem;
    color: #64748b;
    font-weight: 600;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Back Link --------------------------------------------- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 12px;
    font-weight: 500;
}

.back-link:hover {
    color: #3b82f6;
    text-decoration: none;
}

/* --- Change Colors (inline) -------------------------------- */
.change-positive {
    color: #15803d;
    font-weight: 600;
}

.change-negative {
    color: #b91c1c;
    font-weight: 600;
}

.change-neutral {
    color: #64748b;
}

/* --- Section Headings -------------------------------------- */
.section-heading {
    font-size: 0.85rem;
    font-weight: 700;
    color: #0f172a;
    margin: 28px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Quick Nav Links --------------------------------------- */
.quick-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.quick-nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #1e293b;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.quick-nav a:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.08);
    text-decoration: none;
}

.quick-nav a::after {
    content: "\2192";
    color: #94a3b8;
}

/* --- Narrative Summary ------------------------------------- */
.narrative-summary {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #0f172a;
    padding: 18px 22px;
    margin-bottom: 20px;
    border-radius: 0 6px 6px 0;
    line-height: 1.65;
    color: #334155;
    font-size: 0.87rem;
}

.narrative-summary p {
    margin: 0;
}

/* --- Empty State ------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #94a3b8;
    font-size: 0.85rem;
}

/* --- Print Chart Images ------------------------------------ */
.print-chart-img {
    display: none !important;
}

/* --- Metric Card Context ---------------------------------- */
.metric-card .metric-context {
    font-size: 0.6rem;
    color: #94a3b8;
    margin-top: 4px;
    line-height: 1.35;
    font-weight: 400;
}

/* --- Divergence Indicator --------------------------------- */
.divergence-low {
    color: #15803d;
    font-weight: 600;
}

.divergence-med {
    color: #b45309;
    font-weight: 600;
}

.divergence-high {
    color: #b91c1c;
    font-weight: 600;
}

.divergence-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.divergence-dot.dot-low { background: #15803d; }
.divergence-dot.dot-med { background: #b45309; }
.divergence-dot.dot-high { background: #b91c1c; }

/* --- Methodology Section ---------------------------------- */
.methodology-section {
    margin-top: 32px;
    border-top: 1px solid #e2e8f0;
    padding-top: 16px;
}

.methodology-section .collapsible-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 0;
    font-weight: 600;
    font-size: 0.85rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: none;
    border: none;
    font-family: 'Inter', sans-serif;
}

.methodology-content {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 20px 24px;
    margin-top: 8px;
    font-size: 0.82rem;
    color: #334155;
    line-height: 1.7;
}

.methodology-content h4 {
    font-size: 0.75rem;
    font-weight: 700;
    color: #0f172a;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 18px 0 6px;
}

.methodology-content h4:first-child {
    margin-top: 0;
}

.methodology-content p {
    margin: 0 0 10px;
}

.methodology-content dl {
    margin: 0 0 12px;
}

.methodology-content dt {
    font-weight: 600;
    color: #0f172a;
    margin-top: 6px;
}

.methodology-content dd {
    margin-left: 16px;
    color: #475569;
}

/* --- Site Footer ------------------------------------------ */
.site-footer {
    max-width: 1360px;
    margin: 0 auto;
    padding: 24px 32px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.65rem;
    color: #94a3b8;
    line-height: 1.6;
    text-align: center;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .metric-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .app-nav {
        padding: 0 16px;
    }

    .app-nav .nav-brand {
        margin-right: 16px;
    }

    .app-nav .nav-links a {
        padding: 0 12px;
        font-size: 0.75rem;
    }

    .app-container {
        padding: 16px;
    }

    .stat-cards {
        grid-template-columns: 1fr;
    }

    .metric-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        flex-direction: column;
    }

    .chart-container {
        min-width: 100%;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header h1 {
        font-size: 1.2rem;
    }

    .downloads-row {
        flex-direction: column;
    }

    .download-btn {
        justify-content: center;
    }
}

/* ============================================================
   PRINT STYLESHEET — Operator Report
   ============================================================ */
@media print {
    body {
        background: #fff;
        color: #000;
        font-size: 9.5pt;
        line-height: 1.35;
    }

    /* Hide non-report elements */
    .app-nav,
    .filter-bar,
    .pagination,
    .download-btn,
    .downloads-row,
    .quick-nav,
    .back-link,
    #print-btn,
    #corporate-entities,
    #subsidiaries,
    .collapsible-header,
    .collapsible-content,
    .methodology-section,
    .site-footer {
        display: none !important;
    }

    .app-container {
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    /* Report header with watermark */
    #profile-header {
        border-bottom: 2px solid #0f172a;
        padding-bottom: 6px;
        margin-bottom: 10px;
    }

    #profile-header::before {
        content: "SUTTON REPORTS — Operator Quality Profile";
        display: block;
        font-size: 7pt;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        color: #64748b;
        margin-bottom: 4px;
    }

    #profile-header h1 {
        font-size: 15pt;
        color: #0f172a;
    }

    /* Narrative — prominent in print */
    .narrative-summary {
        background: none;
        border-left: 2px solid #0f172a;
        padding: 6px 14px;
        margin-bottom: 12px;
        font-size: 9pt;
        color: #000;
        line-height: 1.45;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Metric cards — compact row */
    .metric-cards {
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 4px !important;
        margin-bottom: 10px;
    }

    .stat-card, .metric-cards > div, .metric-card {
        border: 1px solid #ccc;
        padding: 4px 6px !important;
    }

    .stat-card .value, .metric-cards .value, .metric-card .metric-value {
        font-size: 11pt;
    }

    .stat-card .label, .metric-cards .label, .metric-card .metric-label {
        font-size: 6.5pt;
    }

    /* Charts — show static images, hide canvases */
    .chart-container canvas {
        display: none !important;
    }

    .print-chart-img {
        display: block !important;
        width: 100% !important;
        max-height: 180px;
        object-fit: contain;
    }

    .charts-row {
        gap: 8px !important;
        margin-bottom: 10px;
    }

    .chart-container {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #ddd;
        padding: 6px !important;
    }

    .chart-container h3 {
        font-size: 7.5pt;
        margin-bottom: 3px;
    }

    /* Facility table — compact */
    #facility-section h2 {
        font-size: 11pt;
        margin-bottom: 4px;
    }

    .data-table {
        font-size: 7pt;
        border-collapse: collapse;
    }

    .data-table th {
        position: static;
        background: #f1f5f9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-size: 6.5pt;
        padding: 2px 3px;
    }

    .data-table td {
        padding: 2px 3px;
        border-bottom: 0.5px solid #e2e8f0;
    }

    .data-table tbody tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Ensure star rating colors print */
    .star-1, .star-2, .star-3, .star-4, .star-5, .star-null {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Page setup */
    @page {
        margin: 0.5in;
        size: letter;

        @bottom-center {
            content: "Source: Sutton Reports — suttonreports.com";
            font-size: 7pt;
            color: #94a3b8;
        }
    }

    #facility-section {
        page-break-before: auto;
    }
}
