/* ==========================================================================
   Layout: dunkle Seitenleiste („Kommandozentrale“) + helle Arbeitsfläche
   ========================================================================== */

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

/* --- Seitenleiste --------------------------------------------------------- */
.sidebar {
    position: sticky; top: 0; height: 100vh; z-index: 30;
    display: flex; flex-direction: column; gap: var(--space-5);
    padding: var(--space-5) var(--space-4);
    background: var(--gradient-ink); color: #c9d4e4;
    overflow: hidden; overflow: clip; isolation: isolate;
}
/* Bögen der Weltkugel als zartes Muster */
.sidebar::before {
    content: ""; position: absolute; inset: auto -120px -140px auto; width: 420px; height: 420px; z-index: -1; pointer-events: none;
    background: url("../brand/globe-white.png") center / contain no-repeat; opacity: .05;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: var(--space-1) var(--space-2); color: #fff; }
.brand:hover { color: #fff; }
.brand-mark { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 4px 14px rgba(74, 182, 206, .45)); }
.brand-name { display: block; font-weight: 800; font-size: 1.02rem; letter-spacing: .06em; line-height: 1.05; color: #fff; }
.brand-sub { display: block; font-size: .64rem; font-weight: 750; letter-spacing: var(--tracking-wide); text-transform: uppercase; margin-top: .2rem; }

/* Schnellzugriff (Strg+K) */
.quick-open {
    display: flex; align-items: center; gap: .6rem; width: 100%; height: 40px; padding: 0 .75rem;
    border-radius: 12px; border: 1px solid rgba(255, 255, 255, .09); background: rgba(255, 255, 255, .05);
    color: #8fa0b8; font: inherit; font-size: .86rem; cursor: pointer; transition: all var(--duration) var(--ease);
    white-space: nowrap; overflow: hidden;
}
.quick-open span { overflow: hidden; text-overflow: ellipsis; }
.quick-open:hover { background: rgba(255, 255, 255, .09); color: #dbe5f2; border-color: rgba(255, 255, 255, .16); }
.quick-open kbd { margin-left: auto; font: 600 .7rem var(--font); color: #8fa0b8; border: 1px solid rgba(255, 255, 255, .14); border-radius: 6px; padding: .05rem .35rem; }

.sidebar-cta .btn { width: 100%; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; margin: 0 -.25rem; padding: 0 .25rem; }
.nav::-webkit-scrollbar { display: none; }
.nav-label { font-size: .64rem; font-weight: 750; text-transform: uppercase; letter-spacing: var(--tracking-wide); color: #6f819b; padding: var(--space-4) var(--space-3) .4rem; }
.nav a {
    position: relative; display: flex; align-items: center; gap: .7rem; padding: .55rem var(--space-3); border-radius: 12px;
    color: #b3c1d4; font-weight: 600; font-size: .9rem; transition: background var(--duration), color var(--duration);
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(74, 182, 206, .13); color: #fff; }
/* Aktiver Eintrag: leuchtender Knoten wie im Logo */
.nav a.active::before {
    content: ""; position: absolute; left: -10px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%;
    background: var(--cyan-400); box-shadow: 0 0 0 3px rgba(74, 182, 206, .2), 0 0 12px rgba(74, 182, 206, .8);
}
.nav a .i { width: 1.15em; height: 1.15em; }
.nav-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--accent, #fff) 22%, transparent); color: color-mix(in srgb, var(--accent, #fff) 55%, #fff); margin-left: -.15rem; }
.nav-icon .i { width: .95em; height: .95em; }

/* --- Benutzermenü (Drop-up) --------------------------------------------- */
.user-menu { position: relative; flex: none; }
.user-trigger {
    display: flex; align-items: center; gap: .65rem; width: 100%; padding: .6rem .7rem; text-align: left; cursor: pointer;
    border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08); color: inherit; font: inherit;
    transition: background var(--duration), border-color var(--duration);
}
.user-trigger:hover, .user-menu.open .user-trigger { background: rgba(255, 255, 255, .09); border-color: rgba(255, 255, 255, .16); }
.user-trigger .avatar { background: var(--gradient-brand-strong); color: #fff; }
.user-trigger .who { min-width: 0; flex: 1; line-height: 1.25; }
.user-trigger .who strong { display: block; font-size: .86rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-trigger .who small { font-size: .74rem; color: #8fa0b8; }
.user-trigger .chev { color: #8fa0b8; transition: transform var(--duration) var(--ease); }
.user-menu.open .chev { transform: rotate(180deg); }

.menu-pop {
    position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 60; padding: .4rem;
    border-radius: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--hairline); box-shadow: var(--shadow-lg);
    animation: pop-up .16s var(--ease);
}
@keyframes pop-up { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.menu-head { padding: .65rem .7rem .55rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu-head strong { display: block; font-size: .9rem; }
.menu-head span { font-size: .76rem; color: var(--muted); }
.menu-item {
    display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .7rem; border-radius: 10px; border: 0; background: none;
    color: var(--text-2); font: inherit; font-size: .88rem; font-weight: 650; text-align: left; cursor: pointer;
}
.menu-item .i { color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--primary-soft); color: var(--navy); outline: none; }
.menu-item:hover .i { color: var(--cyan); }
.menu-item kbd { margin-left: auto; font: 700 .68rem var(--font); color: var(--muted); border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 .3rem; }
.menu-item small { margin-left: auto; font-size: .7rem; color: var(--muted); font-weight: 600; }
.menu-item.disabled { cursor: not-allowed; color: var(--muted); }
.menu-item.disabled:hover { background: none; color: var(--muted); }
.menu-sep { border: 0; border-top: 1px solid var(--border); margin: .3rem 0; }

/* --- Inhalt ------------------------------------------------------------------- */
.main {
    min-width: 0; padding: var(--space-8) clamp(1rem, 3.2vw, 2.75rem) 6rem;
    background: radial-gradient(80% 40% at 50% -10%, rgba(74, 182, 206, .10), transparent 70%);
}
.page { max-width: var(--content-max); margin: 0 auto; animation: rise .35s var(--ease) backwards; }
.page-narrow { max-width: 880px; margin: 0 auto; animation: rise .35s var(--ease) backwards; }

/* Elemente, die es nur auf dem Handy gibt */
.topbar, .bottom-nav, .drawer-backdrop, .drawer-close, .topbar-menu { display: none; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }

/* --- Handy: Kopfzeile · Schublade · Bottom-Navigation · Konto-Sheet ---------
   Unten fest: Start · Tools · Suchen · Konto (Daumenbereich).
   „Tools“ schiebt die vollständige Seitenleiste von links herein – dieselbe
   Navigation wie am Desktop. Im Editor (mit .savebar) weicht die Bottom-Navigation
   der Speichern-Leiste; dann öffnet der Menü-Knopf oben die Schublade. */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .desktop-only, .quick-open kbd, .palette-foot { display: none; }

    .topbar {
        position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: var(--space-3);
        min-height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--space-4) 0;
        background: var(--gradient-ink); color: #fff;
    }
    .topbar .brand { padding: 0; flex: none; }
    .topbar .brand-mark { width: 30px; height: 30px; }
    .topbar .brand-name { font-size: .88rem; }
    .topbar .brand-sub { font-size: .56rem; margin-top: .12rem; }
    .topbar-context {
        margin-left: auto; display: inline-flex; align-items: center; gap: .45rem; min-width: 0;
        font-size: .8rem; font-weight: 700; color: #b3c1d4; white-space: nowrap; overflow: hidden;
    }
    .topbar-context .nav-icon { width: 22px; height: 22px; margin: 0; border-radius: 7px; }
    .topbar-menu, .drawer-close {
        place-items: center; flex: none; width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
        border: 1px solid rgba(255, 255, 255, .1); background: rgba(255, 255, 255, .05); color: #dbe5f2;
    }
    .topbar-menu { margin-left: auto; }
    .topbar-context + .topbar-menu { margin-left: 0; }
    .drawer-close { display: grid; }

    /* Seitenleiste als Schublade */
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: auto; z-index: 70;
        padding: calc(var(--space-5) + env(safe-area-inset-top)) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom));
        transform: translateX(-102%); visibility: hidden;
        transition: transform .3s var(--ease), visibility 0s linear .3s;
    }
    body.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .3s var(--ease); box-shadow: 24px 0 60px rgba(4, 10, 20, .35); }
    .drawer-backdrop {
        display: block; position: fixed; inset: 0; z-index: 65; background: rgba(11, 20, 36, .5); backdrop-filter: blur(4px);
        opacity: 0; visibility: hidden; transition: opacity .3s var(--ease), visibility 0s linear .3s;
    }
    body.drawer-open .drawer-backdrop { opacity: 1; visibility: visible; transition: opacity .3s var(--ease); }
    body.drawer-open, body.sheet-open { overflow: hidden; }

    /* Bottom-Navigation */
    .bottom-nav {
        display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
        padding: .3rem .5rem calc(.3rem + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .9); backdrop-filter: blur(16px) saturate(1.4);
        border-top: 1px solid var(--hairline); box-shadow: 0 -8px 24px rgba(15, 27, 45, .06);
    }
    .bottom-nav > a, .bottom-nav > button {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; min-height: 54px; padding: 0;
        border: 0; background: none; color: var(--muted); font: inherit; font-size: .7rem; font-weight: 700; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .bn-icon { display: grid; place-items: center; width: 50px; height: 30px; border-radius: 999px; transition: background var(--duration), color var(--duration); }
    .bn-icon .i { width: 1.3em; height: 1.3em; }
    .bottom-nav .active, .bottom-nav [aria-expanded="true"] { color: var(--navy); }
    .bottom-nav .active .bn-icon, .bottom-nav [aria-expanded="true"] .bn-icon { background: var(--primary-soft); }
    .bn-icon.bn-avatar { width: 28px; height: 28px; margin: 1px 0; border-radius: 50%; background: var(--gradient-brand-strong); color: #fff; font-size: .64rem; font-weight: 800; }
    .bottom-nav [aria-expanded="true"] .bn-avatar { background: var(--gradient-brand-strong); box-shadow: 0 0 0 3px var(--primary-soft); }
    .main { padding-top: var(--space-5); padding-bottom: calc(6.5rem + env(safe-area-inset-bottom)); }
    .toast { left: var(--space-4); right: var(--space-4); bottom: calc(5rem + env(safe-area-inset-bottom)); }

    /* Editor: Speichern-Leiste statt Bottom-Navigation, Menü-Knopf oben */
    body:has(.savebar) .bottom-nav { display: none; }
    body:has(.savebar) .topbar-menu { display: grid; }

    /* Konto-Sheet */
    .sheet-backdrop:not([hidden]) {
        display: flex; align-items: flex-end; position: fixed; inset: 0; z-index: 75;
        background: rgba(11, 20, 36, .45); backdrop-filter: blur(4px); animation: fade-in .2s var(--ease);
    }
    .sheet {
        width: 100%; padding: .4rem .75rem calc(.75rem + env(safe-area-inset-bottom));
        border-radius: 22px 22px 0 0; background: var(--surface); box-shadow: var(--shadow-lg); animation: sheet-up .28s var(--ease);
    }
    .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: .3rem auto .5rem; }
    .sheet .menu-item { padding: .8rem .75rem; font-size: .95rem; }
}
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
    .sidebar, .drawer-backdrop, .sheet, .sheet-backdrop:not([hidden]) { transition: none !important; animation: none !important; }
}

/* --- Seitenkopf ------------------------------------------------------------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-4) var(--space-8); flex-wrap: wrap; margin-bottom: var(--space-8); }
.page-head .eyebrow { display: inline-flex; align-items: center; gap: .4rem; font-size: var(--text-xs); font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .55rem; }
.page-head .eyebrow:hover { color: var(--navy); }
.page-head .meta { color: var(--muted); margin-top: .5rem; display: flex; gap: .4rem var(--space-5); flex-wrap: wrap; font-size: .9rem; }
.page-head .meta span { display: inline-flex; align-items: center; gap: .4rem; }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* --- Raster ------------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-6); align-items: start; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: var(--space-6); }
@media (max-width: 1080px) { .sticky { position: static; } }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin: 0 0 var(--space-4); }
.section-title h2 { font-size: var(--text-lg); }

/* Arbeitsbereich: Formular links, Live-Zusammenfassung rechts (Editor-Muster) */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1.75rem; align-items: start; max-width: 1100px; margin: 0 auto; }
@media (max-width: 1080px) { .workspace { grid-template-columns: 1fr; } .workspace-panel { display: none; } }

/* Mobile Aktionsleiste (Betrag + Speichern) */
.savebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: none; align-items: center; gap: var(--space-4);
    padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .86); backdrop-filter: blur(14px) saturate(1.4);
    border-top: 1px solid var(--hairline); box-shadow: 0 -10px 30px rgba(15, 27, 45, .08);
}
.savebar .total { font-size: 1.4rem; font-weight: 800; letter-spacing: var(--tracking-tight); }
.savebar .btn { margin-left: auto; }
@media (max-width: 1080px) { .savebar { display: flex; } .main:has(.savebar) { padding-bottom: 7rem; } }

