:root {
    --pico-font-size: 90%;
    --pico-border-radius: 1rem;
    --pico-card-border-radius: 1rem;
    --pico-spacing: .9rem;

    --app-bg: #eef7ef;
    --panel-bg: rgba(255, 255, 255, .92);
    --surface-soft: #f7fbf7;
    --border-color: #dbe8dc;
    --text-muted: #657267;
    --shadow: 0 10px 30px rgba(31, 73, 42, .07);
    --radius: 1.2rem;
}

:root:not([data-theme="dark"]),
[data-theme="light"] {
    --pico-primary: #3f7d46;
    --pico-primary-background: #3f7d46;
    --pico-primary-border: #3f7d46;

    --pico-primary-hover: #326638;
    --pico-primary-hover-background: #326638;
    --pico-primary-hover-border: #326638;

    --pico-primary-focus: rgba(63, 125, 70, .25);
    --pico-primary-inverse: #ffffff;
}

* { box-sizing: border-box; }

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(79, 148, 93, .10), transparent 30%),
        linear-gradient(180deg, #f3faf4 0%, var(--app-bg) 100%);
}

.muted { color: var(--text-muted); }

/* Screen pages */
.app-shell {
    max-width: 1120px;
    padding-top: 1.75rem;
    padding-bottom: 3.5rem;
}

.hero,
.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.3rem 1.5rem;
    margin-bottom: 1rem;
}

.hero h1 { margin-bottom: .2rem; }
.hero p { margin: 0; }

.hero-badge {
    padding: .5rem .8rem;
    border-radius: 999px;
    background: #e7f4e9;
    color: #286237;
    font-weight: 700;
    white-space: nowrap;
}

.panel {
    padding: 1.15rem;
    margin-bottom: 1rem;
}

.filter-grid {
    display: grid;
    gap: .9rem;
    align-items: end;
    margin-bottom: 0;
}

.statistics-app .filter-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.survey-app .filter-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.filter-top-row {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: .9rem;
    grid-column: 1 / -1;
    align-items: end;
}

.filter-grid > label,
.filter-top-row > label,
.filter-actions {
    margin-bottom: 0;
}

.filter-grid select,
.filter-top-row select,
.filter-question select,
.filter-campaign select {
    margin-bottom: 0;
}

.filter-question select {
    font-size: 1rem;
    font-weight: 500;
}

.filter-actions { display: contents; }

.filter-actions button,
.filter-actions input[type="submit"] {
    width: 100%;
    min-height: 2.85rem;
    margin-bottom: 0;
}

/* The button opening the printable page is the inverse of the primary button. */
.filter-actions button[formtarget="_blank"],
.filter-actions input[type="submit"][formtarget="_blank"] {
    background: #fff;
    border-color: var(--pico-primary);
    color: var(--pico-primary);
}

.filter-actions button[formtarget="_blank"]:hover,
.filter-actions button[formtarget="_blank"]:focus,
.filter-actions input[type="submit"][formtarget="_blank"]:hover,
.filter-actions input[type="submit"][formtarget="_blank"]:focus {
    background: var(--pico-primary-focus);
    border-color: var(--pico-primary-hover);
    color: var(--pico-primary-hover);
}



.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: .9rem;
}

.section-header h2 { margin-bottom: .2rem; }
.section-header p { margin: 0; }
.view-toggle { flex: 0 0 auto; white-space: nowrap; }
.view-toggle button { margin: 0; padding: .42rem .75rem; font-size: .86rem; }

.table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    padding-bottom: .2rem;
}

table { width: 100%; }

.stats-table {
    width: 100%;
    min-width: 980px;
    margin-bottom: 0;
    font-size: .84rem;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
}

.stats-table thead { position: relative; z-index: 3; }
.stats-table thead th {
    background: #f5faf5;
    border-bottom: 2px solid var(--border-color);
    overflow: visible !important;
    position: relative;
    z-index: 3;
}

/* Rotated region headings should not inherit the green table-header tint. */
.stats-table thead th.rot-head {
    background: #fff;
}

.stats-table th,
.stats-table td {
    padding: .42rem .5rem;
    vertical-align: top;
}

.stats-table th:first-child,
.stats-table td:first-child {
    position: sticky;
    left: 0;
    background: inherit;
    text-align: left;
}

.stats-table tbody th,
.stats-table tfoot th { font-weight: 600; }

.stats-table tfoot th,
.stats-table tfoot td {
    border-top: 2px solid var(--border-color);
    background: #f8fbf8;
}

.label-col {
    width: 230px;
    min-width: 230px;
    text-align: left;
    white-space: normal;
}

.scope-col,
.geo-col {
    width: 82px;
    min-width: 82px;
    max-width: 82px;
    text-align: center;
}

.number-cell { text-align: center; white-space: nowrap; }

.stat-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .12rem;
    line-height: 1.15;
}

.stat-cell strong { font-size: .95rem; }
.stat-cell small { font-size: .72rem; }

.rot-head {
    height: 150px;
    padding: 0 0 0 10px !important;
    vertical-align: bottom !important;
}

.rot-head-inner {
    position: relative;
    height: 150px;
    width: 100%;
    overflow: visible;
}

