/* ---------- Tokens ---------- */
:root {
    --app-bg: #f5f6f4;
    --surface: #ffffff;
    --border: #e2e3df;
    --text: #1d1d1b;
    --text-secondary: #5c5b57;
    --text-muted: #85847f;
    --primary: #1f5f8b;
    --primary-hover: #194f74;
    --primary-soft: #e7f0f7;

    /* Chart series: validated categorical slots 1 and 2, plus violet for the single pulse series */
    --series-dia: #2a78d6;
    --series-sys: #eb6834;
    --series-pulse: #4a3aa7;

    /* Status: at or above / below the home threshold */
    --warning-bg: #fff4e0;
    --warning-text: #7a4a00;
    --good-bg: #e8f5ec;
    --good-text: #1d5e33;
    --afib: #c0392b;

    --header-height: 3.25rem;
    --bottom-nav-height: 3.75rem;

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--text);
    --bs-link-color-rgb: 31, 95, 139;
    --bs-link-hover-color-rgb: 25, 79, 116;
}

html, body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--app-bg);
    color: var(--text);
}

h1 { font-size: 1.5rem; font-weight: 650; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; font-weight: 650; }
h1:focus { outline: none; }

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-bg: var(--primary);
    --bs-btn-active-border-color: var(--primary);
}

.btn-link {
    --bs-btn-color: var(--primary);
    --bs-btn-hover-color: var(--primary-hover);
    --bs-btn-active-color: var(--primary-hover);
}

.form-control, .form-control:focus, .form-select, .form-check-input { background-color: var(--surface); }

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* Hide the number spinners; the numeric keyboard is enough. */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(31, 95, 139, .5);
}

.icon { vertical-align: -0.125em; flex-shrink: 0; }

/* ---------- Layout ---------- */
.app-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

    .app-header .app-container {
        display: flex;
        align-items: center;
        gap: 1rem;
        height: var(--header-height);
    }

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.brand-icon { color: #e34948; }

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .25rem;
}

    .header-actions form { margin: 0; }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

    .icon-button:hover { background: var(--app-bg); color: var(--text); }

.app-main {
    padding-top: 1.25rem;
    /* Leave room for the bottom navigation on phones */
    padding-bottom: calc(var(--bottom-nav-height) + 1.5rem + env(safe-area-inset-bottom));
}

.nav-item-link {
    display: flex;
    align-items: center;
    gap: .4rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
}

    .nav-item-link.active { color: var(--primary); }

/* Phones: bottom tab bar */
.top-nav { display: none; }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

    .bottom-nav .nav-item-link {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        gap: .15rem;
        height: var(--bottom-nav-height);
        font-size: .75rem;
    }

        .bottom-nav .nav-item-link .icon { font-size: 1.35rem; }

/* Tablets and desktop: links in the header */
@media (min-width: 768px) {
    .top-nav { display: flex; gap: 1.5rem; margin-left: 1rem; align-self: stretch; }
    .top-nav .nav-item-link { border-bottom: 2px solid transparent; }
    .top-nav .nav-item-link.active { border-bottom-color: var(--primary); }
    .bottom-nav { display: none; }
    .app-main { padding-bottom: 2rem; }
}

.narrow { max-width: 480px; margin: 0 auto; }

/* ---------- Panels ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.panel-title {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-secondary);
    margin-bottom: .75rem;
}

    .panel-title .unit,
    .panel-title a {
        text-transform: none;
        letter-spacing: 0;
    }

    .panel-title .unit { font-weight: 400; color: var(--text-muted); margin-left: .25rem; }
    .panel-title a { text-decoration: none; }

/* ---------- Reading entry ---------- */
.reading-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
}

.reading-field label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: .2rem;
}

.reading-field .unit { font-weight: 400; color: var(--text-muted); }

.reading-input {
    width: 100%;
    font-size: 1.75rem;
    font-weight: 600;
    text-align: center;
    padding: .5rem .25rem;
    font-variant-numeric: tabular-nums;
}