/* --- Schnellzugriff-Dialog (Strg+K) ---------------------------------------- */
.palette-backdrop {
    position: fixed; inset: 0; z-index: 80; display: none; align-items: flex-start; justify-content: center; padding: 12vh var(--space-4) 0;
    background: rgba(11, 20, 36, .45); backdrop-filter: blur(6px);
}
.palette-backdrop.open { display: flex; animation: rise .18s var(--ease); }
.palette { width: min(620px, 100%); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--hairline); }
.palette-input { display: flex; align-items: center; gap: .7rem; padding: 0 var(--space-5); border-bottom: 1px solid var(--border); }
.palette-input .i { color: var(--muted); }
.palette-input input { flex: 1; height: 58px; border: 0; outline: 0; font: 600 1.05rem var(--font); color: var(--text); background: transparent; }
.palette-list { max-height: 50vh; overflow-y: auto; padding: var(--space-2); margin: 0; list-style: none; }
.palette-list .group { padding: .6rem .75rem .3rem; font-size: .64rem; font-weight: 750; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--muted); }
.palette-list a { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border-radius: 12px; color: var(--text); font-weight: 600; }
.palette-list a .ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft, var(--surface-3)); color: var(--accent, var(--text-2)); flex: none; }
.palette-list a small { margin-left: auto; color: var(--muted); font-weight: 600; font-size: .75rem; }
.palette-list a.selected, .palette-list a:hover { background: var(--primary-soft); color: var(--navy); }
.palette-empty { padding: var(--space-6); text-align: center; color: var(--muted); }
.palette-foot { display: flex; gap: var(--space-4); padding: .55rem var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2); font-size: .74rem; color: var(--muted); }
.palette-foot kbd { font: 700 .68rem var(--font); border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 .3rem; background: var(--surface); }

