/* ------------------------------------------------------------------
   Blood sugar log - dashboard styles

   Visual direction: a lab worksheet. Cool paper stock, a faint printed
   grid, hairline rules, and every number set in a monospaced face so
   columns line up the way they would on a printed report. The one loud
   element is the time-in-range ribbon.
   ------------------------------------------------------------------ */

:root {
    --paper:     #f2f3ee;
    --panel:     #fbfbf8;
    --grid:      #e5e8de;
    --rule:      #d6dacd;
    --rule-firm: #b9c0ae;
    --ink:       #171c18;
    --ink-soft:  #6a7166;
    --ink-faint: #9aa094;

    /* Two-sided scale: the low side runs amber, the high side runs brick,
       and each side gets a darker shade for the danger band. */
    --moss:      #3f6f52;
    --moss-soft: #dce7de;
    --amber:     #b8761b;
    --amber-deep:#7d4508;
    --brick:     #a8452f;
    --brick-deep:#5f1f13;
    --slate:     #2f5d7a;

    --on-band:   #ffffff;   /* text sitting on a coloured ribbon segment */

    --radius: 3px;

    --font-data: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono",
                 Menlo, Consolas, "Liberation Mono", monospace;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper:     #131613;
        --panel:     #1a1e1a;
        --grid:      #22271f;
        --rule:      #2e342d;
        --rule-firm: #444c42;
        --ink:       #e7eae2;
        --ink-soft:  #979e91;
        --ink-faint: #6d746a;

        --moss:      #6ea87f;
        --moss-soft: #22301f;
        --amber:     #d6a04a;
        --amber-deep:#a06d1c;
        --brick:     #d4735a;
        --brick-deep:#9c3c26;
        --slate:     #74a8c9;

        /* Dark-mode band colours are light, so band text flips to dark. */
        --on-band:   #131613;
    }
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    padding: 0;
    background-color: var(--paper);
    /* The printed grid. Two hairlines, deliberately faint. */
    background-image:
        linear-gradient(to right, var(--grid) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
    background-size: 28px 28px;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
}

