/* Phase 1 / Sprint 08 — Reports & Export Experience */

:root {
    --s8-ink: #10233f;
    --s8-muted: #607089;
    --s8-line: #d8e1ec;
    --s8-surface: #ffffff;
    --s8-soft: #f5f8fc;
    --s8-blue: #1f5f99;
    --s8-teal: #16805b;
    --s8-amber: #b66c06;
    --s8-danger: #b42318;
    --s8-shadow: 0 14px 34px rgba(16, 35, 63, .09);
}

[data-s8-report] {
    color: var(--s8-ink);
}

[data-s8-report] main {
    container-type: inline-size;
}

.s8-report-context,
.s8-report-toolbar,
.s8-table-tools,
.s8-table-footer,
.s8-filter-heading {
    font-family: Inter, Cairo, "Segoe UI", Arial, sans-serif;
}

.s8-report-context {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 1rem;
    padding: .75rem 1rem;
    border: 1px solid var(--s8-line);
    border-radius: 10px;
    color: var(--s8-muted);
    background: linear-gradient(135deg, rgba(255,255,255,.98), rgba(245,248,252,.96));
}

.s8-report-context > span,
.s8-report-context > time {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-width: 0;
    font-size: .78rem;
    font-weight: 700;
}

.s8-report-context svg,
.s8-report-toolbar svg,
.s8-table-tools svg,
.s8-chart-action svg {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
}

.s8-live-dot {
    width: .52rem;
    height: .52rem;
    border-radius: 999px;
    background: var(--s8-teal);
    box-shadow: 0 0 0 4px rgba(22,128,91,.13);
}

.s8-report-toolbar {
    position: sticky;
    z-index: 60;
    top: calc(var(--header-height, 72px) + .5rem);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 1.25rem;
    padding: .75rem;
    border: 1px solid rgba(184, 199, 217, .9);
    border-radius: 12px;
    background: rgba(255,255,255,.95);
    box-shadow: 0 12px 30px rgba(16,35,63,.11);
    backdrop-filter: blur(14px);
}

.s8-report-toolbar.s6-report-toolbar {
    top: calc(var(--header-height, 72px) + .5rem);
}

.s8-toolbar-copy {
    display: grid;
    gap: .08rem;
    min-width: 10rem;
}

.s8-toolbar-copy strong {
    color: var(--s8-ink);
    font-size: .9rem;
}

.s8-toolbar-copy small {
    color: var(--s8-muted);
    font-size: .72rem;
}

.s8-toolbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .45rem;
    flex-wrap: wrap;
}

.s8-export-button,
.s8-chart-action,
.s8-table-button,
.s8-page-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 40px;
    padding: .48rem .72rem;
    border: 1px solid var(--s8-line);
    border-radius: 8px;
    color: var(--s8-ink);
    background: var(--s8-surface);
    font: inherit;
    font-size: .76rem;
    font-weight: 750;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .16s ease, background-color .16s ease, color .16s ease, transform .16s ease;
}

.s8-export-button:hover,
.s8-chart-action:hover,
.s8-table-button:hover,
.s8-page-button:hover:not(:disabled) {
    color: #174f91;
    border-color: #9bb7d7;
    background: #edf5ff;
    transform: translateY(-1px);
}

.s8-export-button.is-primary {
    color: #fff;
    border-color: var(--s8-blue);
    background: var(--s8-blue);
}

.s8-export-button.is-primary:hover {
    color: #fff;
    background: #174f91;
}

.s8-export-button:disabled,
.s8-page-button:disabled {
    opacity: .46;
    cursor: not-allowed;
}

.s8-export-status {
    position: fixed;
    z-index: 2500;
    inset-block-end: 1.25rem;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    max-width: min(34rem, calc(100vw - 2rem));
    padding: .72rem 1rem;
    border: 1px solid #b8dfcf;
    border-radius: 9px;
    color: #0e6849;
    background: #effaf5;
    box-shadow: var(--s8-shadow);
    font-size: .82rem;
    font-weight: 750;
}

[dir="rtl"] .s8-export-status { transform: translateX(50%); }