/* --- Modal ------------------------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 85; display: none; align-items: flex-start; justify-content: center;
    padding: 8vh var(--space-4) var(--space-4); overflow-y: auto; background: rgba(11, 20, 36, .45); backdrop-filter: blur(6px);
}
.modal-backdrop.open { display: flex; animation: rise .18s var(--ease); }
.modal { width: min(600px, 100%); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-lg); border: 1px solid var(--hairline); overflow: hidden; }
.modal-head { position: relative; padding: 1.4rem 1.5rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-head::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--gradient-brand); }
.modal-head .eyebrow-label { color: var(--cyan); }
.modal-head h2 { font-size: 1.3rem; font-weight: 800; margin-top: .2rem; }
.modal-head p { color: var(--muted); font-size: .88rem; margin-top: .3rem; padding-right: 2.5rem; }
.modal-head .modal-close { position: absolute; top: 1rem; right: 1rem; }
.modal-body { padding: 1.4rem 1.5rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-loading { padding: 3rem; display: grid; place-items: center; color: var(--muted); }

/* Bestätigung (statt window.confirm): kurz, mit klarer Folge und sicherer Vorauswahl „Abbrechen“ */
.confirm-backdrop { z-index: 88; align-items: center; padding-top: var(--space-4); }
.modal.confirm { width: min(440px, 100%); padding: 1.5rem 1.5rem 1.25rem; text-align: center; animation: pop-up .18s var(--ease); }
.confirm-icon { width: 52px; height: 52px; margin: 0 auto .9rem; border-radius: 16px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); }
.confirm-icon .i { width: 1.5em; height: 1.5em; }
.confirm.tone-primary .confirm-icon { background: var(--primary-soft); color: var(--navy); }
.confirm h2 { font-size: 1.2rem; font-weight: 800; }
.confirm p { color: var(--muted); font-size: .92rem; margin-top: .4rem; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: 1.4rem; }
