:root {
    --bg: #eef2f3;
    --surface: #ffffff;
    --ink: #17242b;
    --muted: #5b6b73;
    --line: #dbe3e6;
    --accent: #0d8a8a;
    --accent-600: #0b7373;
    --danger: #c0392b;
    --success: #1e8e5a;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(23, 36, 43, .06), 0 6px 20px rgba(23, 36, 43, .05);
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

/* ---------------------------------------------------------- top bar */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -.01em;
    color: var(--ink);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    line-height: 1;
}

.nav { display: flex; align-items: center; gap: 1.1rem; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--ink); }
.logout-form { margin: 0; }

.linkbtn {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--muted);
    cursor: pointer;
}
.linkbtn:hover { color: var(--ink); }
.linkbtn.danger { color: var(--danger); }

/* ------------------------------------------------------------ layout */

.wrap { max-width: 880px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem 1.5rem;
    margin-bottom: 1.25rem;
}
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }

h1 { font-size: 1.5rem; letter-spacing: -.02em; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; letter-spacing: -.01em; margin: 0; }

.muted { color: var(--muted); }
.opt { color: var(--muted); font-weight: 400; font-size: .85em; }

/* ------------------------------------------------------------- forms */

form label {
    display: block;
    font-weight: 600;
    font-size: .92rem;
    margin-bottom: 1rem;
}
label.inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0 1.2rem 0 0; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select, textarea {
    display: block;
    width: 100%;
    margin-top: .35rem;
    padding: .55rem .65rem;
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}
textarea { resize: vertical; }

/* no spinner arrows on number fields — plain typing, numeric keypad on mobile */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.row { display: flex; gap: 1rem; align-items: flex-end; }
.row > label, .row > * { flex: 1; }

/* date-of-birth Year/Month/Day dropdowns */
.field { margin-bottom: 1rem; }
.field-label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .35rem; }
/* year-of-birth dropdown */
.year-picker { max-width: 8rem; }
.year-picker select { margin-top: 0; }

fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .35rem; }

/* input with a unit suffix */
.suffixed { position: relative; display: block; margin-top: .35rem; }
.suffixed input { margin-top: 0; padding-right: 3.4rem; }
.suffix {
    position: absolute;
    right: .6rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: .85rem;
    pointer-events: none;
}
.suffix-select {
    position: absolute;
    right: .35rem;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    margin: 0;
    padding: .2rem 1.4rem .2rem .4rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: .85rem;
}
.suffix-select:focus { outline: none; }

.form-actions { display: flex; gap: .75rem; align-items: center; }

/* ----------------------------------------------------------- buttons */

.btn {
    display: inline-block;
    padding: .6rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: .95rem;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
}
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-600); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--muted); }

/* ------------------------------------------------------------ flashes */

