/* Mein Tagebuch · ruhige Notizbuch-Optik: warmes Papier, dunkle Tinte, eine Farbe je Messart.
   Blau = Blutzucker, Orange = Gewicht (beide auf hellem und dunklem Grund auf Farbsehschwäche geprüft).
   Keine externen Fonts — die CSP erlaubt nur eigene Dateien. */

:root {
    color-scheme: light;
    --page:      #f4f2ec;
    --card:      #fcfcfb;
    --ink:       #1c1d20;
    --ink-2:     #4f5157;
    --muted:     #77797f;
    --line:      #e2dfd6;
    --line-soft: #ebe9e2;
    --press:     #efece5;
    --glucose:   #2a78d6;
    --glucose-bg: rgba(42, 120, 214, 0.10);
    --weight:    #eb6834;
    --good:      #1f7a46;
    --good-bg:   rgba(31, 122, 70, 0.10);
    --warn:      #9a5b00;
    --warn-bg:   rgba(237, 161, 0, 0.16);
    --danger:    #c0392b;
    --band:      rgba(31, 122, 70, 0.09);
    --shadow:    0 1px 2px rgba(28, 29, 32, 0.05), 0 8px 24px -12px rgba(28, 29, 32, 0.18);
    --radius:    14px;
    --serif: "Sitka Heading", "Sitka Text", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans:  "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
    --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --page:      #121211;
        --card:      #1a1a19;
        --ink:       #f2f1ec;
        --ink-2:     #c3c2b7;
        --muted:     #8f8e86;
        --line:      #2f2f2c;
        --line-soft: #262624;
        --press:     #232321;
        --glucose:   #3987e5;
        --glucose-bg: rgba(57, 135, 229, 0.16);
        --weight:    #d95926;
        --good:      #5cc98b;
        --good-bg:   rgba(92, 201, 139, 0.14);
        --warn:      #f2b755;
        --warn-bg:   rgba(242, 183, 85, 0.15);
        --danger:    #f07468;
        --band:      rgba(92, 201, 139, 0.10);
        --shadow:    0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px -14px rgba(0, 0, 0, 0.7);
    }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
    min-height: 100vh;
    background: var(--page);
    color: var(--ink);
    font: 16px/1.5 var(--sans);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
