/* ============================================================================
   Texas Court of Appeals — D3 Edition
   Design: Editorial civic. Inspired by NYT, ProPublica, The Marshall Project.
   ============================================================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Typography */
    --font-headline: 'Source Serif 4', Georgia, serif;
    --font-body: 'Inter', -apple-system, system-ui, sans-serif;
    --font-data: 'IBM Plex Mono', monospace;
    
    /* Colors — muted, editorial */
    --ink: #1a1a1a;
    --ink-secondary: #4a4a4a;
    --ink-tertiary: #767676;
    --ink-faint: #999999;
    
    --surface: #ffffff;
    --surface-alt: #f7f7f5;
    --rule: #e0e0e0;
    --rule-light: #eeeeee;
    
    /* Status — desaturated for trust */
    --healthy: #2a7d4f;
    --healthy-light: #d4edda;
    --stressed: #b8860b;
    --stressed-light: #fff3cd;
    --critical: #a94442;
    --critical-light: #f8d7da;
    
    /* Chart colors */
    --chart-positive: #2a7d4f;
    --chart-negative: #a94442;
    --chart-neutral: #767676;
    --chart-bar: #4a7c9b;
    --chart-bar-hover: #2d5a73;
    
    /* Layout */
    --max-width: 900px;
    --gutter: 24px;
}

html {
    font-size: 17px;
    line-height: 1.6;
}

body {
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

/* ============================================================================
   Header — Editorial style
   ============================================================================ */

.header {
    padding: 48px 0 32px;
    border-bottom: 1px solid var(--rule);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
}

.header h1 {
    font-family: var(--font-headline);
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.deck {
    font-size: 1.1rem;
    color: var(--ink-secondary);
    max-width: 540px;
}

.header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============================================================================
   Lede — Opening text
   ============================================================================ */

.lede {
    padding: 32px 0;
    border-bottom: 1px solid var(--rule-light);
}

.lede p {
    font-size: 1.05rem;
    color: var(--ink-secondary);
    margin-bottom: 12px;
    max-width: 680px;
}

.lede p:last-child {
    margin-bottom: 0;
}

/* ============================================================================
   Metrics Strip
   ============================================================================ */

.metrics-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    padding: 28px 0;
    border-bottom: 1px solid var(--rule);
}

.metric {
    text-align: center;
}

.metric-value {
    display: block;
    font-family: var(--font-data);
    font-size: 2rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.2;
}

.metric-label {
    display: block;
    font-size: 0.75rem;
    color: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 4px;
}

@media (max-width: 600px) {
    .metrics-strip {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* ============================================================================
   Visualization Sections
   ============================================================================ */

.viz-section {
    padding: 40px 0;
    border-bottom: 1px solid var(--rule-light);
}

.viz-section h2 {
    font-family: var(--font-headline);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.viz-description {
    font-size: 0.9rem;
    color: var(--ink-tertiary);
    margin-bottom: 24px;
    max-width: 600px;
}

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

.chart-small {
    min-height: 200px;
    max-width: 400px;
}

/* D3 Chart Styles */
.chart-container svg {
    display: block;
    overflow: visible;
}

.axis text {
    font-family: var(--font-body);
    font-size: 11px;
    fill: var(--ink-tertiary);
}

.axis path,
.axis line {
    stroke: var(--rule);
}

.axis-label {
    font-family: var(--font-body);
    font-size: 11px;
    fill: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bar {
    fill: var(--chart-bar);
    cursor: pointer;
    transition: fill 0.15s ease;
}

.bar:hover {
    fill: var(--chart-bar-hover);
}

.bar.positive {
    fill: var(--chart-positive);
}

.bar.negative {
    fill: var(--chart-negative);
}

.reference-line {
    stroke: var(--ink);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
}

.reference-label {
    font-family: var(--font-data);
    font-size: 10px;
    fill: var(--ink-secondary);
}

.dot {
    cursor: pointer;
    transition: r 0.15s ease;
}

.dot:hover {
    r: 8;
}

.court-label {
    font-family: var(--font-body);
    font-size: 11px;
    fill: var(--ink-secondary);
}

.tooltip {
    position: absolute;
    background: var(--ink);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.tooltip strong {
    display: block;
    margin-bottom: 4px;
}

/* ============================================================================
   Data Table
   ============================================================================ */

.table-section {
    padding: 40px 0;
}

.table-section h2 {
    font-family: var(--font-headline);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.table-wrapper {
    overflow-x: auto;
    margin-top: 16px;
}

#data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--ink);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

#data-table th.numeric {
    text-align: right;
}

#data-table th:hover {
    color: var(--ink);
}

#data-table th.sorted {
    color: var(--ink);
}

#data-table th.sorted::after {
    content: ' ↓';
}

#data-table th.sorted.asc::after {
    content: ' ↑';
}

#data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--rule-light);
    vertical-align: middle;
}

#data-table td.numeric {
    text-align: right;
    font-family: var(--font-data);
    font-size: 0.85rem;
}

#data-table tbody tr {
    cursor: pointer;
    transition: background 0.1s ease;
}

#data-table tbody tr:hover {
    background: var(--surface-alt);
}

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

.court-name {
    font-weight: 600;
}

.court-location {
    font-size: 0.8rem;
    color: var(--ink-tertiary);
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.healthy { background: var(--healthy); }
.status-dot.stressed { background: var(--stressed); }
.status-dot.critical { background: var(--critical); }

.trend-positive { color: var(--healthy); }
.trend-negative { color: var(--critical); }

/* ============================================================================
   Detail Panel
   ============================================================================ */

.detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 2px solid var(--ink);
    padding: 24px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 50;
    transition: transform 0.25s ease;
}

.detail-panel.hidden {
    transform: translateY(100%);
}

.detail-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--ink-tertiary);
    cursor: pointer;
    line-height: 1;
}

.detail-close:hover {
    color: var(--ink);
}

.detail-panel h3 {
    font-family: var(--font-headline);
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.detail-location {
    color: var(--ink-tertiary);
    margin-bottom: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-item-label {
    font-size: 0.7rem;
    color: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-item-value {
    font-family: var(--font-data);
    font-size: 1.2rem;
    font-weight: 600;
}

.detail-counties {
    font-size: 0.85rem;
    color: var(--ink-secondary);
    line-height: 1.6;
}

/* ============================================================================
   Methodology
   ============================================================================ */

.methodology {
    padding: 40px 0;
    background: var(--surface-alt);
    margin: 40px calc(-1 * var(--gutter));
    padding-left: var(--gutter);
    padding-right: var(--gutter);
}

.methodology h2 {
    font-family: var(--font-headline);
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.methodology dl {
    max-width: 600px;
}

.methodology dt {
    font-weight: 600;
    margin-top: 12px;
}

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

.methodology dd {
    color: var(--ink-secondary);
    font-size: 0.9rem;
}

.methodology-note {
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--ink-tertiary);
}

.methodology-note a {
    color: var(--ink-secondary);
}

/* ============================================================================
   Footer
   ============================================================================ */

.footer {
    padding: 32px 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--ink-tertiary);
}

.footer a {
    color: var(--ink-secondary);
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 700px) {
    html { font-size: 16px; }
    
    .header h1 { font-size: 1.8rem; }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-meta {
        align-items: flex-start;
        flex-direction: row;
        gap: 16px;
    }
    
    .chart-container {
        min-height: 300px;
    }
}
