/*
 * chart.css — the CHART pages (P2b): the viewport, the toolbar, Topola's SVG as drawn by the FolialeRenderer
 * (public/assets/chart/chart.js — it returns no CSS of its own, so every box colour is here), and the PRINT
 * layout. Baseline-loaded (Assets::VIEW_CSS) because the chart arrives as a fragment. Colours are
 * --foliale-* / --bs-* variables only; the chart's own tokens are declared on .chart-page.
 */
.chart-page {
    --foliale-chart-text: var(--bs-body-color);
    --foliale-chart-muted: var(--bs-secondary-color);
    --foliale-chart-line: var(--bs-secondary-color);
    --foliale-chart-box: var(--bs-body-bg);
    --foliale-chart-box-border: var(--bs-emphasis-color);
    --foliale-chart-unknown-sex: var(--bs-tertiary-bg);
    /* colour by sex: ALIASES of the app-wide tints (base.css :root) — one pink and one blue, shared with
       the People rail's rows */
    --foliale-chart-male: var(--foliale-male-tint);
    --foliale-chart-female: var(--foliale-female-tint);
    --foliale-chart-family: var(--bs-body-bg);
    /* the person the chart was opened from: a thick border always; the fill tint when boxes are uncoloured */
    --foliale-chart-root: var(--bs-primary);
    --foliale-chart-root-fill: var(--foliale-highlight);
    /* colour by generation: four tints, cycled — none of them the by-sex pink / cyan */
    --foliale-chart-gen-0: var(--bs-success-bg-subtle);
    --foliale-chart-gen-1: var(--bs-primary-bg-subtle);
    --foliale-chart-gen-2: var(--bs-warning-bg-subtle);
    --foliale-chart-gen-3: var(--bs-secondary-bg-subtle);
}

/* === the viewport: a scrolling, draggable frame around the SVG ============================== */
.chart-viewport {
    position: relative;
    height: calc(100vh - 15rem);
    min-height: 20rem;
    overflow: auto;
    cursor: grab;
    background: var(--bs-body-bg);
}
.chart-viewport.is-panning {
    cursor: grabbing;
    user-select: none;
}
.chart-svg {
    display: block;
    margin: 0 auto;
}

/* the print dialog's OFF-SCREEN copy (chart-print.js): drawn again inside a light-theme .chart-page host so its
   computed colours are the light tokens; laid out (text is measured) but never seen, never printed */
.chart-print-stage {
    position: fixed;
    top: 0;
    left: -200000px;
    pointer-events: none;
}
@media print {
    .chart-print-stage {
        display: none !important;
    }
}

/* === the toolbar ============================================================================= */
.chart-fields-panel {
    min-width: 14rem;
}
.chart-field-move {
    line-height: 1;
}
.chart-field:first-child [data-field-move="up"],
.chart-field:last-child [data-field-move="down"] {
    visibility: hidden;
}

/* === the boxes (FolialeRenderer) ============================================================= */
.chart-svg .detailed text {
    font-family: var(--foliale-font-family);
    fill: var(--foliale-chart-text);
}
.chart-svg .detailed .name {
    font-size: 12px;
    font-weight: 600;
}
.chart-svg .detailed .details {
    font-size: 10px;
}
.chart-svg .detailed .id {
    font-size: 9px;
    fill: var(--foliale-chart-muted);
}
.chart-svg .detailed {
    stroke-width: 1.5px;
}
.chart-svg .detailed rect.border {
    stroke: var(--foliale-chart-box-border);
}
.chart-svg .detailed rect.family {
    stroke: var(--foliale-chart-box-border);
}
.chart-svg .indi {
    cursor: pointer;
}
.chart-svg .link {
    fill: none;
    stroke: var(--foliale-chart-line);
    stroke-width: 1px;
}
.chart-svg .additional-marriage {
    stroke-dasharray: 2;
}

