/**
 * Research Report Modal — CSS
 * Prefix: rrm-
 */

/* ========================================================================
   Modal Overlay
   ======================================================================== */

.rrm-overlay {
    position: fixed;
    inset: 0;
    left: var(--sidebar-width, 60px);
    z-index: 1100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 250ms ease-out;
}

.rrm-overlay.rrm-show {
    opacity: 1;
}

.rrm-overlay.rrm-closing {
    opacity: 0;
}

/* Sidebar expanded */
body:has(.collapsible-sidebar.expanded) .rrm-overlay {
    left: var(--sidebar-expanded, 280px);
}

/* ========================================================================
   Content Container
   ======================================================================== */

.rrm-container {
    max-width: 960px;
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    background: var(--color-bg-page, #fff);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* ========================================================================
   Top Bar (sticky)
   ======================================================================== */

.rrm-topbar {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--color-bg-page, #fff);
    border-bottom: 1px solid var(--color-border-default, #e5e7eb);
}

.rrm-topbar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary, #111);
}

.rrm-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid var(--color-border-default, #e5e7eb);
    border-radius: 6px;
    color: var(--color-text-secondary, #666);
    font-size: 16px;
    cursor: pointer;
    transition: all 150ms;
}

.rrm-close-btn:hover {
    background: var(--color-bg-hover, #f3f4f6);
    color: var(--color-text-primary, #111);
    border-color: var(--color-text-tertiary, #999);
}

/* ========================================================================
   Body
   ======================================================================== */

.rrm-body {
    padding: 32px 32px 64px;
}

.rrm-loading,
.rrm-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--color-text-tertiary, #999);
    font-size: 14px;
}

.rrm-error {
    color: var(--color-danger, #ef4444);
}

/* ========================================================================
   Report Article — Academic Typography
   ======================================================================== */

.rrm-report {
    max-width: 100%;
    color: var(--color-text-primary, #111);
}

/* Header section */
.rrm-header-section {
    text-align: center;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--color-border-default, #e5e7eb);
    margin-bottom: 24px;
}

.rrm-report h1 {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--color-text-primary, #111);
    margin: 0 0 8px;
}

.rrm-subtitle {
    font-size: 15px;
    color: var(--color-text-secondary, #555);
    margin: 0 0 4px;
}

.rrm-date {
    font-size: 13px;
    color: var(--color-text-tertiary, #999);
    margin: 0 0 20px;
}

/* KPI Grid */
.rrm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.rrm-kpi-card {
    background: var(--color-bg-secondary, #f9fafb);
    border: 1px solid var(--color-border-default, #e5e7eb);
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
}

.rrm-kpi-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--color-accent, #f97316);
    line-height: 1.3;
}

.rrm-kpi-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-tertiary, #999);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Table of Contents */
.rrm-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    padding: 16px;
    background: var(--color-bg-secondary, #f9fafb);
    border-radius: 8px;
    margin-bottom: 32px;
    font-size: 13px;
    line-height: 1.8;
}

.rrm-toc strong {
    width: 100%;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary, #999);
    margin-bottom: 4px;
}

.rrm-toc a {
    color: var(--color-text-secondary, #555);
    text-decoration: none;
    transition: color 150ms;
}

.rrm-toc a:hover {
    color: var(--color-accent, #f97316);
}

/* Section headings */
.rrm-report h2 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--color-text-primary, #111);
    margin: 40px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border-default, #e5e7eb);
}

.rrm-report h3 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-text-primary, #111);
    margin: 24px 0 12px;
}

/* Paragraphs */
.rrm-report p {
    font-size: 15px;
    line-height: 1.75;
    color: var(--color-text-secondary, #555);
    margin: 0 0 12px;
}

/* Lists */
.rrm-report ul,
.rrm-report ol {
    font-size: 15px;
    line-height: 1.75;
    color: var(--color-text-secondary, #555);
    margin: 0 0 12px;
    padding-left: 24px;
}

.rrm-report li {
    margin-bottom: 4px;
}

/* Code */
.rrm-report code {
    font-family: var(--font-mono, 'SF Mono', monospace);
    font-size: 13px;
    background: var(--color-bg-tertiary, #f3f4f6);
    padding: 1px 5px;
    border-radius: 3px;
}

/* Strong */
.rrm-report strong {
    font-weight: 600;
    color: var(--color-text-primary, #111);
}

/* ========================================================================
   Tables
   ======================================================================== */

.rrm-table-wrap {
    overflow-x: auto;
    margin: 12px 0 16px;
    border-radius: 8px;
    border: 1px solid var(--color-border-default, #e5e7eb);
}

.rrm-report table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.5;
}

.rrm-report th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-secondary, #555);
    background: var(--color-bg-tertiary, #f3f4f6);
    padding: 8px 12px;
    white-space: nowrap;
    border-bottom: 2px solid var(--color-border-default, #e5e7eb);
}

.rrm-report td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--color-border-subtle, #f0f0f0);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary, #555);
}

.rrm-report tbody tr:nth-child(even) {
    background: var(--color-bg-inset, #fafafa);
}

/* Positive / Negative value colors */
.rrm-pos { color: var(--color-success, #22c55e); }
.rrm-neg { color: var(--color-danger, #ef4444); }

/* ========================================================================
   Highlight Box
   ======================================================================== */

.rrm-highlight {
    border-left: 3px solid var(--color-accent, #f97316);
    background: var(--color-accent-muted, rgba(249, 115, 22, 0.06));
    padding: 16px 20px;
    border-radius: 0 8px 8px 0;
    margin: 16px 0;
}

.rrm-highlight p {
    margin-bottom: 6px;
}

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

/* ========================================================================
   CSS Bar Chart (weight comparison)
   ======================================================================== */

.rrm-bar-chart {
    margin: 16px 0;
}

.rrm-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.rrm-bar-label {
    width: 100px;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary, #555);
    text-align: right;
    flex-shrink: 0;
}

.rrm-bar-track {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rrm-bar-fill {
    height: 18px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    min-width: 2px;
    transition: width 600ms ease-out;
}

.rrm-bar-fill span {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.rrm-bar-v1 {
    background: var(--color-text-tertiary, #999);
}

.rrm-bar-v2 {
    background: var(--color-accent, #f97316);
}

.rrm-bar-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 12px;
    font-size: 12px;
    color: var(--color-text-secondary, #555);
}

.rrm-bar-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 4px;
}

.rrm-bar-swatch.rrm-bar-v1 { background: var(--color-text-tertiary, #999); }
.rrm-bar-swatch.rrm-bar-v2 { background: var(--color-accent, #f97316); }

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

.rrm-footer {
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-default, #e5e7eb);
    text-align: center;
}

.rrm-footer p {
    font-size: 12px;
    color: var(--color-text-tertiary, #999);
    margin: 0 0 4px;
}

/* ========================================================================
   Dark Mode
   ======================================================================== */

[data-theme="dark"] .rrm-container,
.dark-mode .rrm-container {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .rrm-kpi-card,
.dark-mode .rrm-kpi-card {
    background: var(--color-bg-tertiary, #1f2937);
}

[data-theme="dark"] .rrm-toc,
.dark-mode .rrm-toc {
    background: var(--color-bg-tertiary, #1f2937);
}

[data-theme="dark"] .rrm-report tbody tr:nth-child(even),
.dark-mode .rrm-report tbody tr:nth-child(even) {
    background: var(--color-bg-tertiary, #1f2937);
}

[data-theme="dark"] .rrm-bar-fill span,
.dark-mode .rrm-bar-fill span {
    color: #fff;
}

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

@media (max-width: 768px) {
    .rrm-overlay {
        left: 0;
    }

    body:has(.collapsible-sidebar.expanded) .rrm-overlay {
        left: 0;
    }

    .rrm-body {
        padding: 20px 16px 48px;
    }

    .rrm-report h1 {
        font-size: 20px;
    }

    .rrm-report h2 {
        font-size: 18px;
    }

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

    .rrm-bar-label {
        width: 72px;
        font-size: 11px;
    }
}