.sheet {
    max-width: 1060px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

/* ---------- Shared type ---------- */

.eyebrow {
    margin: 0;
    font-family: var(--font-data);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.mono   { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.muted  { color: var(--ink-faint); }
.nowrap { white-space: nowrap; }
.num    { text-align: right; }

code {
    font-family: var(--font-data);
    font-size: 0.9em;
    background: var(--grid);
    padding: 1px 5px;
    border-radius: var(--radius);
}

/* ---------- Login gate ---------- */

.gate-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.gate {
    width: 100%;
    max-width: 340px;
    background: var(--panel);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--moss);
    padding: 32px 28px;
}

.gate-title {
    margin: 6px 0 24px;
    font-family: var(--font-data);
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.gate-form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
    font-family: var(--font-data);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.field-input {
    font-family: var(--font-data);
    font-size: 15px;
    padding: 10px 12px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule-firm);
    border-radius: var(--radius);
}

.field-input:focus-visible {
    outline: 2px solid var(--moss);
    outline-offset: 1px;
}

.gate-error {
    margin: 0;
    font-size: 13px;
    color: var(--brick);
}

.btn {
    display: inline-block;
    font-family: var(--font-data);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    text-align: center;
    padding: 10px 16px;
    color: var(--paper);
    background: var(--ink);
    border: 1px solid var(--ink);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.btn:hover { background: var(--moss); border-color: var(--moss); }
.btn:focus-visible { outline: 2px solid var(--moss); outline-offset: 2px; }

.btn-quiet {
    color: var(--ink-soft);
    background: transparent;
    border-color: var(--rule-firm);
    padding: 7px 12px;
}

.btn-quiet:hover {
    color: var(--panel);
    background: var(--ink);
    border-color: var(--ink);
}

/* ---------- Masthead ---------- */

.masthead {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    justify-content: space-between;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--ink);
}

.masthead-title {
    margin: 2px 0 0;
    font-family: var(--font-data);
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.masthead-actions { display: flex; gap: 8px; }

/* ---------- Range selector ---------- */

.ranges {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 0 0 26px;
    border-bottom: 1px solid var(--rule);
}

.range {
    font-family: var(--font-data);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-decoration: none;
    padding: 9px 14px;
    color: var(--ink-soft);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.range:hover { color: var(--ink); }

.range-on {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--moss);
}

.range:focus-visible { outline: 2px solid var(--moss); outline-offset: -2px; }

/* ---------- Readout ---------- */

.readout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 28px 40px;
    padding: 22px 24px;
    margin-bottom: 22px;
    background: var(--panel);
    border: 1px solid var(--rule);
    border-left: 4px solid var(--rule-firm);
}

.readout-main {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.readout-value {
    font-family: var(--font-data);
    font-size: 60px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.readout-unit {
    font-family: var(--font-data);
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.bucket-inrange  .readout-value { color: var(--moss); }
.bucket-low      .readout-value { color: var(--amber); }
.bucket-verylow  .readout-value { color: var(--amber-deep); }
.bucket-high     .readout-value { color: var(--brick); }
.bucket-veryhigh .readout-value { color: var(--brick-deep); }

/* The left rule of the strip picks up the reading's own colour. */
.readout.bucket-inrange  { border-left-color: var(--moss); }
.readout.bucket-low      { border-left-color: var(--amber); }
.readout.bucket-verylow  { border-left-color: var(--amber-deep); }
.readout.bucket-high     { border-left-color: var(--brick); }
.readout.bucket-veryhigh { border-left-color: var(--brick-deep); }

.readout-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 32px;
    margin: 0;
}

.readout-meta dt {
    font-family: var(--font-data);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.readout-meta dd {
    margin: 2px 0 0;
    font-family: var(--font-data);
    font-size: 15px;
}

/* ---------- Panels ---------- */

.panel {
    background: var(--panel);
    border: 1px solid var(--rule);
    padding: 20px 22px 22px;
    margin-bottom: 22px;
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    align-items: baseline;
    justify-content: space-between;
    padding-bottom: 12px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--rule);
}

.panel-title {
    margin: 0;
    font-family: var(--font-data);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.panel-note {
    margin: 0;
    font-family: var(--font-data);
    font-size: 12px;
    color: var(--ink-faint);
}

.empty p { margin: 0; color: var(--ink-soft); max-width: 52ch; }

/* ---------- Time in range ribbon (the signature element) ---------- */

.ribbon {
    display: flex;
    height: 46px;
    overflow: hidden;
    border: 1px solid var(--rule-firm);
}

.ribbon-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2px;
    flex-basis: 0;
    border-right: 1px solid var(--panel);
}

.ribbon-seg:last-child { border-right: 0; }

.ribbon-pct {
    font-family: var(--font-data);
    font-size: 12px;
    font-weight: 600;
    color: var(--on-band);
    letter-spacing: 0.02em;
}

.seg-inrange  { background: var(--moss); }
.seg-low      { background: var(--amber); }
.seg-verylow  { background: var(--amber-deep); }
.seg-high     { background: var(--brick); }
.seg-veryhigh { background: var(--brick-deep); }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    list-style: none;
    margin: 18px 0 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 170px;
    padding: 10px 14px 10px 0;
    border-right: 1px solid var(--rule);
}

.legend-item:last-child { border-right: 0; }

.swatch {
    width: 10px;
    height: 10px;
    flex: none;
    border-radius: 1px;
}

.legend-label { font-size: 13px; color: var(--ink-soft); }

.legend-num {
    margin-left: auto;
    font-family: var(--font-data);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.legend-sub {
    font-family: var(--font-data);
    font-size: 11px;
    color: var(--ink-faint);
    min-width: 2.5ch;
    text-align: right;
}

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

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
    gap: 1px;
    margin-bottom: 22px;
    background: var(--rule);
    border: 1px solid var(--rule);
}

.card {
    background: var(--panel);
    padding: 16px 18px 18px;
}

.card-label {
    margin: 0 0 10px;
    font-family: var(--font-data);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.card-value {
    margin: 0;
    font-family: var(--font-data);
    font-size: 30px;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.card-unit {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

.card-sub {
    margin: 8px 0 0;
    font-family: var(--font-data);
    font-size: 12px;
    color: var(--ink-soft);
}

.card-accent { box-shadow: inset 3px 0 0 var(--slate); }
.card-accent .card-value { color: var(--slate); }

/* ---------- Charts ---------- */

.canvas-wrap {
    position: relative;
    width: 100%;
    height: 320px;
}

.canvas-short { height: 190px; }

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Cards that show a pair of numbers rather than one headline figure. */
.card-pair { display: flex; align-items: baseline; gap: 8px; }

.card-joiner {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

/* ---------- Tables ---------- */

/* Narrow screens scroll the table sideways rather than crushing columns. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table thead th {
    padding: 0 10px 8px;
    font-family: var(--font-data);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-align: left;
    color: var(--ink-faint);
    border-bottom: 1px solid var(--rule-firm);
}

.table thead th.num { text-align: right; }

.table tbody td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

.table tbody tr:last-child td { border-bottom: 0; }

.table td.num { text-align: right; white-space: nowrap; }

.pip {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 1px;
    vertical-align: baseline;
}

.pip-inrange  { background: var(--moss); }
.pip-low      { background: var(--amber); }
.pip-verylow  { background: var(--amber-deep); }
.pip-high     { background: var(--brick); }
.pip-veryhigh { background: var(--brick-deep); }

.delta-down { color: var(--moss); }
.delta-up   { color: var(--brick); }
.delta-flat { color: var(--ink-faint); }

/* Chart panel sits above its own table without a doubled gap. */
.panel .canvas-wrap + .table { margin-top: 20px; }

/* ---------- Notes ---------- */

/* Set like marginalia: the date sits in its own narrow column, the way a
   date would sit in the margin of a paper logbook. */
.notes {
    list-style: none;
    margin: 0;
    padding: 0;
}

.note {
    display: grid;
    grid-template-columns: 62px 1fr;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--rule);
}

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

.note-when {
    font-family: var(--font-data);
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-faint);
    white-space: nowrap;
}

.note-body {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
}

/* ---------- Colophon ---------- */

.colophon {
    margin-top: 34px;
    padding-top: 16px;
    border-top: 1px solid var(--rule);
}

.colophon p {
    margin: 0;
    max-width: 62ch;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-faint);
}

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

@media (max-width: 640px) {
    body { background-size: 20px 20px; }
    .sheet { padding: 20px 12px 44px; }
    .masthead-title { font-size: 21px; }

    .readout { gap: 18px 26px; padding: 18px; }
    .readout-value { font-size: 46px; }

    /* Two even columns beats a ragged wrap. */
    .readout-meta {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px 20px;
        width: 100%;
    }

    .panel { padding: 16px 14px 18px; }
    .canvas-wrap { height: 260px; }

    .legend-item { flex-basis: 100%; border-right: 0; border-bottom: 1px solid var(--rule); }
    .legend-item:last-child { border-bottom: 0; }

    .table { font-size: 13px; min-width: 420px; }
    .table tbody td { padding: 8px 6px; }
    .card-value { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
