/*
 * Tagebuch – ruhig, sachlich, lesbar.
 * Keine Webfonts: keine externen Anfragen aus Firmennetzen, schneller Aufbau.
 * Oberfläche in Systemschrift, Tagebuchtext in einer Serif für die Lesbarkeit langer Passagen.
 */
:root {
    --paper: #f3f6f5;
    --surface: #ffffff;
    --ink: #1e2b2f;
    --muted: #56676c;
    --line: #d2dcda;
    --accent: #2e6b66;
    --accent-ink: #ffffff;
    --accent-weak: #dcebe8;
    --mark: #8a5a14;
    --mark-weak: #f6ecd9;
    --danger: #a23a3a;
    --focus: #1d5fd1;
    --heat-0: #e7eeec;
    --heat-1: #b6d3ce;
    --heat-2: #6fa79f;
    --heat-3: #3a7d76;
    --heat-4: #1a4541;
    --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Noto Serif", Georgia, serif;
    --radius-s: 4px;
    --radius-m: 8px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #151c1e;
        --surface: #1c2528;
        --ink: #e3ebe9;
        --muted: #9aaeb0;
        --line: #33413f;
        --accent: #6fb3aa;
        --accent-ink: #0e1b19;
        --accent-weak: #22403c;
        --mark: #e0b36a;
        --mark-weak: #3a2f1c;
        --danger: #e08a8a;
        --focus: #8fb4ff;
        --heat-0: #232e30;
        --heat-1: #2f5550;
        --heat-2: #3f7a72;
        --heat-3: #5fa69c;
        --heat-4: #9fd6cd;
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 1rem/1.55 var(--ui);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.125rem; line-height: 1.3; margin: 2rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: 0 0 .75rem; }
.lead { color: var(--muted); max-width: 38rem; }
.hint, small { color: var(--muted); font-size: .875rem; }

/* ------------------------------------------------------------ Rahmen */

header.site {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1.5rem;
    padding: .75rem clamp(1rem, 4vw, 2.5rem);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.brand { font-weight: 600; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
header.site nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
header.site nav a:not(.button) { color: var(--muted); text-decoration: none; padding: .25rem 0; border-bottom: 2px solid transparent; }
header.site nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
header.site nav a:not(.button):hover { color: var(--ink); }

main { flex: 1; width: 100%; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 2.5rem) 3rem; }
main.narrow { max-width: 46rem; }
main.wide { max-width: 68rem; }

footer.site { padding: .75rem clamp(1rem, 4vw, 2.5rem); font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); }
footer.site .lock::before { content: ""; display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); margin-right: .45rem; vertical-align: .05rem; }
footer.site .lock.ok::before { background: var(--accent); }
footer.site .lock.bad { color: var(--danger); }
footer.site .lock.bad::before { background: var(--danger); }

.notice { padding: .75rem 1rem; border-radius: var(--radius-s); border-left: 4px solid var(--accent); background: var(--surface); }
.notice.error { border-left-color: var(--danger); color: var(--danger); }

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

form label { display: block; margin: 0 0 1.1rem; font-weight: 600; font-size: .95rem; }
form label small { display: block; font-weight: 400; margin-top: .3rem; }
form label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0 1rem 0 0; font-weight: 400; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], textarea, select {
    display: block;
    width: 100%;
    margin-top: .35rem;
    padding: .55rem .7rem;
    font: inherit;
    font-weight: 400;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
}
textarea { resize: vertical; font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent-weak); outline-offset: 0; }
label.inline input { width: 5rem; margin: 0; display: inline-block; }
.code-input { font-size: 1.5rem !important; letter-spacing: .3em; max-width: 12rem; font-variant-numeric: tabular-nums; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1rem 1.1rem .2rem; margin: 0 0 1.5rem; background: var(--surface); }
legend { font-weight: 600; padding: 0 .4rem; }
fieldset.when { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0 1rem; }
.duration { margin-bottom: 1.1rem; }
.duration .label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: .35rem; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    font: inherit;
    font-weight: 600;
    font-size: .95rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); }
