:root {
    --ink: #17324d;
    --muted: #536779;
    --bg: #f4f7f9;
    --card: #fff;
    --accent: #005eb8;
    --accent2: #003f7f;
    --border: #d8e1e8;
    --success: #007f3b;
    --focus: #ffbf47;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

/* HEADER */

.site-title {
    color: inherit;
    text-decoration: none;
    font-weight: inherit;
}

.site-title:hover {
    text-decoration: none;
}

header {
    background: var(--ink);
    color: white;
    padding: 28px 20px;
}

.wrap {
    max-width: 900px;
    margin: auto;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

h1 {
    margin: 0 0 8px;
    font-size: clamp(1.65rem, 4vw, 2.35rem);
}

header p {
    margin: 0;
    max-width: 700px;
    opacity: .95;
}

/* MENU */

.menu-container {
    position: relative;
    flex-shrink: 0;
}

.menu-button {
    background: transparent;
    color: white;
    border: none;
    padding: 10px;
    font-size: 3rem;
    line-height: 1;
    font-weight: bold;
    cursor: pointer;
}

.menu-button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.menu-button:focus {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);

    min-width: 220px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 14px #00000025;

    overflow: hidden;
    z-index: 1000;
}

.menu-dropdown.open {
    display: block;
}

.menu-dropdown a {
    display: block;
    padding: 13px 16px;
    color: var(--ink);
    text-decoration: none;
}

.menu-dropdown a:hover {
    background: #eef3f6;
}

.menu-dropdown a:focus {
    outline: 3px solid var(--focus);
    outline-offset: -3px;
}

/* MAIN */

main {
    padding: 28px 20px 50px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px #17324d12;
}

h2 {
    margin-top: 0;
    font-size: 1.35rem;
}

h3 {
    color: var(--ink);
    margin-top: 24px;
}

.small {
    font-size: .9rem;
    color: var(--muted);
}

/* FORMS */

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

label {
    display: block;
    font-weight: bold;
    margin-bottom: 7px;
}

input[type=date],
input[type=time],
input[type=text],
input[type=email],
input[type=number] {
    width: 100%;
    padding: 12px;
    border: 2px solid #768692;
    border-radius: 6px;
    font-size: 1rem;
    color: var(--ink);
    background: white;
}

input:focus {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
    border-color: var(--ink);
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: normal;
}

.check input {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

.hint {
    color: var(--muted);
    font-size: .93rem;
    margin: 6px 0 0;
}

/* BUTTONS */

button,
.button {
    border: 0;
    border-radius: 6px;
    padding: 13px 20px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

.button {
    display: inline-block;
    text-decoration: none;
}

.primary {
    background: var(--accent);
    color: white;
}

.primary:hover {
    background: var(--accent2);
}

.secondary {
    background: #e8eef3;
    color: var(--ink);
}

button:focus,
.button:focus {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}

/* STATUS MESSAGES */

.error {
    background: #fff1f1;
    border-left: 5px solid #d5281b;
    padding: 12px 15px;
    margin-top: 16px;
    display: none;
}

.success {
    background: #e9f6ef;
    border-left: 5px solid var(--success);
    padding: 15px;
    margin-top: 20px;
    display: none;
}

.info-box {
    background: #e8f1f8;
    border-left: 5px solid var(--accent);
    padding: 15px 18px;
    margin: 20px 0;
}

/* IMAGE + HEADING */

.heading-with-icon {
    display: flex;
    align-items: center;
    gap: 12px;
}

.heading-with-icon img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.heading-with-icon h2 {
    margin: 0;
}

.pdf-button img {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

/* VIDEO */

.video-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    margin-top: 20px;
    overflow: hidden;
    border-radius: 10px;
    background: #000;
}

.video-container iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* TABLES */

.preview {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

th {
    background: #eef3f6;
}

/* FOOTER */

footer {
    text-align: center;
    color: var(--muted);
    padding: 0 20px 35px;
    font-size: .9rem;
}

/* MOBILE */

@media (max-width: 650px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 18px;
    }

    .header-row {
        align-items: flex-start;
    }

    .menu-button {
        font-size: 2.5rem;
    }
}

/* WEEKLY BP READINGS */

.bp-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin-top: 20px;
}

.bp-entry-table {
    min-width: 680px;
}

.bp-entry-table th {
    text-align: center;
}

.bp-entry-table td {
    text-align: center;
}

.bp-input {
    width: 90px !important;
    padding: 10px !important;
    text-align: center;
}

.average-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin: 20px 0;
}

.average-result {
    background: #eef3f6;
    border-radius: 10px;
    padding: 22px;
    text-align: center;
}

.average-label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
}

.average-result strong {
    display: block;
    font-size: 2.4rem;
    color: var(--ink);
    line-height: 1.1;
}

.average-unit {
    color: var(--muted);
    font-size: .9rem;
}