.flash {
    border-radius: 8px;
    padding: .7rem .9rem;
    margin-bottom: 1rem;
    font-size: .92rem;
    border: 1px solid transparent;
}
.flash-success { background: #e6f6ee; color: #14603c; border-color: #bfe6d1; }
.flash-error   { background: #fdeceb; color: #8f2820; border-color: #f4c7c2; }
.flash-info    { background: #eaf4f4; color: #0b5757; border-color: #c6e4e4; }

/* --------------------------------------------------------- dashboard */

.profile-summary .ps-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}
.profile-summary h1 { font-size: 1.35rem; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0 .8rem;
}

.empty { text-align: center; padding: 2.5rem 1.5rem; }
.empty p { color: var(--muted); margin: 0 0 1rem; }

.table-card { padding: 0; overflow: hidden; }
.table-card table { margin: 0; }

table.readings {
    width: 100%;
    border-collapse: collapse;
    font-size: .93rem;
}
table.readings th, table.readings td {
    text-align: left;
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
table.readings thead th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: #f7fafa;
}
table.readings tbody tr:last-child td { border-bottom: 0; }
table.readings tbody tr:hover { background: #f9fbfb; }

td.num, th.num {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}
.nowrap { white-space: nowrap; }
.time { display: block; color: var(--muted); font-size: .8rem; }
.notes-col { max-width: 16rem; }

.row-actions { display: flex; gap: .7rem; }
.row-actions a { color: var(--accent); text-decoration: none; }
.row-actions a:hover { text-decoration: underline; }
.inline-form { display: inline; margin: 0; }

/* ------------------------------------------------------------- footer */

.foot {
    text-align: center;
    color: var(--muted);
    font-size: .82rem;
    padding: 1.5rem;
}

/* ------------------------------------------------------------ mobile */

@media (max-width: 560px) {
    .row { flex-direction: column; gap: 0; align-items: stretch; }
    .section-head { flex-direction: column; align-items: stretch; }
    .section-head .btn { text-align: center; }
    .notes-col { display: none; }
    .profile-summary .ps-head { flex-direction: column; }
}

/* ------------------------------------------ expanded form + cards */

.form-wide { max-width: 560px; }

details {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: .8rem;
    background: #fcfdfd;
}
details > summary {
    cursor: pointer;
    padding: .7rem .9rem;
    font-weight: 600;
    font-size: .95rem;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
    content: "+";
    color: var(--muted);
    font-weight: 700;
    font-size: 1.1rem;
}
details[open] > summary::after { content: "–"; }
details[open] > summary { border-bottom: 1px solid var(--line); }
details > *:not(summary) { padding: 0 .9rem; }
details > *:not(summary):first-of-type { padding-top: .9rem; }
details > label:last-child,
details > fieldset:last-child,
details > .row:last-child { margin-bottom: .9rem; }

.unit-mini {
    width: auto;
    display: inline-block;
    margin: 0 0 0 .5rem;
    padding: .1rem 1.3rem .1rem .4rem;
    font-size: .8rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
}
.hint { color: var(--muted); font-size: .85rem; margin: .2rem 0 0; }

/* reading cards */
.reading-card { padding: 1rem 1.1rem; scroll-margin-top: 72px; }
.reading-card:target {
    box-shadow: 0 0 0 2px var(--accent), var(--shadow);
    animation: card-flash 2s ease-out 1;
}
@keyframes card-flash {
    0%   { background: #eaf7f6; }
    100% { background: var(--surface); }
}
.rc-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .8rem;
    padding-bottom: .7rem;
    border-bottom: 1px solid var(--line);
}
.rc-when strong { font-size: 1rem; }
.rc-head-right { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; justify-content: flex-end; }
.rc-head-right a { color: var(--accent); text-decoration: none; font-size: .9rem; }
.rc-head-right a:hover { text-decoration: underline; }

.bmi-badge {
    background: #eaf4f4;
    color: #0b5757;
    border: 1px solid #c6e4e4;
    border-radius: 999px;
    padding: .15rem .6rem;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .6rem .9rem;
}
.metric { display: flex; flex-direction: column; gap: .1rem; }
.metric-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.metric-val {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.02rem;
    font-weight: 600;
}

.rc-text { font-size: .9rem; margin: .7rem 0 0; }
.rc-text-label { color: var(--muted); font-weight: 600; }

/* --------------------------------------------------------- charts */

.chart-card { padding: 1.1rem 1.2rem 1.3rem; }
.chart-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .7rem;
}
.chart-head h2 { font-size: 1.1rem; }

/* segmented metric toggle on a chart */
.chart-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ct-btn {
    background: #fff;
    border: 0;
    padding: .35rem .85rem;
    font: inherit;
    font-size: .85rem;
    color: var(--muted);
    cursor: pointer;
}
.ct-btn + .ct-btn { border-left: 1px solid var(--line); }
.ct-btn.is-active { background: var(--accent); color: #fff; }
.ct-btn:hover:not(.is-active) { background: #f2f6f6; }

.chart { width: 100%; height: auto; display: block; margin-top: .3rem; }
.chart-axis { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
.chart-ref  { fill: #6f858c; font-size: 10px; font-family: var(--sans); }

.chart-legend { display: flex; flex-wrap: wrap; gap: .1rem 1rem; margin: .1rem 0 .2rem; }
.cl-item { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.cl-dot { width: .7rem; height: .7rem; border-radius: 50%; display: inline-block; }

.stat-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: .5rem .8rem;
    padding: .3rem 0 .9rem;
    margin-bottom: .3rem;
    border-bottom: 1px solid var(--line);
}
.stat { display: flex; flex-direction: column; gap: .1rem; }
.stat-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.stat-val {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.05rem;
    font-weight: 600;
}
