/* ==========================================================================
   Pflanzenkalender – Designschicht über Pico CSS
   Pico liefert Formulare, Typografie und Grundabstände; hier kommen
   Farbpalette, App-Layout und Komponenten dazu.
   ========================================================================== */

/* ---------- Farb- und Formtokens (hell) ---------- */
:root:not([data-theme=dark]),
[data-theme=light] {
    --pico-font-family-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif,
        var(--pico-font-family-emoji);
    --pico-border-radius: 0.75rem;
    --pico-background-color: #f4f7f3;
    --pico-color: #1f2a22;
    --pico-muted-color: #66756a;
    --pico-muted-border-color: #e3eae2;
    --pico-card-background-color: #ffffff;
    --pico-card-sectioning-background-color: #f8faf7;
    --pico-card-box-shadow: 0 1px 2px rgba(23, 51, 33, 0.05), 0 6px 20px rgba(23, 51, 33, 0.06);
    --pico-primary: #2e7d4f;
    --pico-primary-background: #2e7d4f;
    --pico-primary-border: #2e7d4f;
    --pico-primary-hover: #236640;
    --pico-primary-hover-background: #236640;
    --pico-primary-hover-border: #236640;
    --pico-primary-focus: rgba(46, 125, 79, 0.28);
    --pico-primary-inverse: #ffffff;
    --pico-primary-underline: rgba(46, 125, 79, 0.4);

    --ink: #1f2a22;
    --leaf-soft: #e4f2e8;
    --leaf-strong: #1d5c38;
    --sun-soft: #fff1e0;
    --sun-strong: #b45309;
    --sky-soft: #e5f0fb;
    --sky-strong: #1d5c96;
    --stone-soft: #eef1ed;
    --danger: #c0392b;
    --topbar-bg: rgba(244, 247, 243, 0.82);
    --placeholder-from: #d9efdf;
    --placeholder-to: #b9dfc6;
}

/* ---------- Farb- und Formtokens (dunkel) ---------- */
@media only screen and (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --pico-background-color: #0f1612;
        --pico-color: #e3ece5;
        --pico-muted-color: #93a397;
        --pico-muted-border-color: #223028;
        --pico-card-background-color: #16201a;
        --pico-card-sectioning-background-color: #1a261f;
        --pico-card-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
        --pico-primary: #6fcf97;
        --pico-primary-background: #3d9a63;
        --pico-primary-border: #3d9a63;
        --pico-primary-hover: #8ee0ae;
        --pico-primary-hover-background: #4cae74;
        --pico-primary-hover-border: #4cae74;
        --pico-primary-focus: rgba(111, 207, 151, 0.3);
        --pico-primary-inverse: #ffffff;

        --ink: #e3ece5;
        --leaf-soft: #1c3326;
        --leaf-strong: #8ee0ae;
        --sun-soft: #3a2a14;
        --sun-strong: #f5b25c;
        --sky-soft: #172b3d;
        --sky-strong: #8cc4f0;
        --stone-soft: #1d2821;
        --danger: #f08070;
        --topbar-bg: rgba(15, 22, 18, 0.82);
        --placeholder-from: #1d3527;
        --placeholder-to: #27493a;
    }
}

/* ---------- Grundlayout ---------- */
body {
    min-height: 100vh;
}

body > main {
    max-width: 1080px;
    padding: 1.5rem 1rem 6rem;
}

.wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 1rem;
}

h1, h2, h3 {
    letter-spacing: -0.02em;
}

h1 {
    font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem);
    margin-bottom: 0.25rem;
}

h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
}

a {
    text-decoration: none;
}

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

