body {
    background: #f6f8fb;
}

[data-bs-theme="dark"] body {
    background: #111827;
}

.metric {
    min-height: 112px;
}

.chart-wrap {
    height: 58vh;
    min-height: 360px;
    position: relative;
    width: 100%;
    overflow: hidden;
}

.table td,
.table th {
    vertical-align: middle;
}

.print-only {
    display: none;
}

.chart-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.summary-pill {
    border-radius: 999px;
    color: #111827;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 4px 10px;
}

.summary-target {
    background: rgba(25, 135, 84, 0.14);
}

.summary-high {
    background: rgba(255, 193, 7, 0.20);
}

.summary-very-high {
    background: rgba(253, 126, 20, 0.20);
}

.summary-low {
    background: rgba(220, 53, 69, 0.14);
}

.period-notes-list {
    display: grid;
    gap: 8px;
}

.period-note {
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 8px;
}

.period-note:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.period-note-time {
    color: #6c757d;
    font-size: 0.875rem;
}

.note-actions {
    display: flex;
    flex-shrink: 0;
    gap: 4px;
}

.note-actions .btn {
    line-height: 1;
    min-width: 30px;
}

.icon-btn {
    align-items: center;
    display: inline-flex;
    height: 30px;
    justify-content: center;
    padding: 0;
    width: 30px;
}

.icon-btn svg {
    fill: none;
    height: 15px;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    width: 15px;
}

.note-scores {
    color: #6c757d;
    font-size: 0.875rem;
    margin-top: 3px;
}

.note-symptoms {
    color: #495057;
    font-size: 0.875rem;
    margin-top: 3px;
}

.stat-card {
    background: var(--bs-body-bg);
}

.stat-green {
    background: rgba(25, 135, 84, 0.08);
    border-color: rgba(25, 135, 84, 0.24) !important;
}

.stat-yellow {
    background: rgba(255, 193, 7, 0.13);
    border-color: rgba(255, 193, 7, 0.34) !important;
}

.stat-orange {
    background: rgba(253, 126, 20, 0.13);
    border-color: rgba(253, 126, 20, 0.32) !important;
}

.stat-neutral {
    background: var(--bs-body-bg);
}

.peak-analysis-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
}

.peak-analysis-item {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    background: var(--bs-body-bg);
}

.peak-rise-low {
    background: rgba(25, 135, 84, 0.08);
    border-color: rgba(25, 135, 84, 0.22);
}

.peak-rise-medium {
    background: rgba(255, 193, 7, 0.12);
    border-color: rgba(255, 193, 7, 0.30);
}

.peak-rise-high {
    background: rgba(253, 126, 20, 0.12);
    border-color: rgba(253, 126, 20, 0.28);
}

.peak-rise-very-high {
    background: rgba(220, 53, 69, 0.10);
    border-color: rgba(220, 53, 69, 0.26);
}