button.small, .button.small { padding: .35rem .7rem; font-size: .85rem; }
button[disabled] { opacity: .6; cursor: progress; }
button.linklike { background: none; border: none; padding: 0; color: var(--accent); font-weight: 400; text-decoration: underline; }
button.danger-link { color: var(--danger); }
button.danger-link:hover { border-color: var(--danger); }
button.linklike.danger-link { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }

.form-error { color: var(--danger); font-weight: 600; }
.form-ok { color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.25rem 1.25rem .5rem; margin: 0 0 1.5rem; }
.card h2 { margin-top: 0; }

/* ------------------------------------------------------------ Anmeldung */

.auth { max-width: 26rem; margin: 2rem auto 0; }
.auth .aside { margin-top: 1.5rem; color: var(--muted); }
.totp-setup { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center; margin: 1rem 0 1.5rem; }
.totp-setup .qr img { display: block; background: #fff; padding: 8px; border-radius: var(--radius-s); border: 1px solid var(--line); }
.totp-setup code { font-size: 1rem; word-break: break-all; }
ul.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 10rem)); gap: .4rem 1.5rem; font: 1.1rem/1.4 ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* ------------------------------------------------------------ Listen */

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
form.filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; }
form.filter label { margin: 0; font-weight: 400; }
form.filter .form-error { flex-basis: 100%; margin: 0; }

h2.month { font-size: .95rem; color: var(--muted); font-weight: 600; margin: 2rem 0 .5rem; }
ul.entries { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
ul.entries li { border-bottom: 1px solid var(--line); }
.entry-row {
    display: grid;
    grid-template-columns: 10.5rem 1fr auto;
    gap: .25rem 1.25rem;
    padding: .8rem .5rem;
    color: var(--ink);
    text-decoration: none;
    align-items: baseline;
}
.entry-row:hover { background: var(--surface); }
.row-when { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .92rem; }
.row-title { font-family: var(--serif); font-size: 1.08rem; }
.row-meta { color: var(--muted); font-size: .85rem; text-align: right; white-space: nowrap; }
.flag { display: inline-block; margin-left: .5rem; padding: .05rem .45rem; border-radius: var(--radius-s); background: var(--mark-weak); color: var(--mark); font-size: .78rem; font-weight: 600; }
.empty { padding: 2rem 0; color: var(--muted); max-width: 34rem; }
.loading { color: var(--muted); }

/* ------------------------------------------------------------ Eintrag */

.entry-when { color: var(--muted); margin: 0 0 .35rem; font-variant-numeric: tabular-nums; }
.entry-view h1 { font-family: var(--serif); font-size: 2rem; font-weight: 600; }
.entry-status { font-size: .88rem; color: var(--muted); }
.entry-status.edited { color: var(--mark); background: var(--mark-weak); display: inline-block; padding: .25rem .6rem; border-radius: var(--radius-s); }
.entry-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0 2rem; }
.entry-section { border-top: 1px solid var(--line); padding-top: .25rem; }
.entry-section h2 { font-size: 1rem; color: var(--muted); margin: 1.25rem 0 .5rem; }
.entry-text { font-family: var(--serif); font-size: 1.12rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 1.25rem; max-width: 40rem; }
.is-empty { color: var(--muted); font-style: italic; }