/* ---------- Kopfzeile ---------- */
body > header.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    max-width: none;
    padding: 0;
    background: var(--topbar-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    height: 3.75rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 0.7rem;
    background: linear-gradient(135deg, #48b072, #1d5c38);
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(46, 125, 79, 0.3);
}

nav.mainnav {
    display: flex;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

nav.mainnav a {
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    color: var(--pico-muted-color);
    font-weight: 500;
}

nav.mainnav a:hover {
    color: var(--ink);
    background: var(--stone-soft);
}

nav.mainnav a[aria-current=page] {
    color: var(--leaf-strong);
    background: var(--leaf-soft);
}

.usermenu {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
}

.usermenu form {
    margin: 0;
}

.avatar {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--leaf-soft);
    color: var(--leaf-strong);
    font-weight: 700;
    font-size: 0.9rem;
}

/* ---------- Tab-Leiste unten (Handy) ---------- */
nav.tabbar {
    display: none;
}

@media (max-width: 640px) {
    nav.mainnav,
    .usermenu .username {
        display: none;
    }

    nav.tabbar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 20;
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        padding: 0.4rem 1.5rem calc(0.4rem + env(safe-area-inset-bottom));
        background: var(--topbar-bg);
        backdrop-filter: saturate(180%) blur(12px);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
        border-top: 1px solid var(--pico-muted-border-color);
    }

    nav.tabbar a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--pico-muted-color);
    }

    nav.tabbar a span {
        font-size: 1.35rem;
        line-height: 1.2;
    }

    nav.tabbar a[aria-current=page] {
        color: var(--pico-primary);
    }

    nav.tabbar a.tab-add {
        display: grid;
        place-items: center;
        width: 3.25rem;
        height: 3.25rem;
        margin-top: -1.5rem;
        border-radius: 50%;
        background: var(--pico-primary-background);
        color: var(--pico-primary-inverse);
        font-size: 1.6rem;
        box-shadow: 0 8px 20px rgba(46, 125, 79, 0.35);
    }
}

/* ---------- Seitenkopf ---------- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-head p {
    margin: 0;
}

.eyebrow {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--pico-primary);
}

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

.back {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--pico-muted-color);
    font-weight: 500;
}

/* ---------- Knöpfe ---------- */
a[role=button],
button {
    font-weight: 600;
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    margin: 0;
}

.btn-block {
    width: 100%;
    margin: 0;
}

.btn-ghost,
.btn-danger {
    --pico-background-color: transparent;
    --pico-border-color: var(--pico-muted-border-color);
    --pico-color: var(--pico-color);
    --pico-box-shadow: none;
}

.btn-ghost:is(:hover, :focus, :active) {
    --pico-background-color: var(--stone-soft);
    --pico-border-color: var(--pico-muted-border-color);
    --pico-color: var(--pico-color);
}

.btn-danger {
    --pico-color: var(--danger);
}

.btn-danger:is(:hover, :focus, :active) {
    --pico-background-color: color-mix(in srgb, var(--danger) 12%, transparent);
    --pico-border-color: var(--danger);
    --pico-color: var(--danger);
}

.btn-icon {
    padding: 0.35rem 0.6rem;
    line-height: 1;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--stone-soft);
    color: var(--pico-muted-color);
}

.badge-overdue { background: var(--sun-soft); color: var(--sun-strong); }
.badge-due     { background: var(--leaf-soft); color: var(--leaf-strong); }
.badge-soon    { background: var(--sky-soft); color: var(--sky-strong); }

/* ---------- Karten-Raster ---------- */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 1.1rem;
}

.grid-cards > article {
    margin: 0;
}

article {
    position: relative;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 1.25rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* Ganze Karte klickbar: der Link der Überschrift wird über die Karte gespannt. */
article h3 a::after {
    content: "";
    position: absolute;
    inset: 0;
}

article:has(h3 a):hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(23, 51, 33, 0.06), 0 12px 28px rgba(23, 51, 33, 0.1);
}

/* Formulare und Knöpfe müssen über dem aufgespannten Link liegen. */
article form,
article button {
    position: relative;
    z-index: 1;
}

article h3 {
    margin: 0;
    font-size: 1.05rem;
}

article h3 a {
    color: var(--ink);
}

/* Pflanzenkarte */
article.card {
    padding: 0;
    overflow: hidden;
}

.card-media {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--stone-soft);
}

.card-media img,
.thumb img,
.hero-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-media .badge {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.card-body {
    padding: 0.9rem 1rem 1.1rem;
}

.card-body p {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
}

.placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--placeholder-from), var(--placeholder-to));
    font-size: 3rem;
}