.event-timeline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.event-timeline-item {
    align-items: center;
    background: rgba(108, 117, 125, 0.08);
    border: 1px solid rgba(108, 117, 125, 0.18);
    border-left: 4px solid var(--event-color, #6c757d);
    border-radius: 6px;
    display: inline-flex;
    gap: 6px;
    padding: 5px 8px;
}

.event-timeline-icon {
    align-items: center;
    background: var(--event-color, #6c757d);
    border-radius: 999px;
    color: #fff;
    display: inline-flex;
    font-size: 0.75rem;
    font-weight: 700;
    height: 20px;
    justify-content: center;
    width: 20px;
}

.event-timeline-time {
    color: #495057;
    font-weight: 600;
}

.event-timeline-label {
    color: #212529;
}

.day-score-list {
    display: grid;
    gap: 8px;
}

.day-score-row {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) auto;
    gap: 2px 12px;
    align-items: baseline;
}

.day-score-label {
    font-weight: 600;
}

.day-score-stars {
    color: #f59f00;
    font-size: 1rem;
    letter-spacing: 0;
    white-space: nowrap;
}

.day-score-note {
    color: var(--bs-secondary-color);
    grid-column: 1 / -1;
}

.day-conclusion-list {
    display: grid;
    gap: 7px;
}

.day-conclusion-item {
    align-items: flex-start;
    display: grid;
    gap: 8px;
    grid-template-columns: 22px 1fr;
    line-height: 1.35;
}

.day-conclusion-icon {
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
}

.insights-list {
    display: grid;
    gap: 6px;
}

.insights-list div::before {
    content: "- ";
    color: #198754;
    font-weight: 700;
}

body.jpg-exporting {
    background: #fff !important;
}

body.jpg-exporting nav,
body.jpg-exporting .no-print {
    display: none !important;
}

body.jpg-exporting main.container {
    max-width: 1180px !important;
    padding: 24px !important;
}

body.jpg-exporting .print-only {
    display: block !important;
}

body.jpg-exporting .row.g-4 {
    display: block !important;
}

body.jpg-exporting .col-lg-8 {
    width: 100% !important;
}

body.jpg-exporting .print-report-row .col-lg-8 > .card {
    margin-top: 0 !important;
}

body.jpg-exporting .print-report-row .col-lg-8 > .card + .card {
    margin-top: 16px !important;
}

body.jpg-exporting .chart-wrap {
    height: 420px !important;
    min-height: 420px !important;
    max-height: 420px !important;
}

body.jpg-exporting #glucoseChart {
    height: 420px !important;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 9mm;
    }

    html,
    body {
        width: 192mm;
        min-height: 279mm;
        background: #fff !important;
    }

    body {
        font-size: 11px;
        padding-bottom: 8mm;
        position: relative;
    }

    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    nav,
    .no-print {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    main.container {
        max-width: none !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .card {
        border: 1px solid #d7dde5 !important;
        box-shadow: none !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .card-body {
        padding: 8px !important;
    }

    .chart-wrap {
        display: block !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    #glucoseChart {
        display: block !important;
        width: 100% !important;
    }

    #chartContext {
        padding: 5px 8px !important;
        margin-bottom: 6px !important;
        font-size: 10px;
        color: #111 !important;
        background: #eef5ff !important;
        border: 1px solid #c7ddff !important;
    }

    .chart-summary {
        gap: 4px;
        margin-bottom: 4px !important;
    }

    .summary-pill {
        font-size: 9px;
        padding: 2px 6px;
    }

    .summary-pill small {
        display: inline;
        font-size: 8px;
    }

    .event-timeline {
        gap: 4px;
        margin-top: 5px !important;
    }

    .event-timeline-item {
        border-left-width: 3px;
        border-radius: 4px;
        font-size: 8px;
        gap: 3px;
        padding: 2px 5px;
    }

    .event-timeline-icon {
        font-size: 7px;
        height: 14px;
        width: 14px;
    }

    .peak-rise-low {
        background: rgba(25, 135, 84, 0.08) !important;
        border-color: rgba(25, 135, 84, 0.22) !important;
    }

    .peak-rise-medium {
        background: rgba(255, 193, 7, 0.12) !important;
        border-color: rgba(255, 193, 7, 0.30) !important;
    }

    .peak-rise-high {
        background: rgba(253, 126, 20, 0.12) !important;
        border-color: rgba(253, 126, 20, 0.28) !important;
    }

    .peak-rise-very-high {
        background: rgba(220, 53, 69, 0.10) !important;
        border-color: rgba(220, 53, 69, 0.26) !important;
    }

    .stat-green {
        background: rgba(25, 135, 84, 0.08) !important;
        border-color: rgba(25, 135, 84, 0.24) !important;
    }

    .stat-yellow {
        background: rgba(255, 193, 7, 0.13) !important;
        border-color: rgba(255, 193, 7, 0.34) !important;
    }

    .stat-orange {
        background: rgba(253, 126, 20, 0.13) !important;
        border-color: rgba(253, 126, 20, 0.32) !important;
    }

    #stats {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr);
        gap: 6px !important;
    }

    #stats > div {
        break-inside: avoid;
        width: auto !important;
        max-width: none !important;
        flex: none !important;
        page-break-inside: avoid;
        padding: 0 !important;
    }

    #stats .border {
        padding: 6px !important;
        min-height: 16mm;
    }

    #stats .fs-5 {
        font-size: 13px !important;
    }

    h1,
    .h3 {
        font-size: 18px !important;
        margin-bottom: 2px !important;
    }

    h2,
    .h5 {
        font-size: 13px !important;
        margin-bottom: 6px !important;
    }

    .print-chart-card {
        margin-bottom: 0 !important;
    }

    .print-report-row {
        display: block !important;
        margin-top: 2mm !important;
    }

    .col-lg-8 {
        width: 100% !important;
    }

    .print-report-row .col-lg-8 > .card {
        margin-top: 0 !important;
    }

    .print-report-row .col-lg-8 > .card + .card {
        margin-top: 8px !important;
    }

    .print-report-notes {
        display: block !important;
        break-inside: avoid !important;
        margin-top: 8px !important;
        page-break-inside: avoid !important;
    }

    .period-notes-list {
        break-inside: avoid !important;
        gap: 4px;
        font-size: 10px;
        page-break-inside: avoid !important;
    }

    .period-note {
        break-inside: avoid;
        page-break-inside: avoid;
        padding-bottom: 4px;
    }

    .period-note-time {
        font-size: 9px;
    }

    .note-scores {
        font-size: 8px;
        line-height: 1.2;
        margin-top: 1px;
    }

    .note-symptoms {
        font-size: 8px;
        line-height: 1.2;
        margin-top: 1px;
    }

    .peak-analysis-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
        font-size: 9px;
    }

    .peak-analysis-item {
        break-inside: avoid;
        page-break-inside: avoid;
        padding: 5px;
        border-radius: 4px;
    }

    .day-score-list {
        gap: 3px;
        font-size: 9px;
    }

    .day-score-row {
        grid-template-columns: 70px auto;
        gap: 1px 6px;
    }

    .day-score-stars {
        font-size: 9px;
        letter-spacing: 0;
    }

    .day-conclusion-list {
        gap: 3px;
        font-size: 9px;
    }

    .day-conclusion-item {
        gap: 4px;
        grid-template-columns: 14px 1fr;
        line-height: 1.2;
    }

    .insights-list {
        gap: 3px;
        font-size: 9px;
    }
}