.bp-chart-wrapper {
    width: 100%;
    overflow-x: auto;
    margin-top: 20px;
}

.bp-chart {
    display: block;
    width: 100%;
    min-width: 600px;
    height: auto;
}

.chart-grid-line {
    stroke: #aab7c2;
    stroke-width: 1;
    opacity: 0.55;
}

.chart-axis-text {
    fill: #536779;
    font-size: 14px;
}

.chart-axis-title {
    fill: #17324d;
    font-size: 15px;
    font-weight: bold;
}

.chart-systolic {
    stroke: #005eb8;
    stroke-width: 4;
}

.chart-systolic-point {
    fill: #005eb8;
}

.chart-diastolic {
    stroke: #536779;
    stroke-width: 4;
}

.chart-diastolic-point {
    fill: #536779;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-top: 12px;
    font-weight: bold;
}

.legend-line {
    display: inline-block;
    width: 28px;
    height: 4px;
    vertical-align: middle;
    margin-right: 7px;
}

.systolic-line {
    background: #005eb8;
}

.diastolic-line {
    background: #536779;
}

@media (max-width: 650px) {

    .average-grid {
        grid-template-columns: 1fr;
    }

}

/* BLOOD PRESSURE CHART BACKGROUND BANDS */

.chart-zone-normal {
    fill: #d9f0df;
}

.chart-zone-elevated {
    fill: #fff4cf;
}

.chart-zone-high {
    fill: #f8d7da;
}

.chart-zone-label {
    fill: #17324d;
    font-size: 13px;
    font-weight: bold;
}

/* =========================================
   PERSONALISED BP DIARY
   ========================================= */

.diary-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.diary-heading h2 {
    margin-top: 0;
}

.diary-patient-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 30px;
    margin: 25px 0;
}

.diary-write-line {
    display: inline-block;
    width: 65%;
    margin-left: 8px;
    border-bottom: 1px solid var(--ink);
}

.diary-instruction {
    margin: 20px 0;
}

.diary-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.diary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.diary-table th,
.diary-table td {
    border: 1px solid var(--border);
    padding: 12px;
}

.diary-table th {
    background: #eef3f6;
    text-align: center;
}

.diary-table th span {
    font-size: 0.8rem;
    font-weight: normal;
}

.diary-date {
    width: 30%;
    font-weight: bold;
    vertical-align: middle;
}

.diary-time {
    width: 15%;
    text-align: center;
    font-weight: bold;
}

.diary-writing-box {
    width: 27.5%;
    height: 42px;
    background: #fff;
}

.diary-notes {
    margin-top: 30px;
}

.notes-line {
    height: 32px;
    border-bottom: 1px solid var(--border);
}

.diary-disclaimer {
    margin-top: 30px;
}


/*
 * MOBILE
 */

@media (max-width: 650px) {

    .diary-heading {
        display: block;
    }

    .diary-heading button {
        margin-top: 15px;
    }

    .diary-patient-details {
        grid-template-columns: 1fr;
        gap: 18px;
    }

}


/*
 * PRINTING
 */

/* ========================================
   PRINTABLE BLOOD PRESSURE REPORT
   ======================================== */

.print-report-header {
    display: none;
}