.rot-head-text {
    position: absolute;
    left: 16px;
    bottom: 20px; /* moved approximately 10px upward */
    width: 150px;
    transform: rotate(-60deg);
    transform-origin: left bottom;
    white-space: nowrap;
    text-align: left;
    line-height: 1;
    pointer-events: none;
}

.section-view { overflow: hidden; position: relative; }
.section-view-track {
    display: flex;
    width: 200%;
    transition: transform 280ms ease;
    will-change: transform;
}
.section-view.is-chart .section-view-track { transform: translateX(-50%); }
.section-view-pane { width: 50%; min-width: 50%; }
.section-view-pane.chart-pane { padding-top: .5rem; }
.chart-pane { display: grid; place-items: center; padding: 1rem; }
.pie-chart { width: 100%; min-height: 340px; }

/* Printable pages */
.print-page {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(79, 148, 93, .08), transparent 30%),
        linear-gradient(180deg, #f3faf4 0%, var(--app-bg) 100%);
    font-size: .88rem;
}

.print-shell,
.print-document {
    max-width: 1120px;
    width: calc(100% - 2rem);
    1margin: 1.25rem auto 2rem;
    margin: 0 auto;
}

.print-ribbon,
.print-section,
.question-page {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.print-ribbon {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    padding: 1.3rem 1.45rem;
    margin-bottom: 1.15rem;
}

.print-ribbon h1 { margin-bottom: .2rem; }
.print-ribbon p { margin: 0; }
.print-ribbon button { flex: 0 0 auto; }

.parameter-summary,
.filter-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: .25rem;
    padding: .75rem 0 0;
    margin: .75rem 0 0;
    border-top: 1px solid var(--border-color);
    list-style: none !important;
    padding-left: 0;
}

.parameter-summary li,
.filter-summary li {
    margin: 0;
    padding-left: 0;
    list-style: none !important;
}

.parameter-summary li::marker,
.filter-summary li::marker {
    content: "";
}

.print-section,
.question-page {
    padding: 1.35rem;
    margin-bottom: 1.35rem;
}

.print-section h2,
.question-page h2 { margin-bottom: .2rem; }

.chart-wrap { height: 320px; margin: .8rem 0 1.25rem; }
.chart-wrap .pie-chart { height: 100%; min-height: 0; }

.print-landscape table { font-size: .76rem; }
.print-landscape th,
.print-landscape td {
    padding: .34rem .42rem;
    text-align: right;
    vertical-align: middle;
}
.print-landscape th:first-child,
.print-landscape td:first-child { text-align: left; }

.print-landscape .stat-cell {
    align-items: flex-end;
    text-align: right;
}

.question-page { min-height: 270mm; padding: 12mm; }
.question-total { margin: 0 0 .8rem; color: var(--text-muted); }
.print-portrait .pie-chart { height: 92mm; margin: .35rem auto 1rem; }

.no-data {
    display: grid;
    place-items: center;
    height: 70mm;
    margin-bottom: 1rem;
    border: 1px dashed #b9c8bb;
    color: var(--text-muted);
}

.print-portrait table {
    border-collapse: collapse;
    font-size: .84rem;
}

.print-portrait th,
.print-portrait td {
    padding: .48rem .58rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}

.print-portrait th:nth-child(2),
.print-portrait th:nth-child(3),
.print-portrait td:nth-child(2),
.print-portrait td:nth-child(3) {
    width: 18%;
    text-align: right;
    white-space: nowrap;
}

.print-portrait thead th { border-bottom: 2px solid #aebbae; }
.print-portrait tfoot th,
.print-portrait tfoot td {
    border-top: 2px solid #aebbae;
    border-bottom: 0;
    font-weight: 700;
}

@media (max-width: 900px) {
    .statistics-app .filter-grid,
    .survey-app .filter-grid,
    .filter-top-row { grid-template-columns: 1fr; }

    .hero,
    .print-ribbon { flex-direction: column; align-items: stretch; }

    .section-header { align-items: stretch; }
}

@media (max-width: 768px) {
    .section-header { flex-direction: column; }
    .view-toggle { align-self: flex-end; }
    .stats-table { min-width: 900px; }
    .label-col { width: 180px; min-width: 180px; }
    .scope-col,
    .geo-col { width: 76px; min-width: 76px; max-width: 76px; }
    .rot-head,
    .rot-head-inner { height: 136px; }
    .rot-head-text { width: 138px; }
}

@page landscape-page { size: A4 landscape; margin: 10mm; }
@page portrait-page { size: A4 portrait; margin: 12mm; }

@media print {
    .print-landscape { page: landscape-page; }
    .print-portrait { page: portrait-page; }
    .print-page { background: #fff; }

    .print-shell,
    .print-document {
        max-width: none;
        width: auto;
        margin: 0;
    }

    .print-ribbon {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 0 0 7mm;
        margin: 0;
    }

    .print-ribbon button { display: none !important; }

    .print-section,
    .question-page {
        min-height: auto;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        margin: 0;
        break-before: page;
        page-break-before: always;
    }

    .print-ribbon + .print-section,
    .print-ribbon + .question-page {
        break-before: auto;
        page-break-before: auto;
    }

    .chart-wrap { height: 78mm; }
    .print-portrait .pie-chart { height: 90mm; }

    .print-landscape table { font-size: 7.5pt; }
    .print-portrait table { font-size: 8.5pt; }

    .table-scroll { overflow: visible; }
}