/* Aufgabenkarte auf „Heute" */
article.task {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 1rem;
}

.task-head {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.task-head .kind {
    font-size: 0.875rem;
    color: var(--pico-muted-color);
}

.task form {
    margin: auto 0 0;
}

.thumb {
    flex: none;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 1rem;
    overflow: hidden;
}

.thumb .placeholder {
    font-size: 1.6rem;
}

/* ---------- Panels und Listen ---------- */
.panel {
    margin-bottom: 1.25rem;
    padding: 1.1rem 1.25rem;
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 1.25rem;
    box-shadow: var(--pico-card-box-shadow);
}

.panel > h2:first-child {
    margin-top: 0;
}

.rows {
    list-style: none;
    margin: 0;
    padding: 0;
}

.rows > li {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 0;
    margin: 0;
    list-style: none;
    border-top: 1px solid var(--pico-muted-border-color);
}

.rows > li:first-child {
    border-top: 0;
}

.rows .grow {
    flex: 1;
    min-width: 0;
}

.rows .grow strong,
.rows .grow a {
    display: block;
}

.rows .grow a {
    color: var(--ink);
    font-weight: 600;
}

.rows .grow small {
    display: block;
    line-height: 1.3;
}

.rows form {
    margin: 0;
}

.icon-circle {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 50%;
    background: var(--leaf-soft);
    font-size: 1.15rem;
}

.row-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

/* ---------- Detailseite ---------- */
.hero {
    display: grid;
    grid-template-columns: minmax(0, 340px) 1fr;
    gap: 1.5rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.hero-media {
    aspect-ratio: 1;
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: var(--pico-card-box-shadow);
}

.hero-media .placeholder {
    font-size: 5rem;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
}

.chip {
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    font-size: 0.875rem;
}

.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.actions > * {
    margin: 0;
}

@media (max-width: 640px) {
    .hero {
        grid-template-columns: 1fr;
    }

    .hero-media {
        aspect-ratio: 4 / 3;
    }
}

/* Aufklappbare Formulare */
.panel details {
    margin: 0.75rem 0 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--pico-muted-border-color);
}

.panel details summary {
    font-weight: 600;
    color: var(--pico-primary);
}

.panel details[open] summary {
    margin-bottom: 1rem;
}

/* ---------- Formularseiten ---------- */
.form-card {
    max-width: 520px;
    margin: 1rem auto;
}

.form-card .panel {
    padding: 1.5rem;
}

.auth-card {
    max-width: 400px;
    margin: 6vh auto 0;
    text-align: center;
}

.auth-card form {
    text-align: left;
}

.auth-card .brand-mark {
    width: 3.5rem;
    height: 3.5rem;
    margin: 0 auto 1rem;
    border-radius: 1.1rem;
    font-size: 1.8rem;
}

/* ---------- Leerer Zustand ---------- */
.empty {
    padding: 2.5rem 1rem;
    text-align: center;
}

.empty .emoji {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.empty p {
    margin: 0.25rem auto 1rem;
    max-width: 32rem;
    color: var(--pico-muted-color);
}

/* ---------- Meldungen ---------- */
.message {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    border-radius: 0.9rem;
    background: var(--leaf-soft);
    color: var(--leaf-strong);
    font-weight: 500;
}

.message::before {
    content: "✓";
    font-weight: 700;
}

.grid-cards + .panel,
.empty + .panel {
    margin-top: 1.5rem;
}

.empty .actions {
    justify-content: center;
}

/* Schmale Bildschirme: Status und Knöpfe einer Zeile rutschen in eine zweite Reihe. */
@media (max-width: 640px) {
    .rows > li {
        flex-wrap: wrap;
    }

    .rows .grow {
        flex: 1 1 9rem;
    }

    .rows > li > form {
        margin-left: auto;
    }

    .rows > li > .badge {
        margin-left: 3.25rem;
    }

    .rows > li > .row-actions {
        margin-left: auto;
    }
}