@media print {

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


    body {
        background: #ffffff;
        color: #000000;
        font-size: 9pt;
    }


    /*
     * Hide normal website elements
     */

    header,
    footer,
    .readings-settings,
    #updateReadingsDates,
    #calculateBtn,
    #clearBtn,
    #printBtn,
    #csvBtn,
    #readingError {
        display: none !important;
    }


    /*
     * Main printable area
     */

    main.wrap {
        max-width: none;
        width: 100%;
        margin: 0;
        padding: 0;
    }


    /*
     * Report heading
     */

    .print-report-header {
        display: block;
        margin: 0 0 4px 0;
        padding-bottom: 3px;
        border-bottom: 2px solid #17324d;
    }

    .print-report-header h1 {
        margin: 0 0 2px 0;
        font-size: 17pt;
        color: #17324d;
    }

    .print-report-header p {
        margin: 0;
        font-size: 10pt;
    }


    /*
     * Remove normal card appearance
     */

    .card {
        border: 0;
        box-shadow: none;
        padding: 0;
        margin: 0 0 12px 0;
        page-break-inside: avoid;
    }


    /*
     * Hide introductory text in
     * the readings card
     */

    main > .card:first-of-type > h2,
    main > .card:first-of-type > p {
        display: none;
    }


    /*
     * Readings table
     */

    .bp-table-wrapper {
        overflow: visible;
        margin-top: 0;
    }

    .bp-entry-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 8pt;
    }

    .bp-entry-table th,
    .bp-entry-table td {
        padding: 0px 3px;
        height: 15px;
        line-height: 1;
        border: 1px solid #777;
    }

    .bp-entry-table input {
        width: 100%;
        height: 13px;
        min-height: 0;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        text-align: center;
        font-size: 7.5pt;
        line-height: 1;
    }

    .bp-entry-table th {
        background: #eef3f6 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .bp-entry-table input {
        width: 100%;
        border: 0;
        background: transparent;
        padding: 0;
        text-align: center;
        font-size: 8pt;
    }


    /*
 * Weekly average + chart
 * side by side
 */

    .report-results-row {
        display: grid !important;
        grid-template-columns: 28% 72%;
        gap: 6mm;
        align-items: start;
        width: 100%;
        margin-top: 6px;
        page-break-inside: avoid;
    }


    /*
     * Weekly average
     */

    #resultsCard {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #resultsCard h2 {
        margin: 0 0 5px 0;
        font-size: 12pt;
    }

    #resultsCard .average-grid {
        display: block;
        margin: 0;
    }

    #resultsCard .average-result {
        padding: 5px;
        margin: 0 0 5px 0;
        border-radius: 4px;
    }

    #resultsCard .average-label {
        margin-bottom: 1px;
        font-size: 8pt;
    }

    #resultsCard .average-result strong {
        font-size: 19pt;
        line-height: 1;
    }

    #resultsCard .average-unit {
        font-size: 7pt;
    }

    #resultsCard #readingCount {
        margin: 4px 0 0;
        font-size: 7pt;
        line-height: 1.15;
    }


    /*
     * Chart
     */

    #chartCard {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        min-width: 0;
    }

    #chartCard h2 {
        margin: 0 0 2px 0;
        font-size: 12pt;
    }

    #chartCard > p {
        margin: 0 0 2px 0;
        font-size: 7pt;
        line-height: 1.15;
    }

    #chartCard .bp-chart-wrapper {
        width: 100%;
        overflow: visible;
        margin: 0;
    }

    #chartCard .bp-chart {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: none !important;
    }

    #chartCard .chart-legend {
        margin-top: 2px;
        gap: 12px;
        font-size: 7pt;
    }

    .chart-tooltip {
        display: none !important;
    }

    /*
     * Preserve chart background colours
     */

    .chart-zone-normal,
    .chart-zone-elevated,
    .chart-zone-high {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }


    /*
     * Hide About these results
     * from the printed report
     */

    main > .card:last-of-type {
        display: none;
    }

}

/* Chart tooltip */

.bp-chart-wrapper {
    position: relative;
}

.chart-data-point {
    cursor: pointer;
}

.chart-data-point:hover,
.chart-data-point:focus {
    stroke-width: 4px;
    outline: none;
}

.chart-tooltip {
    position: absolute;
    z-index: 10;

    display: none;

    min-width: 110px;
    padding: 9px 12px;

    background: #17324d;
    color: #ffffff;

    border-radius: 6px;

    text-align: center;
    line-height: 1.3;

    pointer-events: none;

    transform:
            translate(-50%, calc(-100% - 10px));

    box-shadow:
            0 3px 10px rgba(0, 0, 0, 0.18);
}

.chart-tooltip.visible {
    display: block;
}

.chart-tooltip strong,
.chart-tooltip span,
.chart-tooltip small {
    display: block;
}

.chart-tooltip strong {
    font-size: 0.9rem;
}

.chart-tooltip span {
    margin-top: 2px;
    font-size: 1rem;
    font-weight: bold;
}

.chart-tooltip small {
    margin-top: 2px;
    font-size: 0.75rem;
    opacity: 0.9;
}

/* ========================================
   PRINTABLE BLOOD PRESSURE REPORT
   ======================================== */


/* ========================================
   PERSONALISED DIARY - PRINT ONLY
   ======================================== */

@media print {
    .no-print {
        display: none !important;
    }
    .diary-print-area {
        display: block !important;
        border: 0;
        box-shadow: none;
        padding: 0;
        margin: 0;
    }

    .diary-heading {
        margin-bottom: 32px;
    }

    .diary-heading h2 {
        margin: 0 0 2px 0;
        font-size: 17pt;
    }

    .diary-heading p {
        margin: 0;
    }

    .diary-patient-details {
        margin: 10px 0;
        gap: 20px;
    }

    .diary-instruction {
        margin: 7px 0;
        font-size: 8.5pt;
        line-height: 1.2;
    }

    .diary-table {
        width: 100%;
        margin-top: 6px;
        border-collapse: collapse;
        font-size: 8.5pt;
    }

    .diary-table th,
    .diary-table td {
        padding: 2px 5px;
        border: 1px solid #777;
        line-height: 1.1;
    }

    .diary-table th {
        padding-top: 3px;
        padding-bottom: 3px;
    }

    .diary-writing-box {
        height: 24px;
    }

    .diary-notes {
        margin-top: 10px;
    }

    .notes-line {
        height: 18px;
    }

    .diary-disclaimer {
        margin-top: 10px;
        margin-bottom: 0;
        font-size: 7.5pt;
        line-height: 1.2;
    }

}