/*
 * The few things that are shared across every page: the colour and type
 * tokens, the reset, the app's skeleton (`.app`, `.kopf*`, `.haupt`,
 * `.bahn`), buttons, the overlay frame, the empty-state note, the fab, the
 * form fields and the toasts. Everything else -- the pills, the
 * cards, the settings panels, the throw field -- is a component's own CSS,
 * added once through `styleOnce()` where it is used (`WEB.§10`).
 *
 * The values are the mockup's (`esmusssein/mockup/index.html`, 9-804); the fonts
 * are given as a list with system fallbacks rather than fetched from a CDN
 * (`WEB.§2`), so the roles they mark -- serif for what esmusssein wrote, mono for
 * what somebody threw in -- hold even where IBM Plex is not installed.
 */

:root {
    color-scheme: light;

    --paper: #f5f5f1;
    --card: #ffffff;
    --sunk: #efefea;
    --ink: #16181a;
    --ink-mid: #5e6360;
    --ink-soft: #8d918d;
    --line: #e3e4de;
    --line-soft: #edeee9;
    --accent: #17544b;
    --accent-mid: #3c7d72;
    --accent-bg: #e6efea;

    --s-eingang: #b0762a;
    --s-aktiv: #17544b;
    --s-ablage: #6f7b8c;
    --s-wartet: #4b6a8f;
    --s-archiv: #9aa09a;
    --s-papierkorb: #a8564e;

    /* PRINZIP.§3 die-schrift-sagt-wer-geschrieben-hat -- the three roles:
       sans is the application speaking, serif is what esmusssein wrote, mono is
       what a person threw in. None of them is ever used as decoration. */
    --sans: 'IBM Plex Sans', system-ui, sans-serif;
    --serif: 'IBM Plex Serif', Georgia, serif;
    --mono: 'IBM Plex Mono', ui-monospace, monospace;

    --unten: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
}

button, input, textarea, select {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent-mid);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ---- Geruest: Kopfbalken, darunter die Seite -------------------------- */

