/* ============================================================
   Seedcode - css/main.css
   Grundlayout, Farbschema, Basiskomponenten.
   Mobile-first, ohne Hover-Zwang, große Touch-Ziele.
   ============================================================ */

:root {
    --bg:          #10161a;
    --bg-2:        #161f25;
    --bg-3:        #1d2830;
    --line:        #2a3842;
    --text:        #e4eef0;
    --text-dim:    #93a6b0;
    --accent:      #63d29a;
    --accent-dark: #2f8f63;
    --warn:        #f0b849;
    --bad:         #ef6f6c;
    --good:        #63d29a;
    --water:       #4fa3ff;
    --light:       #ffd45e;
    --nutrient:    #c98cff;
    --radius:      12px;
    --radius-sm:   8px;
    --panel-w:     380px;
    --tap:         44px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 600; line-height: 1.25; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
h4 { font-size: .88rem; letter-spacing: .02em; color: var(--text); }
p { margin: 0 0 .6em; }
ul { margin: 0; padding-left: 1.1em; }

.muted { color: var(--text-dim); }
.small { font-size: .8rem; }
.warn-text { color: var(--warn); }

/* ---------- App-Grid ---------- */

.app {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr var(--panel-w);
    grid-template-areas:
        "top  top"
        "room panel";
    height: 100dvh;
    height: 100vh;
}

.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    z-index: 20;
}

.brand { font-weight: 700; letter-spacing: .04em; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.brand-mark { color: var(--accent); width: 20px; height: 20px; flex: 0 0 20px; }

.ico { width: 1em; height: 1em; fill: currentColor; vertical-align: -.13em; flex: 0 0 auto; }
.stat i .ico { width: .95em; height: .95em; }

.stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }

.stat {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 11px;
    font-size: .85rem;
    white-space: nowrap;
}
.stat i { font-style: normal; color: var(--text-dim); display: inline-flex; align-items: center; }
.stat b { font-variant-numeric: tabular-nums; }

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

.btn {
    appearance: none;
    border: 1px solid var(--line);
    background: var(--bg-3);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    min-height: var(--tap);
    font: inherit;
    font-size: .9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    touch-action: manipulation;
}
.btn em { font-style: normal; color: var(--text-dim); font-size: .8em; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: .82rem; }
.btn-primary { background: var(--accent-dark); border-color: var(--accent); color: #eafff4; }
.btn-ghost { background: transparent; }
.btn-danger { border-color: #7a3b3b; color: #ffbfbd; background: #2a1a1c; }

.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row.wrap { flex-wrap: wrap; }

.icon-btn {
    appearance: none;
    width: var(--tap); height: var(--tap);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--bg-3);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

.text-input {
    width: 100%;
    padding: 10px 12px;
    min-height: var(--tap);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.switch {
    display: flex; align-items: center; gap: 8px;
    margin: 10px 0 0; min-height: var(--tap);
}
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 28px;
    margin: 0;
    width: 100%;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px; background: var(--bg-3); border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track {
    height: 6px; border-radius: 3px; background: var(--bg-3); border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px; height: 22px; margin-top: -9px;
    border-radius: 50%; background: var(--accent); border: none; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: 22px; height: 22px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer;
}
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--line); }
input[type="range"]:disabled::-moz-range-thumb { background: var(--line); }

/* ---------- Panel ---------- */

.panel {
    grid-area: panel;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-left: 1px solid var(--line);
    min-height: 0;
}

.sheet-handle { display: none; }

.tabs {
    display: flex;
    gap: 2px;
    padding: 6px 6px 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-dim);
    padding: 10px 12px;
    min-height: var(--tap);
    font: inherit;
    font-size: .88rem;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    white-space: nowrap;
}
.tab.active { color: var(--text); background: var(--bg-3); box-shadow: inset 0 -2px 0 var(--accent); }

.panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
}

.panel-title { margin-bottom: 10px; }

.card {
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}

.kv {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 3px 0; font-size: .88rem;
}
.kv b { font-variant-numeric: tabular-nums; }

.empty-hint {
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    color: var(--text-dim);
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chip {
    font-size: .74rem; padding: 2px 8px; border-radius: 999px;
    background: rgba(99, 210, 154, .13); color: var(--accent);
    border: 1px solid rgba(99, 210, 154, .3);
}
.chip-dim { background: transparent; color: var(--text-dim); border-color: var(--line); }
.chip-ok { background: rgba(99, 210, 154, .2); }

.hints li { margin-bottom: .4em; font-size: .84rem; color: var(--text-dim); }

/* ---------- Toasts ---------- */

.toasts {
    position: fixed;
    right: calc(var(--panel-w) + 16px);
    top: 64px;
    display: flex; flex-direction: column; gap: 6px;
    z-index: 60; width: min(420px, calc(100vw - 24px));
    pointer-events: none;
}
.toast {
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-left: 3px solid var(--text-dim);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: .86rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    animation: toast-in .18s ease-out;
}
.toast-good { border-left-color: var(--good); }
.toast-bad  { border-left-color: var(--bad); }
.toast-info { border-left-color: var(--water); }
.toast-out  { opacity: 0; transition: opacity .5s ease; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */

.modal-root { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.modal-root.open { pointer-events: auto; }

.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(6, 10, 12, .72);
    display: flex; align-items: center; justify-content: center;
    padding: 14px;
    animation: toast-in .15s ease-out;
}

.modal {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    width: min(620px, 100%);
    max-height: min(88dvh, 88vh);
    display: flex; flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal-head {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1rem; flex: 1; }
.modal-body { padding: 12px; overflow-y: auto; }
.modal-foot {
    display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
    padding: 10px 12px; border-top: 1px solid var(--line);
}

/* ---------- Mobil: Panel wird Bottom Sheet ---------- */

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "top"
            "room";
    }

    .topbar { gap: 8px; padding: 6px 10px; }
    .topbar > .btn { display: none; }
    .brand { font-size: .95rem; }
    .stats { flex-wrap: nowrap; gap: 5px; }
    .stat { padding: 2px 8px; font-size: .76rem; }

    .panel {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: 64dvh;
        border-left: none;
        border-top: 1px solid var(--line);
        border-radius: 16px 16px 0 0;
        transform: translateY(calc(100% - 108px));
        transition: transform .22s ease;
        z-index: 40;
        box-shadow: 0 -12px 34px rgba(0, 0, 0, .45);
    }
    .panel.open { transform: translateY(0); }

    .sheet-handle {
        display: block;
        width: 100%; height: 26px;
        border: none; background: transparent; cursor: pointer;
        position: relative;
    }
    .sheet-handle::before {
        content: "";
        position: absolute; left: 50%; top: 10px;
        transform: translateX(-50%);
        width: 44px; height: 4px; border-radius: 2px;
        background: var(--line);
    }

    .toasts {
        right: auto;
        left: 50%;
        top: auto;
        transform: translateX(-50%);
        bottom: calc(122px + env(safe-area-inset-bottom));
    }
}

/* ---------- Startfehler (z. B. Daten nicht ladbar) ---------- */

.fatal {
    grid-column: 1 / -1;
    max-width: 640px;
    margin: 12vh auto;
    padding: 24px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--bad);
    border-radius: var(--radius);
}
.fatal h1 { font-size: 1.25rem; margin-bottom: .6em; }
.fatal-msg { color: var(--warn); }
.fatal code { background: var(--bg-3); padding: 1px 5px; border-radius: 4px; }
.fatal pre {
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    overflow-x: auto;
    font-size: .85rem;
}