.attachment-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.attachment-list li { display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.att-name { font-weight: 600; overflow-wrap: anywhere; }
.att-meta { color: var(--muted); font-size: .85rem; grid-column: 1; }
.att-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.preview { margin: 0 0 1rem; padding: .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.preview img { display: block; max-width: 100%; height: auto; margin-bottom: .5rem; }
.preview audio { width: 100%; margin-bottom: .5rem; }
.preview .att-meta { word-break: break-all; }
label.upload { position: relative; display: inline-block; margin: 0 0 .5rem; }
label.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
label.upload:focus-within .button { outline: 2px solid var(--focus); outline-offset: 2px; }
.progress { color: var(--accent); font-weight: 600; }

.integrity { font-size: .9rem; color: var(--accent); }
.integrity.bad { color: var(--danger); font-weight: 600; }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { display: grid; grid-template-columns: 10.5rem 1fr auto; gap: .15rem 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; align-items: baseline; }
.h-when { color: var(--muted); font-variant-numeric: tabular-nums; }
.h-reason { grid-column: 2; color: var(--muted); white-space: pre-wrap; }
.history-list button { grid-column: 3; grid-row: 1; }

dialog { max-width: min(44rem, 92vw); width: 100%; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.25rem 1.5rem; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(20, 30, 32, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.dialog-head h2 { margin: 0 0 1rem; }
.version-body dt { font-weight: 600; font-size: .85rem; color: var(--muted); margin-top: .9rem; }
.version-body dd { margin: .2rem 0 0; font-family: var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ------------------------------------------------------------ Übersicht: der Jahreskalender */

.year-nav { display: flex; gap: .4rem; align-items: center; }
.year-nav select { width: auto; margin: 0; }
.year-nav button { width: 2.4rem; padding: .5rem 0; font-size: 1.1rem; }

.totals { display: flex; flex-wrap: wrap; gap: 1rem 3rem; margin: 1rem 0 2rem; }
.totals div { display: flex; flex-direction: column-reverse; }
.totals dt { color: var(--muted); font-size: .88rem; }
.totals dd { margin: 0; font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }

.calendar {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
    gap: 1.75rem 2rem;
}
.cal-month h3 { font-size: .9rem; font-weight: 600; margin-bottom: .4rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-wd { font-size: .68rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    border-radius: 3px;
    border: 0;
    padding: 0;
    color: var(--muted);
    background: var(--heat-0);
}
button.cal-day { cursor: pointer; font-weight: 600; }
.cal-day.l1 { background: var(--heat-1); color: var(--ink); }
.cal-day.l2 { background: var(--heat-2); color: #fff; }
.cal-day.l3 { background: var(--heat-3); color: #fff; }
.cal-day.l4 { background: var(--heat-4); color: #fff; }
@media (prefers-color-scheme: dark) {
    .cal-day.l3, .cal-day.l4 { color: #0e1b19; }
}
.cal-day.today { box-shadow: inset 0 0 0 2px var(--mark); }
.cal-day.selected { box-shadow: 0 0 0 2px var(--ink); }
button.cal-day:hover { filter: brightness(1.1); }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; margin: 1.25rem 0 0; font-size: .82rem; color: var(--muted); }
.swatch { display: inline-block; width: .9rem; height: .9rem; border-radius: 2px; margin-left: .6rem; }
.swatch:first-child { margin-left: 0; }
.swatch.l0 { background: var(--heat-0); } .swatch.l1 { background: var(--heat-1); } .swatch.l2 { background: var(--heat-2); }
.swatch.l3 { background: var(--heat-3); } .swatch.l4 { background: var(--heat-4); }

.day-panel { margin: 2rem 0 0; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.day-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; }
.day-head h2 { margin: 0; }
.day-panel ul.entries { margin-top: .75rem; }

.distribution { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 0 3rem; margin-top: 1rem; }
.bar-row { display: grid; grid-template-columns: 2.5rem 1fr 2rem; gap: .6rem; align-items: center; margin: .3rem 0; font-size: .85rem; }
.bar-label { color: var(--muted); }
.bar-track { height: .7rem; background: var(--heat-0); border-radius: 2px; overflow: hidden; }
.bar { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.export { margin-top: 2.5rem; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------ Klein */

@media (max-width: 40rem) {
    header.site nav { width: 100%; }
    .entry-row { grid-template-columns: 1fr; gap: .1rem; }
    .row-meta { text-align: left; }
    .history-list li { grid-template-columns: 1fr; }
    .h-reason, .history-list button { grid-column: 1; grid-row: auto; justify-self: start; }
    .attachment-list li { grid-template-columns: 1fr; }
    .att-actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
    .entry-view h1 { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; }
}

@media print {
    header.site, footer.site, .entry-actions, label.upload, .att-actions, .history-list button { display: none !important; }
    body { background: #fff; }
}