.s8-filter-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    width: 100%;
    margin-block-end: .7rem;
}

.s8-filter-heading strong { font-size: .84rem; }

.s8-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.7rem;
    height: 1.7rem;
    padding-inline: .38rem;
    border-radius: 999px;
    color: #174f91;
    background: #eaf3ff;
    font-size: .7rem;
    font-weight: 800;
}

.s8-report-filter {
    border: 1px solid var(--s8-line) !important;
    border-radius: 10px !important;
    background: var(--s8-soft) !important;
}

.s8-table-region {
    position: relative;
    border: 1px solid var(--s8-line);
    border-radius: 10px;
    background: var(--s8-surface);
    overflow: hidden;
}

.s8-table-region > .table-responsive,
.table-responsive.s8-table-scroll {
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.s8-table-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .7rem;
    border-block-end: 1px solid var(--s8-line);
    background: var(--s8-soft);
}

.s8-table-search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 18rem;
    max-width: 32rem;
}

.s8-table-search svg {
    position: absolute;
    inset-inline-start: .72rem;
    color: var(--s8-muted);
    pointer-events: none;
}

.s8-table-search input,
.s8-page-size {
    min-height: 40px;
    border: 1px solid #b8c7d9;
    border-radius: 8px;
    color: var(--s8-ink);
    background: var(--s8-surface);
    font: inherit;
    font-size: .78rem;
}

.s8-table-search input {
    width: 100%;
    padding: .5rem .75rem .5rem 2.25rem;
}

[dir="rtl"] .s8-table-search input { padding: .5rem 2.25rem .5rem .75rem; }

.s8-table-options {
    display: flex;
    align-items: center;
    gap: .45rem;
}

.s8-page-size { padding: .45rem .6rem; }

.s8-table-region table {
    margin: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
}

.s8-table-region thead th {
    position: sticky;
    z-index: 3;
    top: 0;
    color: #24364f;
    background: #edf2f8 !important;
    box-shadow: inset 0 -1px 0 #c8d4e2;
    white-space: nowrap;
}

.s8-sort-button {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: .45rem;
    width: 100%;
    padding: .2rem 0;
    border: 0;
    color: inherit;
    background: transparent;
    font: inherit;
    font-weight: 800;
    text-align: start;
    cursor: pointer;
}

.s8-sort-button::after {
    content: "↕";
    color: #718198;
    font-size: .8rem;
}

th[aria-sort="ascending"] .s8-sort-button::after { content: "↑"; color: var(--s8-blue); }
th[aria-sort="descending"] .s8-sort-button::after { content: "↓"; color: var(--s8-blue); }

.s8-table-region tbody tr:nth-child(even) > * { background-color: rgba(245,248,252,.72); }
.s8-table-region tbody tr:hover > * { background-color: #edf5ff !important; }

.s8-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    min-height: 52px;
    padding: .55rem .7rem;
    border-block-start: 1px solid var(--s8-line);
    color: var(--s8-muted);
    background: var(--s8-soft);
    font-size: .76rem;
}

.s8-pagination {
    display: flex;
    align-items: center;
    gap: .35rem;
}

.s8-page-button { min-width: 40px; padding: .42rem; }

.s8-table-empty {
    display: grid;
    place-items: center;
    gap: .35rem;
    min-height: 10rem;
    padding: 2rem;
    color: var(--s8-muted);
    text-align: center;
}

.s8-table-empty strong { color: var(--s8-ink); }

.s8-empty-row td {
    padding: 2rem !important;
    color: var(--s8-muted) !important;
    text-align: center !important;
}

.s8-chart-card { position: relative; min-width: 0; overflow: hidden; }

.s8-chart-card canvas {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
}

.s8-chart-actions {
    position: absolute;
    z-index: 6;
    inset-block-start: .7rem;
    inset-inline-end: .7rem;
    display: flex;
    gap: .35rem;
}

.s8-chart-action {
    min-height: 36px;
    padding: .4rem .55rem;
    background: rgba(255,255,255,.94);
    box-shadow: 0 5px 14px rgba(16,35,63,.08);
}

