/* ==========================================================================
   Emberly UI
   Loaded after bootstrap.min.css, which is kept only for the grid, the
   utilities and the date-time picker. Everything visual lives here.

   1. Tokens          5. Cards & page titles    9. Charts
   2. Base            6. Tables                10. Dashboard
   3. App shell       7. Forms & buttons       11. Logbook & pickers
   4. Navigation      8. Feedback              12. Public pages, 13. Helpers
   ========================================================================== */


/* 1. Tokens --------------------------------------------------------------- */

:root {
    /* Surfaces */
    --canvas: #dfe0f2;
    --surface: #ffffff;
    --surface-sunken: #f3f4fb;
    --line: #d6d8eb;
    --line-strong: #bcbfdb;

    /* Text */
    --ink: #23253a;
    --ink-title: #353850;
    --ink-soft: #474a66;
    --muted: #6f7290;

    /* Brand: periwinkle for identity and primary actions, teal for data and links */
    --brand: #5661b3;
    --brand-deep: #434d99;
    --brand-tint: #eceefa;
    --teal: #0b7a78;
    --teal-deep: #075e5c;
    --teal-tint: #e4f3f2;

    /* Entry kinds */
    --k-glucose: #0b7a78;
    --k-insulin: #3f63d8;
    --k-carbs: #d9900a;
    --k-event: #8a4fd3;
    --k-scenario: #5b6080;

    /* States */
    --ok: #1f8a4c;
    --ok-tint: #e6f5ec;
    --warn: #c77700;
    --warn-tint: #fdf1dc;
    --bad: #cf3a2f;
    --bad-tint: #fdeae8;

    --radius-s: 8px;
    --radius: 12px;
    --radius-l: 18px;
    --shadow: 0 1px 2px rgba(35, 37, 58, 0.04), 0 8px 24px -12px rgba(35, 37, 58, 0.12);
    --shadow-pop: 0 12px 40px -8px rgba(35, 37, 58, 0.28);

    --font-ui: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Poppins", "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --sidebar-w: 248px;
    --topbar-h: 56px;
}


/* 2. Base ----------------------------------------------------------------- */

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

body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5 {
    font-family: var(--font-display);
    font-weight: 650;
    letter-spacing: -0.015em;
    color: var(--ink-title);
    margin: 0 0 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.05rem; }

p { margin: 0 0 0.75em; }

a {
    color: var(--teal);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--teal-deep);
    text-decoration: underline;
    text-underline-offset: 2px;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1rem 0;
}

small, .small { color: var(--muted); }

b, strong { font-weight: 650; }

:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}


/* 3. App shell ------------------------------------------------------------ */

.app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 16px 32px;
}

.app-footer {
    padding: 20px 16px 28px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

.app-footer a { color: var(--ink-soft); }

/* Brand */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-family: "Nunito", var(--font-display);
    font-size: 29px;
    font-weight: 900;
    letter-spacing: -0.01em;
    color: var(--brand);
    line-height: 1;
}

.brand:hover {
    color: var(--brand);
    text-decoration: none;
}

.brand-mark {
    width: 30px;
    height: 30px;
    background: url("/static/img/emberly_mark.svg") center / contain no-repeat;
    flex: none;
}

/* Top bar: phones and tablets, and every public page */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(223, 224, 242, 0.86);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--line);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Quick add: one tap from anywhere */
.quick-add {
    display: flex;
    align-items: center;
    gap: 7px;
}

.quick-add-btn {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--kind);
    background: var(--surface);
    border: 1px solid var(--line);
    touch-action: manipulation;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.quick-add-btn .icon {
    width: 18px;
    height: 18px;
}

.quick-add-btn:hover {
    color: var(--kind);
    border-color: var(--kind);
}

.quick-add-btn:active { transform: scale(0.94); }

.kind-glucose { --kind: var(--k-glucose); }
.kind-insulin { --kind: var(--k-insulin); }
.kind-carbs { --kind: var(--k-carbs); }
.kind-event { --kind: var(--k-event); }
.kind-scenario { --kind: var(--k-scenario); }