h1 { font: 600 28px/1.15 var(--serif); letter-spacing: -0.01em; text-wrap: balance; }
h2 { font: 600 19px/1.25 var(--serif); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.stack > * + * { margin-top: 14px; }
.boot  { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty { padding: 18px 4px; color: var(--muted); text-align: center; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */

.btn {
    appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px; border-radius: 11px;
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
    font: 600 15px/1 var(--sans); cursor: pointer; text-decoration: none;
    transition: background-color 0.12s, transform 0.06s;
}
.btn:hover { background: var(--press); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--page); }
.btn-primary:hover { background: var(--ink); opacity: 0.88; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); }
.btn-block { display: flex; width: 100%; }
.btn-left { margin-right: auto; }
.link { appearance: none; border: 0; padding: 0; background: none; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.icon-btn {
    appearance: none; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
    color: var(--muted); font-size: 17px; cursor: pointer;
}
.icon-btn:hover { background: var(--press); color: var(--ink); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Formulare ---------- */

.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.input {
    width: 100%; min-width: 0; min-height: 46px; padding: 10px 13px;
    border: 1px solid var(--line); border-radius: 11px;
    background: var(--page); color: var(--ink); font: 16px/1.3 var(--sans);
}
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.input::placeholder { color: var(--muted); opacity: 0.8; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* große Werteingabe mit Einheit */
.value-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 4px 2px; border-bottom: 2px solid var(--line); }
.value-row:focus-within { border-bottom-color: var(--ink); }
.input-big {
    flex: 1; min-height: 0; padding: 4px 0; border: 0; border-radius: 0; background: transparent; box-shadow: none !important;
    font: 600 46px/1.1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.input-big::placeholder { font-weight: 400; opacity: 0.35; }
.unit { font-size: 17px; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* Segmente und Chips */
.seg { display: inline-flex; padding: 4px; gap: 2px; border-radius: 12px; background: var(--press); border: 1px solid var(--line-soft); max-width: 100%; overflow-x: auto; }
.seg-btn {
    appearance: none; flex: 1; min-height: 38px; padding: 0 16px; border: 0; border-radius: 9px;
    background: transparent; color: var(--ink-2); font: 600 14.5px/1 var(--sans); white-space: nowrap; cursor: pointer;
}
.seg-btn.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.entry-form .seg { display: flex; }
.seg-glucose.is-active { box-shadow: inset 0 -3px 0 var(--glucose), 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg-weight.is-active  { box-shadow: inset 0 -3px 0 var(--weight), 0 1px 3px rgba(0, 0, 0, 0.12); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    appearance: none; min-height: 38px; padding: 0 14px; border-radius: 999px;
    border: 1px solid var(--line); background: transparent; color: var(--ink-2);
    font: 500 14px/1 var(--sans); cursor: pointer;
}
.chip:hover { background: var(--press); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--page); }

/* ---------- Anmelden ---------- */

body.gate { display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
    width: 100%; max-width: 380px; padding: 34px 28px 30px; text-align: center;
    background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
    animation: pop 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.gate-card > * + * { margin-top: 16px; }
.gate-lead { color: var(--ink-2); }
/* Blutstropfen ohne Bilddatei: Quadrat mit drei runden Ecken, um 45° gedreht */
.gate-mark, .brand-drop {
    display: block; flex-shrink: 0; background: var(--glucose);
    border-radius: 50% 0 50% 50%; transform: rotate(-45deg);
}
.gate-mark  { width: 44px; height: 44px; margin: 10px auto 6px; }
.brand-drop { width: 13px; height: 13px; margin: 4px 2px 0; }
.notice { padding: 10px 12px; border-radius: 10px; font-size: 14.5px; text-align: left; }
.notice-err { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--ink); }
.notice-ok  { background: var(--good-bg); color: var(--ink); }

/* ---------- Grundgerüst ---------- */

.shell { min-height: 100vh; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    max-width: 920px; margin: 0 auto; padding: 14px 20px;
    background: color-mix(in srgb, var(--page) 88%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font: 600 19px/1 var(--serif); }
.nav { display: flex; gap: 4px; }
.nav-btn {
    appearance: none; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px;
    background: transparent; color: var(--ink-2); font: 600 14.5px/1 var(--sans); cursor: pointer;
}
.nav-btn:hover { background: var(--press); }
.nav-btn.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.nav-ico { display: none; }

.content { max-width: 920px; margin: 0 auto; padding: 8px 20px 60px; }
.content.is-entering .view > * { animation: rise 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.content.is-entering .view > *:nth-child(2) { animation-delay: 0.04s; }
.content.is-entering .view > *:nth-child(3) { animation-delay: 0.08s; }
.content.is-entering .view > *:nth-child(n+4) { animation-delay: 0.12s; }
.view > * + * { margin-top: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; padding: 8px 0 4px; }

.card {
    padding: 20px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 12px; }
.h-unit { font: 600 13px var(--sans); color: var(--muted); }
.card-entry h1 { font-size: 24px; margin-bottom: 16px; }

/* ---------- Kennzahlen ---------- */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { padding: 16px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; align-content: start; gap: 4px; }
.tile-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.tile-value { font: 600 28px/1.1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile-unit  { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.tile-sub   { font-size: 13px; color: var(--ink-2); }
.tile .tag, .tile .link { justify-self: start; margin-top: 4px; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.tag-good { background: var(--good-bg); color: var(--good); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Einträge ---------- */

.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--line-soft); }
.row {
    appearance: none; width: 100%; min-height: 56px; padding: 10px 6px; display: flex; align-items: center; gap: 12px;
    border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 10px;
}
.row:hover { background: var(--press); }
.row-time { width: 46px; flex-shrink: 0; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-glucose { background: var(--glucose); }
.dot-weight  { background: var(--weight); }
.row-main  { flex: 1; min-width: 0; display: grid; }
.row-value { font: 600 19px/1.2 var(--sans); font-variant-numeric: tabular-nums; }
.row-unit  { font-size: 13px; font-weight: 600; color: var(--muted); }
.row-meta  { font-size: 13.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day .card-head { margin-bottom: 4px; }

/* ---------- Medikamente ---------- */

.meds { list-style: none; margin: 0; padding: 0; }
.meds li + li { border-top: 1px solid var(--line-soft); }
.med {
    appearance: none; width: 100%; padding: 14px 8px; display: grid; gap: 8px;
    border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 10px;
}
.med:hover { background: var(--press); }
.med-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; }
.med-name { font: 600 18px/1.25 var(--sans); }
.med-strength { font-size: 14px; font-weight: 600; color: var(--muted); }
.med-line { font-size: 14.5px; color: var(--ink-2); }
.med-meta { font-size: 13px; color: var(--muted); }
.med.is-ended .med-name { color: var(--ink-2); }
.med.is-ended .dose-view { opacity: 0.6; }

.dose-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.dose-cell { display: grid; gap: 4px; min-width: 0; }
.dose-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.dose-input { text-align: center; padding-left: 6px; padding-right: 6px; }
.dose-view { max-width: 420px; gap: 6px; }
.dose-view .dose-cell { padding: 6px 4px; border-radius: 9px; background: var(--press); text-align: center; gap: 1px; }
.dose-view .dose-label { font-size: 11.5px; }
.dose-val { font: 600 17px/1.2 var(--sans); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dose-view .is-empty .dose-val { color: var(--muted); font-weight: 400; }
.r-meds .r-dose { width: 58px; text-align: center; font-variant-numeric: tabular-nums; }
.r-nowrap { white-space: nowrap; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }

/* ---------- Diagramme ---------- */

.chart { position: relative; min-height: 120px; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.grid { stroke: var(--line-soft); stroke-width: 1; }
.axis { fill: var(--muted); font: 11.5px var(--sans); font-variant-numeric: tabular-nums; }
.band { fill: var(--band); }
.legend { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.legend-band { width: 16px; height: 10px; border-radius: 3px; background: var(--band); outline: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.day-shade { fill: var(--ink); opacity: 0.025; }
.pt { cursor: pointer; outline: none; }
.pt-hit { fill: transparent; }
.pt-dot { fill: var(--glucose); stroke: var(--card); stroke-width: 2; transition: r 0.1s; }
.pt.is-hover .pt-dot, .pt:focus-visible .pt-dot { r: 7; }
.pt:focus-visible .pt-hit { stroke: var(--ink); stroke-width: 1.5; }
.w-line { fill: none; stroke: var(--weight); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.w-dot { fill: var(--weight); stroke: var(--card); stroke-width: 2; }
.cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.overlay { fill: transparent; cursor: crosshair; }
.tip {
    position: absolute; z-index: 5; pointer-events: none; display: grid; gap: 1px;
    padding: 7px 10px; border-radius: 9px; background: var(--ink); color: var(--page);
    font-size: 12.5px; white-space: nowrap; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.tip strong { font-size: 14.5px; }
.tip span { opacity: 0.8; }

/* ---------- Modale & Toasts ---------- */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center;
    background: rgba(18, 18, 17, 0.45); padding: 16px;
}
.modal {
    width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto;
    padding: 18px 20px 22px; background: var(--card); border-radius: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    animation: pop 0.25s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
@media (min-width: 721px) { .modal-backdrop { place-items: center; } }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 60; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--page); font-size: 15px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); animation: pop 0.2s both; }
.toast-err { background: var(--danger); color: #fff; }

/* ---------- Export & Bericht ---------- */

.export-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.disclaimer { padding: 0 4px; }
.report-bar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.sheet {
    padding: 32px 34px; background: #fff; color: #111; border-radius: 6px; box-shadow: var(--shadow);
    font-size: 13.5px; line-height: 1.45;
}
.sheet h1 { font-size: 24px; color: #111; }
.sheet h2 { font-size: 16px; margin: 22px 0 8px; color: #111; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 2px solid #111; }
.sheet-head p { color: #444; margin-top: 4px; }
.sheet-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin: 0; font-size: 12.5px; }
.sheet-meta dt { color: #666; }
.sheet-meta dd { margin: 0; font-weight: 600; }
.r-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.r-table th, .r-table td { padding: 6px 8px; border: 1px solid #d6d6d6; text-align: left; vertical-align: top; }
.r-table thead th { background: #f1f1ef; font-size: 12px; }
.r-summary th { width: 22%; background: #f7f7f5; font-weight: 600; }
.r-diary tbody th { white-space: nowrap; font-weight: 600; }
.r-val { white-space: nowrap; }
.r-val strong { font-size: 14px; }
.r-out strong { text-decoration: underline; text-underline-offset: 2px; }
.r-time { color: #666; font-size: 11.5px; }
.r-legend, .r-foot { margin-top: 10px; color: #666; font-size: 12px; }
.r-foot { margin-top: 26px; border-top: 1px solid #ddd; padding-top: 8px; }
.sheet .table-scroll { overflow-x: auto; }

/* ---------- Handy: Navigation unten ---------- */

@media (max-width: 720px) {
    h1 { font-size: 25px; }
    /* ohne backdrop-filter: sonst wird die feste Navigation an die Kopfleiste statt an den Bildschirm gebunden */
    .topbar { padding: 12px 16px; position: static; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--page); }
    .content { padding: 4px 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }
    .nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; gap: 0;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--line);
    }
    .nav-btn { flex: 1; flex-direction: column; gap: 4px; min-height: 52px; padding: 4px 2px; font-size: 11.5px; border-radius: 12px; }
    .nav-btn.is-active { background: transparent; box-shadow: none; color: var(--ink); }
    .nav-ico { display: block; width: 22px; height: 22px; border-radius: 7px; border: 2px solid currentColor; opacity: 0.55; }
    .nav-btn.is-active .nav-ico { opacity: 1; background: currentColor; }
    .nav-today .nav-ico    { border-radius: 50%; }
    .nav-history .nav-ico  { border-radius: 4px; }
    .nav-meds .nav-ico     { width: 13px; border-radius: 7px; transform: rotate(35deg); }
    .nav-export .nav-ico   { border-radius: 4px 4px 11px 11px; }
    .nav-settings .nav-ico { border-radius: 50% 50% 4px 50%; }
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tile-value { font-size: 24px; }
    .card { padding: 16px; }
    .sheet { padding: 20px 16px; }
    .toasts { bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); }
}

/* ---------- Drucken (Arztbericht als PDF) ---------- */

@media print {
    @page { size: A4; margin: 14mm 12mm; }
    body { background: #fff; color: #000; }
    .topbar, .no-print, .toasts { display: none !important; }
    .content { max-width: none; padding: 0; }
    .sheet { padding: 0; box-shadow: none; border-radius: 0; }
    .r-table tr { break-inside: avoid; }
    .sheet h2 { break-after: avoid; }
}

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