/* Sugar Live — Glucose Report
 * Light-themed clinical document. Screen and print share the same look so
 * "what you see is what you save" — the user hits Cmd/Ctrl+P → Save as PDF.
 */

:root {
    --report-bg:        #ffffff;
    --report-text:      #111827;
    --report-muted:     #6b7280;
    --report-border:    #e5e7eb;
    --report-card-bg:   #f9fafb;
    --report-accent:    #1f2937;

    /* AGP / consensus TIR colours */
    --tir-very-low:  #b91c1c;
    --tir-low:       #f59e0b;
    --tir-in-range:  #16a34a;
    --tir-high:      #fbbf24;
    --tir-very-high: #ea580c;
}

html, body {
    background: var(--report-bg);
    color: var(--report-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.report-container {
    max-width: 920px;
    margin: 0 auto;
    padding: 1.5rem 2rem 3rem;
}

/* ---- Toolbar (screen-only) ---- */

.report-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--report-border);
    flex-wrap: wrap;
}

.report-link {
    font-size: 0.875rem;
    color: var(--report-muted);
    text-decoration: none;
}

.report-link:hover { color: var(--report-text); }

.report-toolbar-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.segmented-control {
    display: flex;
    border: 1px solid var(--report-border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.report-days {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: transparent;
    border: none;
    color: var(--report-muted);
    cursor: pointer;
    transition: background 0.15s;
}

.report-days:hover { background: var(--report-card-bg); }
.report-days.active { background: var(--report-accent); color: #fff; }

.report-print-btn {
    padding: 0.4rem 0.875rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--report-accent);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
}

.report-print-btn:hover { background: #0f172a; }

/* ---- Header ---- */

.report-header {
    margin-bottom: 2rem;
}

.report-header h1 {
    font-size: 1.875rem;
    font-weight: 800;
    margin: 0 0 0.5rem;
    letter-spacing: -0.02em;
}

.report-meta {
    font-size: 0.875rem;
    color: var(--report-muted);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.meta-sep { opacity: 0.5; }

/* ---- Sections ---- */

.report-section {
    margin-bottom: 2rem;
    page-break-inside: avoid;
    break-inside: avoid;
}

.report-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--report-muted);
    margin: 0 0 0.875rem;
    border-bottom: 1px solid var(--report-border);
    padding-bottom: 0.5rem;
}

.report-caption {
    font-size: 0.75rem;
    color: var(--report-muted);
    margin: 0 0 0.875rem;
}

/* ---- Stat cards ---- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--report-card-bg);
    border: 1px solid var(--report-border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
}

.stat-value {
    font-size: 1.875rem;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--report-muted);
    line-height: 1.4;
}

.stat-unit { font-weight: 400; opacity: 0.75; }

.stat-unit-inline {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--report-muted);
    margin-left: 0.25rem;
}

/* ---- TIR bar ---- */

.tir-bar {
    display: flex;
    width: 100%;
    height: 2.25rem;
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 0.875rem;
    border: 1px solid var(--report-border);
}

.tir-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.35);
    overflow: hidden;
    white-space: nowrap;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.tir-legend {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    font-size: 0.8125rem;
}

.tir-legend li {
    display: grid;
    grid-template-columns: 0.875rem 1fr auto;
    align-items: center;
    gap: 0.875rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--report-border);
}

.tir-legend li:last-child { border-bottom: none; }

.tir-swatch {
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 0.25rem;
    flex-shrink: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.tir-band-name { color: var(--report-text); }

.tir-band-pct {
    font-weight: 700;
    color: var(--report-text);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ---- Combined TBR / TAR rows ---- */

.tir-combined {
    margin-top: 0.875rem;
    border-top: 1px solid var(--report-border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tir-combined-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8125rem;
}

.tir-combined-label {
    color: var(--report-text);
    font-weight: 600;
}

.tir-combined-value {
    font-weight: 700;
    color: var(--report-text);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ---- AGP chart ---- */

.agp-chart-wrap {
    position: relative;
    width: 100%;
    height: 280px;
}

/* ---- Hypo summary ---- */

.hypo-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* ---- Status / messages ---- */

.report-status {
    text-align: center;
    color: var(--report-muted);
    font-size: 0.75rem;
    margin-top: 1rem;
}

.report-status a {
    color: var(--report-accent);
    text-decoration: underline;
}

/* ---- Print ---- */

@media print {
    @page {
        margin: 1.5cm;
        size: A4;
    }

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

    body { background: #fff; }

    .report-container {
        padding: 0;
        max-width: none;
    }

    /* Force background colours through — needed for the TIR bar to print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .report-section {
        page-break-inside: avoid;
        break-inside: avoid;
        margin-bottom: 1.25rem;
    }

    .report-header { margin-bottom: 1.25rem; }
    .report-header h1 { font-size: 1.5rem; }

    .stat-card {
        background: #fff;
        border: 1px solid #d1d5db;
    }

    .stat-value { font-size: 1.5rem; }

    .agp-chart-wrap { height: 240px; }

    /* Mobile-screen rule shouldn't apply when printing */
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .hypo-summary { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Narrow screens ---- */

@media (max-width: 640px) {
    .report-container { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .hypo-summary { grid-template-columns: 1fr; }
    .report-header h1 { font-size: 1.5rem; }
    .stat-value { font-size: 1.5rem; }
}