.app {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.kopf {
    flex: none;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    padding: 10px 20px;
}
.kopf-bahn {
    max-width: 1120px;
    margin: 0 auto;
}
.kopf-reihe {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.kopf-luecke {
    flex: 1;
    min-width: 6px;
}
.kopf-name {
    font-size: 15px;
    font-weight: 600;
}
.kopf-zahl {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.haupt {
    flex: 1;
    overflow: auto;
    min-height: 0;
}
.bahn {
    max-width: 1120px;
    margin: 0 auto;
    width: 100%;
    padding: 16px 20px 110px;
    box-sizing: border-box;
}

/* ---- Knoepfe ------------------------------------------------------------ */

.knopf {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 4px;
    padding: 6px 11px;
    cursor: pointer;
    color: var(--ink-mid);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
}
.knopf:hover {
    border-color: var(--ink-soft);
    color: var(--ink);
}
.knopf svg {
    width: 13px;
    height: 13px;
}
.knopf-stark {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 500;
}
.knopf-stark:hover {
    background: #10403a;
    border-color: #10403a;
    color: #fff;
}
.knopf-klein {
    padding: 5px 9px;
    font-size: 12px;
}
.knopf-flach {
    border-color: transparent;
    background: transparent;
}
.knopf-flach:hover {
    border-color: var(--line);
}
.knopf-rund {
    padding: 7px;
    border-radius: 50%;
}
.knopf-rund svg {
    width: 16px;
    height: 16px;
}

/* ---- Overlay -------------------------------------------------------- */

.hulle {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(22,24,26,0.34);
    display: grid;
    place-items: center;
    padding: 22px;
}

.tafelblatt {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 50px rgba(22,24,26,0.24);
    width: min(660px, 100%);
    max-height: min(88vh, 940px);
    /* dvh is the height that is really visible: on a phone vh counts the
       address bar too, and the foot with its buttons would sit below it. */
    max-height: min(88dvh, 940px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tafelblatt-schmal {
    width: min(420px, 100%);
}

.tb-griff {
    display: none;
}
.tb-kopf {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 13px 11px 15px;
    border-bottom: 1px solid var(--line-soft);
}
.tb-leib {
    overflow: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 20px 20px;
}
.tb-fuss {
    flex: none;
    border-top: 1px solid var(--line-soft);
    background: var(--sunk);
    padding: 9px 13px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.tb-fuss-reihe {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.tb-luecke {
    flex: 1;
    min-width: 6px;
}
.tb-block {
    border-top: 1px solid var(--line-soft);
    padding: 12px 0 2px;
}
.tb-block:first-child {
    border-top: 0;
    padding-top: 0;
}
.tb-titel {
    font-family: var(--serif);
    font-size: 23px;
    font-weight: 500;
    line-height: 1.26;
    margin: 0 0 8px;
    text-wrap: balance;
}
.tb-titel-tipp {
    cursor: text;
    border-radius: 4px;
}
.tb-titel-tipp:hover {
    background: var(--sunk);
}
.tb-wann {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-soft);
    margin: 0 0 14px;
}
.tb-wann-warn {
    color: var(--s-eingang);
}
.tb-wann-wartet {
    color: var(--s-wartet);
}
.tb-punkte {
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.6;
    margin: 0 0 16px;
    padding-left: 18px;
}
.tb-punkte li {
    margin-bottom: 5px;
}
.tb-punkte-tipp {
    cursor: text;
    border-radius: 4px;
}
.tb-punkte-tipp:hover {
    background: var(--sunk);
}

/* ---- Formfelder ----------------------------------------------------- */

.namensfeld {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 6px 9px;
    background: var(--card);
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}
.namensfeld:focus {
    outline: none;
    border-color: var(--accent-mid);
}

.zahlfeld {
    width: 64px;
    font-family: var(--mono);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 5px 7px;
    background: var(--card);
}

.textfeld {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--card);
    padding: 10px 11px;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    min-height: 150px;
}
.textfeld:focus {
    outline: none;
    border-color: var(--accent-mid);
}

/* ---- Das grosse Plus ------------------------------------------------ */

.fab {
    position: fixed;
    right: 22px;
    bottom: calc(22px + var(--unten));
    z-index: 40;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 6px 18px rgba(22,24,26,0.28);
}
.fab:hover {
    background: #10403a;
}
.fab svg {
    width: 26px;
    height: 26px;
}

/* ---- Kleinkram, und die Meldung oben --------------------------------- */

.leer {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-soft);
    font-size: 13px;
}

/* Toasts: bottom left, above everything, and they fade on their own. */
.toasts {
    position: fixed;
    left: 16px;
    bottom: calc(16px + var(--unten));
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}
.toast {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13.5px;
    line-height: 1.4;
    color: #fff;
    background: var(--accent);
    box-shadow: 0 8px 24px rgba(22,24,26,0.22);
    opacity: 1;
    transition: opacity 0.6s ease, transform 0.6s ease;
}
.toast-schlecht {
    background: var(--s-papierkorb);
}
.toast-offline {
    background: var(--s-eingang);
}
.toast-weg {
    opacity: 0;
    transform: translateY(6px);
}

/* =======================================================================
   Das Telefon. Der Kopfbalken bricht um, alles was man antippt ist
   mindestens 44 Pixel hoch, Overlays kommen von unten.
   ======================================================================= */

@media (max-width: 900px) {

    body {
        font-size: 15px;
    }

    .kopf {
        padding: 9px 12px;
    }
    .kopf-reihe {
        gap: 7px;
    }
    .kopf-zahl {
        order: 9;
    }

    .bahn {
        padding: 12px 12px 120px;
    }

    .hulle {
        padding: 0;
        place-items: end stretch;
    }
    .tafelblatt, .tafelblatt-schmal {
        width: 100%;
        max-height: 92vh;
        max-height: 92dvh;
        border: 0;
        border-radius: 14px 14px 0 0;
    }
    .tb-griff {
        display: block;
        width: 38px;
        height: 4px;
        background: var(--line);
        border-radius: 2px;
        margin: 8px auto 0;
        flex: none;
    }
    .tb-kopf {
        padding: 10px 10px 10px 16px;
    }
    .tb-leib {
        padding: 14px 16px 18px;
    }
    .tb-fuss {
        padding: 10px 12px calc(12px + var(--unten));
        gap: 9px;
    }
    .tb-titel {
        font-size: 24px;
    }
    .tb-punkte {
        font-size: 16px;
    }

    .knopf {
        padding: 11px 14px;
        min-height: 44px;
        border-radius: 6px;
    }
    .knopf-klein {
        padding: 10px 12px;
        font-size: 14px;
    }
    .knopf-rund {
        padding: 11px;
    }

    .namensfeld {
        padding: 11px 11px;
        font-size: 16px;
    }
    .zahlfeld {
        padding: 10px 8px;
        font-size: 16px;
        width: 78px;
    }

    .fab {
        right: 16px;
        bottom: calc(16px + var(--unten));
        width: 62px;
        height: 62px;
    }
    .fab svg {
        width: 29px;
        height: 29px;
    }

}