.reading-block + .reading-block {
    border-top: 1px dashed var(--border);
    margin-top: .75rem;
    padding-top: .75rem;
}

.reading-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .85rem;
    color: var(--text-secondary);
    margin-bottom: .35rem;
    min-height: 1.75rem;
}

.afib-check {
    margin-top: .5rem;
    min-height: 1.75rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding-left: 0;
}

    .afib-check .form-check-input {
        float: none;
        margin: 0;
        width: 1.25rem;
        height: 1.25rem;
        flex-shrink: 0;
    }

    .afib-check .form-check-label { font-size: .9rem; }

.afib-icon, .session-flag .icon { color: var(--afib); }

.average-box {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    background: var(--primary-soft);
    border-radius: .5rem;
    padding: .6rem .75rem;
    margin-top: .75rem;
}

/* ---------- Values and status ---------- */
.bp-value {
    font-weight: 650;
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pulse-value {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .75rem;
    font-weight: 600;
    border-radius: 1rem;
    padding: .1rem .5rem;
    white-space: nowrap;
}

    .status-badge.above { background: var(--warning-bg); color: var(--warning-text); }
    .status-badge.below { background: var(--good-bg); color: var(--good-text); }

.muted { color: var(--text-muted); }
.small-text { font-size: .85rem; }

/* ---------- Session lists ---------- */
.session-list { list-style: none; padding: 0; margin: 0; }

.session-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
}

    .session-row:last-child { border-bottom: 0; }

.session-time {
    width: 3.25rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    display: flex;
    flex-direction: column;
    font-size: .9rem;
    line-height: 1.2;
}

    .session-time .icon { color: var(--text-muted); font-size: .8rem; margin-top: .15rem; }

.session-main { flex: 1; min-width: 0; }

.session-detail { font-size: .8rem; color: var(--text-muted); }

.session-flag { font-size: .8rem; font-weight: 600; color: var(--text); }

/* The AFib flag and the note get their own full-width lines under the values. */
.session-extra {
    flex-basis: 100%;
    padding-left: calc(3.25rem + .75rem); /* line up with the values, past the time column */
    margin-top: -.5rem;
}

/* Notes wrap so they can be read in full. */
.session-note {
    font-size: .8rem;
    color: var(--text-secondary);
    font-style: italic;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.session-actions { display: flex; gap: .15rem; }

.day-heading {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 1rem 0 .25rem;
}

    .day-heading:first-child { margin-top: 0; }

/* ---------- Trends ---------- */
.range-picker { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
}

@media (min-width: 768px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-tile .stat-label { font-size: .8rem; color: var(--text-secondary); }
.stat-tile .stat-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-tile .stat-sub { font-size: .8rem; color: var(--text-muted); }

.chart-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .85rem; color: var(--text-secondary); margin-bottom: .25rem; }
.legend-swatch { display: inline-block; width: .9rem; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: .3rem; }
.legend-swatch.dashed { height: 0; border-top: 2px dashed var(--text-muted); }
.legend-swatch.vertical { width: 2px; height: .9rem; background: var(--afib); vertical-align: -0.15em; }

.table-report { font-variant-numeric: tabular-nums; --bs-table-bg: transparent; }
.table-report th { font-size: .8rem; color: var(--text-secondary); font-weight: 600; }

/* ---------- Toast ---------- */
.toast-saved {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--bottom-nav-height) + 1rem + env(safe-area-inset-bottom));
    z-index: 200;
    background: #1d1d1b;
    color: #fff;
    padding: .6rem 1rem;
    border-radius: .5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
    font-size: .9rem;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .toast-saved { bottom: 1.5rem; }
}

/* ---------- Used by the Identity pages ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; font-size: .85rem; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

    .blazor-error-boundary::after { content: "An error has occurred."; }

.darker-border-checkbox.form-check-input { border-color: #929292; }

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}