/* 4. Navigation ----------------------------------------------------------- */

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1045;
    width: min(86vw, 300px);
    padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(14px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    transform: translateX(-102%);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.nav-open .sidebar {
    transform: none;
    box-shadow: var(--shadow-pop);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px 14px;
}

.nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(35, 37, 58, 0.38);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.nav-open .nav-scrim {
    opacity: 1;
    pointer-events: auto;
}

.nav-label {
    padding: 14px 12px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-link-em {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 550;
    color: var(--ink-soft);
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-link-em .icon { color: var(--muted); }

.nav-link-em:hover {
    background: var(--surface-sunken);
    color: var(--ink);
    text-decoration: none;
}

.nav-link-em.is-active {
    background: var(--brand-tint);
    color: var(--brand-deep);
}

.nav-link-em.is-active .icon { color: var(--brand); }

.nav-link-em[class*="kind-"] .icon { color: var(--kind); }

.icon-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn:hover { background: var(--surface-sunken); }

/* The menu button: a white tab sticking out of the left edge of the screen, as the edge of the
   (white) menu which it pulls in, with the logo and the menu icon */
.menu-tab {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 42px;
    min-width: 0;
    margin-left: -16px;
    padding: 0 12px 0 calc(16px + env(safe-area-inset-left, 0px));
    border: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 var(--radius-l) var(--radius-l) 0;
    background: var(--surface);
    box-shadow: 2px 1px 6px -2px rgba(35, 37, 58, 0.18);
    color: var(--ink-soft);
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.1s ease, color 0.15s ease;
}

.menu-tab .icon { flex: none; }

.menu-tab:hover { color: var(--brand); }

.menu-tab:active { transform: translateX(3px); }

@media (min-width: 992px) {
    .app--member { padding-left: var(--sidebar-w); }

    .app--member .sidebar {
        width: var(--sidebar-w);
        transform: none;
        box-shadow: none;
        z-index: 1010;
    }

    .app--member .topbar,
    .app--member .nav-scrim,
    .sidebar .icon-btn {
        display: none;
    }

    .content { padding: 28px 32px 48px; }
}

/* Public pages have no sidebar: links sit in the top bar */
.app--public .sidebar,
.app--public .nav-scrim {
    display: none;
}

/* Public pages (login, register, terms...): white top bar */
.app--public .topbar {
    background: rgba(255, 255, 255, 0.9);
    border-bottom-color: var(--line-strong);
}


/* 5. Cards & page titles -------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow);
}

.card-body { padding: 20px; }

.card > .card-body + .card-body { padding-top: 4px; }

/* Bootstrap's mt-5 is used throughout as the gap between cards */
.mt-5, .my-5 { margin-top: 16px !important; }

/* Page title: the old "path bar" card becomes a plain heading */
.title-bar { margin-bottom: 14px; }

.title-bar .card {
    background: none;
    border: 0;
    box-shadow: none;
}

.title-bar + br { display: none; }

.title-bar .card-body { padding-left: 2px; padding-right: 2px; }

.pathbar {
    padding: 4px 2px 0;
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--muted);
}

.pathbar a { color: #2c2e45; }

.pathbar a:hover {
    color: var(--brand);
    text-decoration: none;
}

.pathbar font {
    font-size: 0.62em !important;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.pathbar .title-action {
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand);
    color: #fff;
}

.pathbar .title-action:hover {
    background: var(--brand-deep);
    color: #fff;
}

/* Section heading inside a card */
.section-title,
.card-body > font[style*="font-weight:700"],
.card-body > div > font[style*="font-weight:700"] {
    display: inline-block;
    font-family: var(--font-display);
    font-size: 17px !important;
    font-weight: 650 !important;
    letter-spacing: -0.015em;
    color: var(--ink-title);
}

.card-body > h3 {
    font-size: 1.15rem;
    margin-bottom: 4px;
}

.card-body h1,
.card-body h2 {
    margin-top: 0;
}


/* 6. Tables --------------------------------------------------------------- */

table { border-collapse: collapse; }

table.dashboard {
    margin-top: 10px;
    border: 0;
    max-width: 100%;
}

table.dashboard td {
    padding: 11px 16px 11px 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

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

table.dashboard td:last-child { padding-right: 0; }

/* Key/value tables: the label column */
table.dashboard:not(.is-list) > tbody > tr > td:first-child {
    color: var(--ink-soft);
    padding-right: 28px;
}

table.dashboard-with-description td:first-child { max-width: 350px; }

/* List tables: header row + full width */
table.dashboard.is-list { width: 100%; }

table.dashboard.is-list > tbody > tr:first-child > td {
    padding-top: 4px;
    padding-bottom: 8px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom-color: var(--line-strong);
}

table.dashboard.is-list > tbody > tr:first-child > td b { font-weight: inherit; }

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.clickable-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.clickable-row:hover { background-color: var(--surface-sunken); }

table.borderless td {
    border: 0 !important;
    padding: 2px 6px 2px 0 !important;
}

table.dashboard_noborder,
table.dashboard_noborder_padded {
    border: 0;
    margin-top: 10px;
}

table.dashboard_noborder td {
    border: 0;
    padding: 1px 1px 1px 5px;
}

table.dashboard_noborder_padded td {
    border: 0;
    padding: 10px;
}

table.noborder td {
    padding: 5px;
    border: 0;
}

table.scenario {
    margin-top: 10px;
    border: 0;
}

table.scenario td {
    padding: 5px;
    border: 0;
}


/* 7. Forms & buttons ------------------------------------------------------ */

input, select, textarea, button {
    font-family: inherit;
    /* 16px keeps iOS from zooming the page when a field gets focus */
    font-size: 16px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="username"],
input:not([type]),
select,
textarea,
.form-control {
    height: 38px;
    padding: 6px 11px;
    color: var(--ink);
    background-color: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    box-shadow: none;
    max-width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { height: auto; }

select {
    padding-right: 30px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f7290' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

input:focus,
select:focus,
textarea:focus,
.form-control:focus {
    outline: 0;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(11, 122, 120, 0.16);
}

input:disabled,
select:disabled,
textarea:disabled {
    color: var(--ink);
    -webkit-text-fill-color: var(--ink);
    opacity: 1;
    background-color: var(--surface-sunken);
    border-color: var(--line);
}

input::placeholder { color: #a3a6bf; }

input[type="checkbox"],
input[type="radio"] {
    width: 18px;
    height: 18px;
    vertical-align: -3px;
    accent-color: var(--teal);
}

.generic_input {
    width: 320px;
    max-width: 100%;
}

/* Buttons. Bare submit inputs and Bootstrap .btn share one look. */
.btn,
button.timenav,
.step-btn,
.preset-btn,
input[type="submit"],
input[type="button"],
input[type="reset"],
button[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    margin: 0;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    box-shadow: none;
    cursor: pointer;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:hover,
button.timenav:hover,
.step-btn:hover,
.preset-btn:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
button[type="submit"]:hover {
    background: var(--surface-sunken);
    border-color: var(--ink-soft);
    color: var(--ink);
    text-decoration: none;
}

.btn:active,
button.timenav:active,
.step-btn:active,
.preset-btn:active,
input[type="submit"]:active,
button[type="submit"]:active {
    transform: scale(0.97);
}

.btn:focus,
.btn.focus { box-shadow: 0 0 0 3px rgba(11, 122, 120, 0.2); }

/* Primary action: the one that commits a form */
.btn-primary,
.btn-success,
.btn-info,
input[type="submit"]:not([name="timenav"]),
button[type="submit"]:not(.timenav) {
    color: #fff;
    background: var(--brand);
    border-color: var(--brand);
}

.btn-primary:hover,
.btn-success:hover,
.btn-info:hover,
.btn-primary:not(:disabled):not(.disabled):active,
.btn-success:not(:disabled):not(.disabled):active,
.btn-info:not(:disabled):not(.disabled):active,
input[type="submit"]:not([name="timenav"]):hover,
button[type="submit"]:not(.timenav):hover {
    color: #fff;
    background: var(--brand-deep);
    border-color: var(--brand-deep);
}

.btn-secondary,
.btn-default,
.btn-quiet,
input[type="submit"].btn-quiet {
    color: var(--ink);
    background: var(--surface);
    border-color: var(--line-strong);
}

.btn-secondary:hover,
.btn-default:hover,
.btn-quiet:hover,
input[type="submit"].btn-quiet:hover {
    color: var(--ink);
    background: var(--surface-sunken);
    border-color: var(--ink-soft);
}

.btn-lg {
    height: 46px;
    padding: 0 22px;
    font-size: 16px;
    border-radius: var(--radius);
}

.btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 13.5px;
}

.btn-block { display: flex; width: 100%; }

/* Time navigation chips */
button.timenav {
    height: 32px;
    padding: 0 12px;
    font-size: 13.5px;
    border-radius: 999px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.chip-row > input[type="submit"] {
    height: 32px;
    padding: 0 12px;
    font-size: 13.5px;
    border-radius: 999px;
}

.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
}

.segmented > * {
    padding: 4px 12px;
    border-radius: 999px;
    color: var(--ink-soft);
}

.segmented > a:hover {
    color: var(--ink);
    text-decoration: none;
}

.segmented > .is-current {
    background: var(--ink);
    color: #fff;
}

.field-label {
    display: block;
    margin-bottom: 4px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.field-hint,
table.dashboard div[style*="font-style: italic"] {
    font-size: 13px !important;
    font-style: normal !important;
    color: var(--muted);
    line-height: 1.4;
}

/* Filter / navigation toolbars */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px 24px;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

.toolbar .form-group { margin: 0; }

.toolbar .input-group.date { width: auto; }

.date-input { width: 128px; }

.input-group.date {
    position: relative;
    flex-wrap: nowrap;
    align-items: center;
}

/* The picker positions itself against this addon, so it must stay in the DOM */
.input-group-addon {
    width: 38px;
    height: 38px;
    margin-left: -1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    color: var(--muted);
    background: var(--surface-sunken);
    border: 1px solid var(--line-strong);
    border-radius: 0 var(--radius-s) var(--radius-s) 0;
    cursor: pointer;
}

.input-group-addon .icon {
    width: 17px;
    height: 17px;
}

.input-group.date > .form-control {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group.date > .date-input { flex: 0 0 118px; }


/* 8. Feedback ------------------------------------------------------------- */

.alert {
    padding: 10px 14px;
    border: 0;
    border-radius: var(--radius);
    font-weight: 550;
}

.alert-success {
    color: var(--ok);
    background: var(--ok-tint);
}

.alert-danger {
    color: var(--bad);
    background: var(--bad-tint);
}

.alert-warning,
.alert-info {
    color: var(--warn);
    background: var(--warn-tint);
}

.centerbox {
    max-width: 400px;
    margin: 0 auto;
}

.centerbox-error,
.centerbox-success {
    max-width: 420px;
    margin: 0 auto 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    text-align: center;
    font-weight: 600;
}

.centerbox-error {
    color: var(--bad);
    background: var(--bad-tint);
}

.centerbox-success {
    color: var(--ok);
    background: var(--ok-tint);
}

.badge-state {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.5;
}

.badge-state.is-clean { color: var(--ok); background: var(--ok-tint); }
.badge-state.is-dirty { color: var(--warn); background: var(--warn-tint); }
.badge-state.is-ongoing { color: var(--ink-soft); background: var(--surface-sunken); box-shadow: inset 0 0 0 1px var(--line); }

.cell-unsure {
    background: var(--warn-tint);
    box-shadow: inset 3px 0 0 var(--k-carbs);
    padding-left: 10px !important;
}

/* Page-leaving loader */
@keyframes spin {
    to { transform: rotate(360deg); }
}

#navigate-away-loader {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand);
    background: rgba(223, 224, 242, 0.72);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    transition: opacity 0.3s ease-in-out;
    visibility: hidden;
    pointer-events: none;
}

#navigate-away-loader > svg {
    width: 44px;
    height: 44px;
    animation: spin 0.9s infinite linear;
}


/* 9. Charts --------------------------------------------------------------- */

.glucose-data-menu { padding-bottom: 8px; }

.glucose-data-graphs { padding-top: 8px; }

.dygraph-legend {
    font-family: var(--font-ui);
    font-size: 12px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border-radius: var(--radius-s);
}

.dygraph-axis-label {
    font-family: var(--font-ui);
    font-size: 11.5px;
    color: var(--muted);
}

.dygraph-title,
.dygraph-label {
    font-family: var(--font-ui);
    color: var(--ink-soft);
}

.chart-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.chart-note {
    font-size: 13px;
    color: var(--muted);
}


/* 10. Dashboard ----------------------------------------------------------- */

.dash-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 768px) {
    .dash-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
}

.dash-card { min-height: 240px; }

.dash-card .card-body { height: 100%; }

.card-kicker {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Current glucose */
.glucose-now {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
}

.glucose-reading {
    display: flex;
    align-items: baseline;
    gap: 10px;
    line-height: 1;
}

.glucose-value {
    font-family: var(--font-display);
    font-size: clamp(64px, 11vw, 92px);
    font-weight: 700;
    letter-spacing: -0.045em;
    color: var(--ink);
    min-width: 1.6ch;
}

.glucose-value.is-stale,
.glucose-value .is-stale { color: #b7bad2; }

.glucose-value .glucose-range {
    display: block;
    margin-top: 6px;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--muted);
}

.glucose-unit {
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
}

.glucose-age {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--muted);
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px var(--ok-tint);
    vertical-align: 1px;
}

/* Trend arrows: 15 minutes ago, now, forecast */
.trends {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.trend {
    padding: 10px 6px 8px;
    border-radius: var(--radius);
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.trend-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.trend-body {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
}

.trend-arrow {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--c, #b7bad2);
    border: 2px solid currentColor;
}

.trend-arrow .icon {
    width: 20px;
    height: 20px;
    stroke-width: 2.4;
    transform: rotate(var(--r, 0deg));
    transition: transform 0.4s ease;
}

.trend-arrow.is-idle { border-style: dashed; }

.trend-arrow.is-idle .icon { visibility: hidden; }

.trend-value {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--c, #b7bad2);
}

/* Stat tiles */
.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.stat {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    min-width: 0;
}

.stat-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat-value {
    margin-top: 2px;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    min-height: 29px;
}

.latest-event {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

/* The latest event and the small GMI chart share the row, at any width */
.latest-event-info {
    flex: 1 1 auto;
    min-width: 0;
}

.gmi-days {
    flex: none;
    color: inherit;
}

.gmi-days:hover { color: inherit; text-decoration: none; }

.gmi-days-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.gmi-day {
    width: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.gmi-day-value {
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
}

.gmi-day-track {
    width: 16px;
    height: 56px;
    display: flex;
    align-items: flex-end;
    border-bottom: 1px solid var(--line-strong);
}

.gmi-day-bar {
    width: 100%;
    border-radius: 4px 4px 0 0;
    background: var(--brand);
    transition: background 0.12s ease;
}

.gmi-days:hover .gmi-day-bar { background: var(--brand-deep); }

.gmi-day-label {
    font-size: 11px;
    line-height: 1.2;
    color: var(--muted);
}

.latest-event-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 650;
}

.latest-event-meta {
    margin-top: 2px;
    color: var(--ink-soft);
}

.plot-box {
    display: block;
    text-align: left;
}


/* 11. Logbook & pickers --------------------------------------------------- */

/* Entry form: a narrow card of label/control rows */
.entry-form {
    max-width: 460px;
    margin: 0 auto;
    text-align: left;
}

.entry-form table.dashboard { width: 100%; }

.entry-form table.dashboard td { padding: 14px 0; }

.entry-form table.dashboard td:first-child {
    width: 120px;
    padding-right: 16px;
    vertical-align: top;
    padding-top: 22px;
}

.entry-form table.dashboard td:first-child font { color: var(--muted); }

.entry-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.entry-actions input[type="submit"],
.entry-actions .btn {
    height: 46px;
    padding: 0 26px;
    font-size: 16px;
    border-radius: var(--radius);
}

.entry-actions .is-main { flex: 1; }

input[type="submit"].is-danger,
input[type="submit"].is-danger:hover { color: var(--bad); }

.logbook-heading { margin-bottom: 4px; }

.logbook-text-input { width: 100%; }

.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stepper .logbook-text-input {
    width: 96px;
    height: 46px;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    letter-spacing: -0.02em;
}

.step-btn {
    width: 46px;
    height: 46px;
    padding: 0;
    font-size: 22px;
    font-weight: 500;
    border-radius: var(--radius);
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.preset-row .preset-break { width: 100%; height: 0; }

.preset-btn {
    display: none;
    min-width: 48px;
    height: 38px;
    padding: 0 10px;
    font-size: 15px;
    border-radius: 999px;
}

.absorption-btn { display: inline-flex; }

.absorption-btn-active,
.absorption-btn-active:hover {
    color: #fff;
    background: var(--ink);
    border-color: var(--ink);
}

.logbook-checkbox {
    width: 24px !important;
    height: 24px !important;
    cursor: pointer;
}

@media (max-width: 767px) {
    .preset-btn { display: inline-flex; }

    .logbook-heading { display: none; }
}

/* "What do you want to log?" tiles */
.add-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    max-width: 560px;
    margin: 0 auto;
}

.add-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: 18px;
    border-radius: var(--radius-l);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: 17px;
    font-weight: 650;
    transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.add-tile:hover {
    color: var(--ink);
    text-decoration: none;
    border-color: var(--kind);
    box-shadow: var(--shadow);
}

.add-tile:active { transform: scale(0.98); }

.add-tile-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--kind);
}

.add-tile-icon .icon {
    width: 22px;
    height: 22px;
}

.add-tile small {
    display: block;
    font-size: 13px;
    font-weight: 500;
}

/* Logbook section headings carry their kind colour */
.kind-title {
    display: flex;
    align-items: center;
    gap: 9px;
}

.kind-title::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--kind, var(--muted));
}

/* Date-time picker */
.bootstrap-datetimepicker-widget.dropdown-menu {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-pop);
    font-family: var(--font-ui);
}

.bootstrap-datetimepicker-widget.dropdown-menu::before,
.bootstrap-datetimepicker-widget.dropdown-menu::after {
    display: none;
}

.bootstrap-datetimepicker-widget table td,
.bootstrap-datetimepicker-widget table th {
    border: 0;
    border-radius: var(--radius-s);
}

.bootstrap-datetimepicker-widget table th {
    font-weight: 650;
    color: var(--ink-soft);
}

.bootstrap-datetimepicker-widget table td.day:hover,
.bootstrap-datetimepicker-widget table td.hour:hover,
.bootstrap-datetimepicker-widget table td.minute:hover,
.bootstrap-datetimepicker-widget table td span:hover,
.bootstrap-datetimepicker-widget table thead tr:first-child th:hover {
    background: var(--surface-sunken);
}

.bootstrap-datetimepicker-widget table td.active,
.bootstrap-datetimepicker-widget table td.active:hover,
.bootstrap-datetimepicker-widget table td span.active {
    background-color: var(--ink);
    color: #fff;
    text-shadow: none;
}

.bootstrap-datetimepicker-widget table td.today::before {
    border-bottom-color: var(--brand);
}

.bootstrap-datetimepicker-widget a,
.bootstrap-datetimepicker-widget a:hover {
    color: var(--ink);
    text-decoration: none;
}

.bootstrap-datetimepicker-widget .btn {
    border: 0;
    background: none;
}

.bootstrap-datetimepicker-widget .dp-ok-btn {
    margin-top: 8px;
    height: 40px;
    color: #fff;
    background: var(--brand);
}

.picker-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(35, 37, 58, 0.45);
}


/* 12. Public pages -------------------------------------------------------- */

.auth-card {
    max-width: 440px;
    margin: 6vh auto 0;
}

.auth-card .card-body { padding: 28px; }

.auth-card h1 {
    font-size: 1.75rem;
    margin-bottom: 4px;
}

.auth-lead {
    color: var(--muted);
    margin-bottom: 20px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="username"] {
    width: 100%;
    height: 46px;
}

.auth-form input[type="submit"] {
    height: 46px;
    margin-top: 8px;
    font-size: 16px;
    border-radius: var(--radius);
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 6px 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.auth-note {
    margin: 18px 0 0;
    font-size: 13.5px;
    color: var(--muted);
}

.check-line {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 4px 0;
    font-size: 14px;
    text-align: left;
}

.check-line input { margin-top: 2px; flex: none; }

/* Landing */
.hero {
    max-width: 720px;
    margin: 0 auto;
    padding: 9vh 0 6vh;
    text-align: center;
}

/* The home page: white, with only the log in button at the top, and the logo as in the bar */
body:has(.hero) { background: var(--surface); }

.app--public:has(.hero) .topbar {
    background: transparent;
    border-bottom: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    justify-content: flex-end;
}

.app--public:has(.hero) .topbar .brand { display: none; }

.hero-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.28em;
    font-family: "Nunito", var(--font-display);
    font-size: clamp(48px, 10vw, 88px);
    font-weight: 900;
    letter-spacing: -0.01em;
    line-height: 1;
    color: var(--brand);
    margin-bottom: 46px;
}

.hero-brand .brand-mark {
    width: 0.95em;
    height: 0.95em;
}

.hero p {
    font-size: clamp(17px, 2.4vw, 21px);
    line-height: 1.5;
    color: var(--ink-soft);
    margin: 0 auto 48px;
    max-width: 600px;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

/* Long-form text pages */
.docs p,
.docs ol,
.docs ul {
    font-size: 16px;
    margin-bottom: 10px;
}

.docs h3,
.docs h4 { margin-top: 1.2em; }

code, samp, kbd {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9em;
    color: var(--ink-soft);
}

pre {
    padding: 12px 14px;
    margin: 1em 0;
    overflow: auto;
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 12.5px;
    line-height: 1.6;
}


/* 13. Helpers ------------------------------------------------------------- */

.muted { color: var(--muted); }

@media (max-width: 480px) {
    .desktop-only,
    .hideable { display: none; }

    .pathbar { font-size: 24px; }

    .card-body { padding: 16px; }

    .generic_input { width: 100%; }

    h1 { font-size: 1.7rem; }
    h2 { font-size: 1.4rem; }
    h3 { font-size: 1.15rem; }

    .trend-label { font-size: 10px; letter-spacing: 0.03em; }

    .stat { padding: 10px; }
    .stat-value { font-size: 20px; }
}

@media (min-width: 481px) {
    .showable { display: none; }
}

/* On phones the name in the top bar gets smaller rather than hidden, to fit next to the buttons */
@media (max-width: 480px) {
    .app--member .topbar .brand { font-size: 24px; gap: 7px; min-width: 0; }
    .app--member .topbar .brand-text { overflow: hidden; text-overflow: clip; white-space: nowrap; }
}

@media (max-width: 359px) {
    .app--member .topbar .brand { font-size: 20px; }
    .app--member .topbar .brand-mark { width: 24px; height: 24px; }
}

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


/* 14. Analysis pages ------------------------------------------------------ */

.event-id {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-weight: 650;
    font-size: 13px;
}

.event-head h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.event-head { color: var(--ink-soft); padding-bottom: 8px; }

.scenario-grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 12px;
    max-width: 560px;
    margin-top: 16px;
}

.scenario-box {
    padding: 14px;
    border-radius: var(--radius);
    background: var(--surface-sunken);
    border: 1px solid var(--line);
}

.scenario-box-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: 650;
}

.scenario-number {
    width: 84px;
    height: 44px !important;
    font-family: var(--font-display);
    font-size: 22px !important;
    font-weight: 700;
    text-align: center;
}

@media (max-width: 480px) {
    .scenario-grid { grid-template-columns: minmax(0, 1fr); }
}


/* 15. Insights & bar charts ------------------------------------------------ */

/* The selectors of the insight and of its options: a third of the usual width, at any screen size */
.generic_input.insight-select { width: 110px; }

.insight-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.insight-figure { text-align: right; }

.insight-figure .stat-value { font-size: 30px; }

.stat-unit {
    margin-left: 2px;
    font-size: 0.55em;
    font-weight: 600;
    color: var(--muted);
}

.insight-empty {
    padding: 28px 0;
    text-align: center;
    color: var(--muted);
}

.insight-table { margin-top: 10px; }

.insight-table summary {
    display: inline-block;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--teal);
}

.insight-table[open] summary { margin-bottom: 8px; }

.barchart {
    position: relative;
    width: 100%;
}

.barchart svg { display: block; }

.barchart-grid { stroke: var(--line); stroke-width: 1; }

.barchart-baseline { stroke: var(--line-strong); stroke-width: 1; }

.barchart-tick {
    font-family: var(--font-ui);
    font-size: 12px;
    fill: var(--muted);
}

.barchart-bar { fill: var(--brand); transition: fill 0.12s ease; }

.barchart-bar.is-faded { fill-opacity: 0.45; }

.barchart-bar.is-active { fill: var(--brand-deep); fill-opacity: 1; }

.barchart-target { fill: transparent; outline: none; }

.barchart-tooltip {
    position: absolute;
    z-index: 5;
    padding: 7px 10px;
    border-radius: var(--radius-s);
    background: var(--ink);
    color: #fff;
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: var(--shadow-pop);
}