/* colour: none / by sex / by generation (Topola's g.node carries generation-color0…11) */
.chart-svg .detailed rect.nocolor,
.chart-svg .detailed rect.family {
    fill: var(--foliale-chart-box);
}
.chart-svg .detailed rect.bysex {
    fill: var(--foliale-chart-unknown-sex);
}
.chart-svg .detailed rect.bysex.male {
    fill: var(--foliale-chart-male);
}
.chart-svg .detailed rect.bysex.female {
    fill: var(--foliale-chart-female);
}
.chart-svg .generation-color0 .detailed rect.bygeneration,
.chart-svg .generation-color4 .detailed rect.bygeneration,
.chart-svg .generation-color8 .detailed rect.bygeneration { fill: var(--foliale-chart-gen-0); }
.chart-svg .generation-color1 .detailed rect.bygeneration,
.chart-svg .generation-color5 .detailed rect.bygeneration,
.chart-svg .generation-color9 .detailed rect.bygeneration { fill: var(--foliale-chart-gen-1); }
.chart-svg .generation-color2 .detailed rect.bygeneration,
.chart-svg .generation-color6 .detailed rect.bygeneration,
.chart-svg .generation-color10 .detailed rect.bygeneration { fill: var(--foliale-chart-gen-2); }
.chart-svg .generation-color3 .detailed rect.bygeneration,
.chart-svg .generation-color7 .detailed rect.bygeneration,
.chart-svg .generation-color11 .detailed rect.bygeneration { fill: var(--foliale-chart-gen-3); }
.chart-svg .detailed rect.family.bygeneration {
    fill: var(--foliale-chart-box);
}

/* confidence (Topola's QUAY 0–3, kept from the prototype): a weaker border dash, a paler fill */
.chart-svg .detailed rect.border.confidence2,
.chart-svg .detailed rect.family.confidence2 { stroke-dasharray: 8 4; }
.chart-svg .detailed rect.border.confidence1,
.chart-svg .detailed rect.family.confidence1 { stroke-dasharray: 3 3; }
.chart-svg .detailed rect.border.confidence0,
.chart-svg .detailed rect.family.confidence0 { stroke-dasharray: 1 3; }
.chart-svg .detailed rect.background.confidence1 { fill-opacity: 0.6; }
.chart-svg .detailed rect.background.confidence0 { fill-opacity: 0.35; }

/* the root: the person the chart was opened from — the border always, the fill only when uncoloured (a
   colour scheme keeps its meaning on the root's box too) */
.chart-svg .chart-root rect.background.nocolor {
    fill: var(--foliale-chart-root-fill);
    fill-opacity: 1;
}
.chart-svg .chart-root rect.border {
    stroke: var(--foliale-chart-root);
    stroke-width: 3px;
}

/* === PRINT: A4 landscape (the @page rule rides in the chart view itself, so only a chart page prints
   landscape); rails, toolbar, header, footer hidden; one title line; the SVG scaled to fit the printable
   area with its aspect kept (viewBox + the default xMidYMid meet). No tiling. ================== */
@media print {
    body:has(.chart-page) .app-sidebar,
    body:has(.chart-page) .app-rightpanel,
    body:has(.chart-page) .app-header,
    body:has(.chart-page) .app-footer,
    .chart-page .chart-heading,
    .chart-page .chart-toolbar,
    .chart-page .chart-notice,
    .chart-page .chart-status {
        display: none !important;
    }
    body:has(.chart-page) .app-shell,
    body:has(.chart-page) .app-centre,
    body:has(.chart-page) .app-content {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }
    body:has(.chart-page) #app-centre-content {
        padding: 0 !important;
    }
    .chart-page .chart-print-title {
        display: block !important;
        margin: 0 0 4mm;
        font-size: 11pt;
        font-weight: 600;
    }
    .chart-page .chart-viewport {
        height: auto;
        min-height: 0;
        overflow: visible;
        border: 0 !important;
    }
    .chart-page .chart-svg {
        width: 100% !important;
        height: 175mm !important;   /* 210mm − 2 × 10mm margins − the title line */
    }
}
