:root {
    /* Fallbacks – werden im _Layout aus den Theme-Einstellungen überschrieben */
    --accent: #6366f1;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --tile-radius: 18px;

    --border: color-mix(in srgb, var(--text) 12%, transparent);
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html {
    background:
        radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

body {
    margin: 0;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;
    color: var(--text);
    font-family: "Plus Jakarta Sans", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand__title {
    font-family: "Bricolage Grotesque", "Plus Jakarta Sans", sans-serif;
    letter-spacing: -.01em;
}

/* ---------- Kopfzeile ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(14px);
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    border-bottom: 1px solid var(--border);
}

.app-header__inner {
    max-width: 1320px;
    margin: 0 auto;
    padding: .75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
    flex: 1 1 200px;
}

.brand__mark {
    display: grid;
    place-items: center;
    width: calc(42px * var(--brand-scale, 1));
    height: calc(42px * var(--brand-scale, 1));
    flex: 0 0 auto;
    border-radius: 12px;
    font-size: calc(1.2rem * var(--brand-scale, 1));
    color: #fff;
    overflow: hidden;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #000));
    box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 80%, transparent);
}
.brand__mark img { width: 100%; height: 100%; object-fit: cover; }

.brand__text { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.brand__title { font-weight: 700; font-size: 1.05rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand__sub { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app-nav { display: flex; align-items: center; gap: .35rem; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .7rem;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 8%, transparent); border-color: var(--border); }

/* ---------- Layout ---------- */
.app-main { flex: 1 0 auto; }

.app-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    padding: 1.5rem;
    color: var(--muted);
    font-size: .8rem;
}

.section-title {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin: 2rem 0 .9rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.section-title:first-of-type { margin-top: .5rem; }
.section-title .to-top {
    display: inline-grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    font-size: 1rem;
    line-height: 1;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.section-title .to-top:hover {
    color: var(--text);
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, transparent);
}
#seitenanfang { scroll-margin-top: 84px; }
.cat-nav { scroll-margin-top: 84px; }

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

.tile {
    --tile-bg: var(--accent);
    --tile-fg: #fff;
    position: relative;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.2rem;
    border-radius: var(--tile-radius);
    text-decoration: none;
    color: var(--tile-fg);
    background:
        linear-gradient(135deg,
            color-mix(in srgb, var(--tile-bg) 92%, #fff 0%),
            color-mix(in srgb, var(--tile-bg) 78%, #000 14%));
    border: 1px solid color-mix(in srgb, #fff 14%, transparent);
    box-shadow: var(--shadow);
    overflow: hidden;
    isolation: isolate;
    transition: transform .18s cubic-bezier(.2,.7,.3,1), box-shadow .18s ease, filter .18s ease;
}
.tile::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(140px 90px at 85% 0%, rgba(255,255,255,.25), transparent 70%);
    opacity: .6;
    z-index: -1;
}
.tile:hover {
    transform: translateY(-4px);
    filter: saturate(1.05) brightness(1.03);
    box-shadow: 0 22px 40px -16px rgba(0,0,0,.6);
}

.tile__icon {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: calc(52px * var(--tile-media, 1));
    height: calc(52px * var(--tile-media, 1));
    border-radius: 14px;
    background: rgba(255,255,255,.16);
    font-size: calc(1.6rem * var(--tile-media, 1));
}
.tile__icon img { width: calc(32px * var(--tile-media, 1)); height: calc(32px * var(--tile-media, 1)); object-fit: contain; }

.tile__body { min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.tile__title { font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.tile__desc {
    font-size: .82rem;
    opacity: .85;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.tile__arrow {
    position: absolute;
    top: .7rem;
    right: .8rem;
    opacity: .55;
    font-size: .9rem;
    transition: transform .18s ease, opacity .18s ease;
}
.tile:hover .tile__arrow { opacity: 1; transform: translate(2px,-2px); }

/* ---------- Leerer Zustand ---------- */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--muted);
}
.empty-state i { font-size: 3rem; opacity: .6; }
.empty-state h2 { color: var(--text); margin-top: 1rem; }

/* ---------- Karten / Panels ---------- */
.card-panel {
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.4rem;
    box-shadow: var(--shadow);
}

.text-muted-soft { color: var(--muted) !important; }
.link-subtle { color: var(--muted); text-decoration: none; }
.link-subtle:hover { color: var(--text); }

.badge-soft {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    color: var(--text);
}

/* ---------- Formulare (Bootstrap-Overrides) ---------- */
.form-label { font-weight: 600; font-size: .85rem; color: var(--text); }
.form-text, .form-check-label { color: var(--muted); }

.form-control, .form-select {
    background: color-mix(in srgb, var(--bg) 50%, var(--surface));
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
}
.form-control:focus, .form-select:focus {
    background: color-mix(in srgb, var(--bg) 40%, var(--surface));
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--accent) 30%, transparent);
}
.form-control::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }

.color-field { display: flex; gap: .5rem; align-items: center; }
.form-control-color { width: 48px; min-width: 48px; height: 42px; padding: .2rem; border-radius: 10px; }

.btn-accent {
    --b: var(--accent);
    background: linear-gradient(135deg, var(--b), color-mix(in srgb, var(--b) 65%, #000));
    border: none;
    color: #fff;
    font-weight: 600;
    border-radius: 10px;
    padding: .55rem 1.1rem;
}
.btn-accent:hover { color: #fff; filter: brightness(1.08); }
.btn-outline-light { border-radius: 10px; }

.form-switch .form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }

/* ---------- Tabelle ---------- */
.table-dark-soft { color: var(--text); --bs-table-bg: transparent; }
.table-dark-soft thead th {
    color: var(--muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 1px solid var(--border);
    padding: .9rem 1rem;
}
.table-dark-soft td { border-bottom: 1px solid var(--border); padding: .8rem 1rem; }
.table-dark-soft tbody tr:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }

.mini-tile {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.1rem;
}
.mini-tile img { width: 24px; height: 24px; object-fit: contain; }

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-icon:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }
.btn-icon--danger:hover { background: color-mix(in srgb, #ef4444 22%, transparent); border-color: #ef4444; color: #fecaca; }

/* ---------- Icon-Picker ---------- */
.icon-chosen {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--text);
    font-size: 1.8rem;
    cursor: pointer;
}

.icon-modal { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.icon-modal .modal-header { border-color: var(--border); }

.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: .5rem;
}
.icon-grid button {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 40%, var(--surface));
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.icon-grid button:hover { transform: translateY(-2px); background: color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.icon-grid button.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

.login-mark {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 18px;
    font-size: 1.8rem;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
}

.preview-wrap { display: grid; }

/* ---------- Theme-Vorschau ---------- */
.theme-preview {
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 1rem;
    background: var(--bg);
    box-shadow: var(--shadow);
}
.theme-preview__bar { display: flex; align-items: center; gap: .5rem; margin-bottom: .9rem; }
.theme-preview__dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); }
.theme-preview__title { font-weight: 700; color: var(--text); }
.theme-preview__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.theme-preview__tile {
    border-radius: 12px; padding: 1.1rem .6rem; text-align: center; font-size: .8rem; font-weight: 600;
    background: var(--accent); color: #fff;
}
.theme-preview__tile--surface { background: var(--surface); color: var(--text); }
.theme-preview__text { margin: .9rem 0 0; color: var(--text); font-size: .9rem; }
.theme-preview__muted { color: var(--muted); }

.preset-bar { display: flex; gap: .5rem; flex-wrap: wrap; }
.preset {
    width: 34px; height: 34px; border-radius: 9px;
    border: 1px solid var(--border); cursor: pointer; padding: 0;
    transition: transform .12s ease, box-shadow .12s ease;
}
.preset:hover { transform: scale(1.1); box-shadow: 0 4px 12px rgba(0,0,0,.35); }

/* ---------- Animation beim Laden ---------- */
.tile { animation: tileIn .45s ease both; }
.tile-grid .tile:nth-child(1) { animation-delay: .02s; }
.tile-grid .tile:nth-child(2) { animation-delay: .06s; }
.tile-grid .tile:nth-child(3) { animation-delay: .10s; }
.tile-grid .tile:nth-child(4) { animation-delay: .14s; }
.tile-grid .tile:nth-child(5) { animation-delay: .18s; }
.tile-grid .tile:nth-child(n+6) { animation-delay: .22s; }

@keyframes tileIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .tile, .tile * { animation: none !important; transition: none !important; }
}

/* ---------- Mobil ---------- */
@media (max-width: 575.98px) {
    .tile-grid { grid-template-columns: 1fr 1fr; gap: .7rem; }
    .tile { flex-direction: column; align-items: flex-start; padding: .9rem; }
    .tile__title { font-size: .92rem; }
    .tile__desc { display: none; }
    .brand__sub { display: none; }
    .app-header__inner { padding: .6rem .9rem; }
    .btn-ghost { padding: .45rem .55rem; font-size: .85rem; }
    .app-nav { gap: .2rem; }
}

/* ---------- Eigene Inhalte (Kopf/Fuß) & Impressum ---------- */
.custom-html {
    color: var(--text);
    margin-bottom: 1.5rem;
}
.custom-html--bottom { margin-top: 2rem; margin-bottom: .5rem; }
.custom-html :where(h1, h2, h3) { color: var(--text); }
.custom-html a { color: var(--accent); }

.imprint-content { color: var(--text); line-height: 1.7; }
.imprint-content :where(h1, h2, h3) { color: var(--text); }
.imprint-content a { color: var(--accent); }
.imprint-content p { margin-bottom: 1rem; }

/* Monospace-Eingabe für HTML-Felder */
textarea.text-monospace,
.text-monospace {
    font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
    font-size: .85rem;
}
textarea.form-control { resize: vertical; }

/* ---------- Footer-Link (Impressum) ---------- */
.app-footer__sep { margin: 0 .5rem; opacity: .5; }
.app-footer__link { color: var(--muted); text-decoration: none; }
.app-footer__link:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Verwaltung: inaktive Kacheln ---------- */
.row-disabled { opacity: .5; }
.row-disabled .mini-tile { filter: grayscale(.6); }
.badge-off {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .12rem .45rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    background: color-mix(in srgb, var(--muted) 12%, transparent);
}

/* ---------- Kachel mit Screenshot-Vorschaubild ---------- */
.tile--shot .tile__icon {
    width: calc(76px * var(--tile-media, 1));
    height: calc(56px * var(--tile-media, 1));
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255,255,255,.10);
}
.tile--shot .tile__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
}

/* ---------- Verwaltung: Kategorie-Blöcke ---------- */
.cat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin: 0 .25rem .6rem;
}
.cat-head h2 { display: inline-flex; align-items: center; gap: .45rem; }
.cat-head .bi-folder2-open, .cat-head .bi-folder2 { color: var(--accent); }

/* ---------- Kategorie-Navigation auf dem Dashboard ---------- */
html { scroll-behavior: smooth; }
.section-title { scroll-margin-top: 84px; }

.cat-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1.5rem;
}
.cat-chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .4rem .8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    color: var(--text);
    text-decoration: none;
    font-size: .88rem;
    font-weight: 600;
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.cat-chip:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    transform: translateY(-1px);
}
.cat-chip__count {
    display: inline-grid;
    place-items: center;
    min-width: 1.4em;
    height: 1.4em;
    padding: 0 .35em;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    color: var(--text);
    font-size: .75rem;
    line-height: 1;
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* ---------- Hintergrund-Wasserzeichen ---------- */
.bg-watermark {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
}
.bg-watermark--icon {
    display: grid;
    place-items: center;
    color: var(--text);
}
.bg-watermark--icon .bi {
    font-size: min(70vw, 70vh);
    line-height: 1;
}
.bg-watermark--image {
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
}

/* ---------- Verwaltung: Sichtbarkeits-Hinweis ---------- */
.badge-scope {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .12rem .45rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* ---------- Design: Vorschau Medien-Größe & Kachel-Farbvorlagen ---------- */
.tile--shot-preview {
    width: calc(76px * var(--tile-media, 1)) !important;
    height: calc(56px * var(--tile-media, 1)) !important;
}
.tile-swatches { display: flex; flex-wrap: wrap; gap: .4rem; }
.tile-swatch {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    border: 1px solid var(--border);
    font-weight: 800;
    font-size: .9rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .08s ease, box-shadow .08s ease;
}
.tile-swatch:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.25); }

/* ---------- Kachel mit Favicon der verlinkten Seite ---------- */
.tile__icon--favicon { position: relative; }
.tile__icon--favicon > i {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}
/* Solange das Favicon-Bild vorhanden ist (geladen), das Ausweich-Icon ausblenden,
   damit es bei transparenten Favicons nicht durchscheint. Schlägt das Laden fehl,
   entfernt sich das Bild selbst (onerror) und das Icon wird wieder sichtbar. */
.tile__icon--favicon:has(img) > i { display: none; }
.tile__icon--favicon > img {
    position: relative;
    z-index: 1;
    width: calc(32px * var(--tile-media, 1));
    height: calc(32px * var(--tile-media, 1));
    object-fit: contain;
}