.s8-chart-loading {
    position: absolute;
    z-index: 4;
    inset: 3.4rem .75rem .75rem;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--s8-muted);
    background: linear-gradient(100deg, #eef3f8 20%, #f8fafc 38%, #eef3f8 56%);
    background-size: 220% 100%;
    animation: s8-shimmer 1.25s linear infinite;
    font-size: .78rem;
    font-weight: 750;
    pointer-events: none;
}

.s8-chart-loading.is-ready {
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}

@keyframes s8-shimmer { to { background-position-x: -220%; } }

.s8-report-section {
    scroll-margin-top: calc(var(--header-height, 72px) + 6.5rem);
}

.s8-section-index {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: 0 0 1rem;
    padding: .6rem;
    overflow-x: auto;
    border: 1px solid var(--s8-line);
    border-radius: 10px;
    background: var(--s8-soft);
    scrollbar-width: thin;
}

.s8-section-index a {
    flex: 0 0 auto;
    padding: .45rem .65rem;
    border-radius: 7px;
    color: var(--s8-muted);
    font-size: .73rem;
    font-weight: 750;
    text-decoration: none;
}

.s8-section-index a:hover,
.s8-section-index a:focus-visible { color: #174f91; background: #e7f1fc; }

.s8-print-header,
.s8-print-footer { display: none; }

.s8-visually-hidden {
    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;
}

:is([data-bs-theme="dark"], [data-theme="dark"]) [data-s8-report] {
    --s8-ink: #e8f0f9;
    --s8-muted: #a9b8ca;
    --s8-line: #34465d;
    --s8-surface: #152338;
    --s8-soft: #101d2e;
    --s8-shadow: 0 16px 38px rgba(0,0,0,.28);
}

:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-report-context,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-report-toolbar {
    color: var(--s8-muted);
    border-color: var(--s8-line);
    background: rgba(19,31,50,.96);
}

:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-export-button,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-chart-action,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-table-button,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-page-button,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-table-search input,
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-page-size {
    color: var(--s8-ink);
    border-color: var(--s8-line);
    background: #192a42;
}

:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-table-region thead th {
    color: #e7eef7;
    background: #1c2d45 !important;
    box-shadow: inset 0 -1px 0 #3d5068;
}

:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-table-region tbody tr:nth-child(even) > * { background-color: rgba(16,29,46,.72); }
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-table-region tbody tr:hover > * { background-color: #203956 !important; }
:is([data-bs-theme="dark"], [data-theme="dark"]) .s8-chart-loading { background: linear-gradient(100deg, #17273d 20%, #21344d 38%, #17273d 56%); background-size: 220% 100%; }

@container (max-width: 860px) {
    .s8-report-toolbar { align-items: flex-start; }
    .s8-toolbar-copy { min-width: 8rem; }
    .s8-export-button span { display: none; }
    .s8-export-button { width: 40px; padding: .45rem; }
}

@media (max-width: 767.98px) {
    .s8-report-context { align-items: flex-start; flex-direction: column; gap: .45rem; }
    .s8-report-toolbar { position: relative; top: auto; align-items: stretch; flex-direction: column; }
    .s8-toolbar-copy { min-width: 0; }
    .s8-toolbar-actions { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); }
    .s8-export-button { width: auto; min-width: 0; }
    .s8-export-button span { display: none; }
    .s8-table-tools { align-items: stretch; flex-direction: column; }
    .s8-table-search { max-width: none; }
    .s8-table-options { display: grid; grid-template-columns: 1fr auto; }
    .s8-page-size { width: 100%; }
    .s8-table-footer { align-items: flex-start; flex-direction: column; }
    .s8-pagination { width: 100%; justify-content: space-between; }
    .s8-chart-action span { display: none; }
    .s8-chart-action { width: 36px; }
}

@media (max-width: 430px) {
    .s8-toolbar-actions { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .s8-table-options { grid-template-columns: 1fr; }
    .s8-table-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .s8-export-button,
    .s8-chart-action,
    .s8-table-button,
    .s8-page-button,
    .s8-chart-loading { animation: none !important; transition: none !important; }
}

@media (forced-colors: active) {
    .s8-report-context,
    .s8-report-toolbar,
    .s8-table-region,
    .s8-export-button,
    .s8-chart-action,
    .s8-table-button,
    .s8-page-button { border: 1px solid CanvasText !important; }
    .s8-live-dot { background: Highlight; box-shadow: none; }
}

@media print {
    @page { size: A4; margin: 13mm 11mm 15mm; }

    html, body {
        color: #172033 !important;
        background: #fff !important;
        font-size: 9.5pt !important;
    }

    body.s8-printing * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    body.s8-printing .home-v2-header,
    body.s8-printing .home-v2-footer,
    body.s8-printing .home-v2-beta-strip,
    body.s8-printing .public-nav,
    body.s8-printing .admin-rail,
    body.s8-printing .s6-report-toolbar,
    body.s8-printing .s8-report-toolbar,
    body.s8-printing .s8-report-context,
    body.s8-printing .s8-section-index,
    body.s8-printing .s8-table-tools,
    body.s8-printing .s8-table-footer,
    body.s8-printing .s8-chart-actions,
    body.s8-printing form,
    body.s8-printing button,
    body.s8-printing .pagination,
    body.s8-printing .leaflet-control-container,
    body.s8-printing .hero-actions { display: none !important; }

    body.s8-printing [data-s8-report] main,
    body.s8-printing .dashboard-main,
    body.s8-printing .workflow-main,
    body.s8-printing .broker-import-main {
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body.s8-printing .s8-print-header {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        gap: 1rem;
        margin: 0 0 8mm;
        padding: 0 0 4mm;
        border-block-end: 2px solid #1f5f99;
    }

    body.s8-printing .s8-print-header strong { display: block; color: #153e68; font-size: 16pt; }
    body.s8-printing .s8-print-header span { color: #5d6b7d; font-size: 8pt; }

    body.s8-printing .s8-print-footer {
        display: block;
        margin-block-start: 7mm;
        padding-block-start: 3mm;
        border-block-start: 1px solid #cbd5e1;
        color: #64748b;
        font-size: 7.5pt;
        text-align: center;
    }

    body.s8-printing .dashboard-hero,
    body.s8-printing .workflow-hero,
    body.s8-printing .broker-import-hero {
        margin: 0 0 6mm !important;
        padding: 6mm !important;
        border: 1px solid #c7d3e0 !important;
        color: #172033 !important;
        background: #f4f7fb !important;
        box-shadow: none !important;
    }

    body.s8-printing .dashboard-hero *,
    body.s8-printing .workflow-hero *,
    body.s8-printing .broker-import-hero * { color: #172033 !important; }

    body.s8-printing section,
    body.s8-printing article,
    body.s8-printing .app-card,
    body.s8-printing .valuation-result-band,
    body.s8-printing .broker-import-card {
        box-shadow: none !important;
        break-inside: avoid;
    }

    body.s8-printing .dashboard-chart-card,
    body.s8-printing .s5-chart-card { break-inside: avoid; min-height: 72mm; }

    body.s8-printing .s8-table-region { overflow: visible !important; border-color: #cbd5e1; }
    body.s8-printing .table-responsive { overflow: visible !important; max-height: none !important; }
    body.s8-printing table { width: 100% !important; font-size: 7.5pt !important; }
    body.s8-printing thead { display: table-header-group; }
    body.s8-printing tfoot { display: table-footer-group; }
    body.s8-printing tr { break-inside: avoid; }
    body.s8-printing th { position: static !important; color: #172033 !important; background: #eaf0f6 !important; }
    body.s8-printing td, body.s8-printing th { padding: 2.2mm !important; border-color: #d9e1ea !important; }
    body.s8-printing [data-s8-page-hidden="true"] { display: table-row !important; }
    body.s8-printing [data-s8-filter-hidden="true"] { display: none !important; }
    body.s8-printing .leaflet-container { min-height: 70mm !important; border: 1px solid #cbd5e1 !important; }
}
