/* =====================
   Design Tokens
   ===================== */
:root {
    color-scheme: dark;
    --bg: #0f1115;
    --panel: #171a21;
    --muted: #bec4cf;
    --accept: #139124;
    --accept-hover: #1aaa2d;
    --delete: #be1818;
    --delete-hover: #da1f1f;
    --fg: #e6e6e6;
    --accent: #4ea1ff;
    --accent-hover: #66acfd;
    --ok: #71ffb6;
    --warn: #ffdf7e;
    --err: #ff8c8c;

    --gap-xs: 6px;
    --gap-sm: 8px;
    --gap-md: 12px;
    --gap-lg: 18px;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;

    --card-pad: 18px;
    --border: rgba(255,255,255,.12);
    --border-soft: rgba(255,255,255,.08);
}

/* =====================
   Base
   ===================== */
* {
    box-sizing: border-box;
}
body,
html {
    height: 100%;
}
body {
    margin: 0;
    min-height: 100dvh;
    /* mobile-safe viewport */
    display: flex;
    flex-direction: column;
    /* Footer push */
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    overflow-x: hidden;
}
a {
    color: var(--fg);
    text-decoration: none;
}
a:hover {
    opacity: 0.85;
}
.muted {
    color: var(--muted);
    opacity: 0.9;
}
.center {
    display: grid;
    place-items: center;
}

/* Headings helpers */
.h1 {
    font-size: 26px;
    margin: 6px 0 8px;
}
.h2 {
    font-size: 18px;
    margin: 0 0 10px;
}
.h3 {
    font-weight: 600;
    margin-top: 8px;
}

/* =====================
   Layout
   ===================== */
main#app {
    flex: 1 0 auto;
    /* füllt Höhe, kein künstliches min-height */
    min-height: 0;
    width: 100%;
    max-width: 1100px;
    margin: 26px auto;
    padding: 0 var(--gap-md);
}
.page {
    display: grid;
    gap: 22px;
}

.grid {
    display: grid;
    gap: var(--gap-md);
}
.grid.two {
    grid-template-columns: 1fr;
}
@media (min-width:1080px) {
    .grid.two {
        grid-template-columns: 1.2fr 0.8fr;
    }
}
.grid.three {
    grid-template-columns: 1fr;
}
@media (min-width:900px) {
    .grid.three {
        grid-template-columns: repeat(3,1fr);
    }
}

.row {
    display: flex;
    gap: var(--gap-md);
    flex-wrap: wrap;
}
.row > * {
    flex: 1 1 260px;
    min-width: 0;
}

.card {
    background: var(--panel);
    border-radius: 14px;
    padding: var(--card-pad);
    box-shadow: 0 4px 20px rgba(0,0,0,.25);
    line-height: 1.6;
}
.card > .h2,
.card > .h3 {
    margin-top: 4px;
}
.card > * + .h2,
.card > * + .h3 {
    margin-top: 12px;
}

/* Topbar (mobil: 3-Spalten-Grid + overflow) */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(23,26,33,.9);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid #202733;
}
.brand {
    font-weight: 800;
    letter-spacing: 0.5px;
    cursor: pointer;
}
.nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    justify-content: center;
}
.nav::-webkit-scrollbar {
    display: none;
}
.nav a {
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
}
.nav a:hover {
    background: #1c212a;
}
.auth {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Footer (scrollt nicht extra) */
.foot {
    margin-top: auto;
    opacity: 0.6;
    text-align: center;
    padding: 18px;
    border-top: 1px solid var(--border-soft);
}

/* =====================
   Buttons
   ===================== */
.btn {
    padding: 10px 12px;
    min-height: 40px;
    /* Tap-friendly */
    border-radius: var(--radius-lg);
    background: var(--accent);
    color: #000;
    border: none;
    cursor: pointer;
    font-weight: 600;
    touch-action: manipulation;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-muted {
    background: rgba(255,255,255,.1);
    color: var(--fg);
}
.btn-muted:hover {
    background: rgba(255, 255, 255, .2);
}
.btn-delete {
    background: var(--delete);
    color: var(--fg);
}
.btn-delete:hover {
    background: var(--delete-hover);
}
.btn-accept {
    background: var(--accept);
    color: var(--fg);
}
.btn-accept:hover {
    background: var(--accept-hover);
}
.btn-ghost {
    background: transparent;
    border: 1px solid #2a2f3a;
    color: #ddd;
}
.btn.is-active {
    box-shadow: 0 0 0 2px var(--accent) inset;
}

/* Small button rows */
.btnRow {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* =====================
   Forms
   ===================== */
label .label {
    display: block;
    font-size: 0.9rem;
    opacity: 0.85;
    margin-bottom: 6px;
    color: #cfd6e2;
    letter-spacing: 0.2px;
}
input[type=file],
input[type=number],
input[type=text],
input[type=url],
select {
    width: 100%;
    padding: 10px 12px;
    min-height: 40px;
    /* Tap-friendly */
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--fg);
}
.range-wrap input[type=range] {
    width: 100%;
}

/* Flash feedback (e.g. paste coords) */
@keyframes flashBorder {
    0% {
        box-shadow: 0 0 0 2px var(--ok) inset;
    }
    100% {
        box-shadow: none;
    }
}
.flash {
    animation: flashBorder 0.8s ease-out;
}

/* =====================
   Tabs
   ===================== */
.tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: -6px;
}
.tab-btn {
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.18);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.tab-btn:hover {
    background: var(--accent);
    color: black;
}
.tab-btn.is-active {
    background: var(--accent);
    color: #000;
    border-color: transparent;
}
.tab {
    display: none;
}
.tab.is-active {
    display: block;
}

/* Moderation subtabs / filters */
.subtabs {
    display: flex;
    gap: 8px;
    margin: 8px 0 12px;
    flex-wrap: wrap;
}
.subtab-btn {
    padding: 7px 10px;
    border-radius: 10px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.15);
    cursor: pointer;
}
.subtab-btn.is-active {
    background: var(--accent);
    color: #000;
    border-color: transparent;
}
.filterRow {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 8px 0 4px;
}

/* =====================
   Previews / Viewer
   ===================== */
.previewBox {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--panel);
    padding: 12px;
    min-height: 200px;
    /* kleiner auf Mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
@media (min-width:640px) {
    .previewBox {
        min-height: 260px;
    }
}

.previewStage {
    transform-origin: top left;
    display: inline-block;
}
.previewBox img {
    max-width: 100%;
    height: auto;
}
#outImg {
    max-width: none;
    image-rendering: pixelated;
}

.previewBox.interactive {
    cursor: grab;
    touch-action: none;
}
.previewBox.interactive.grabbing {
    cursor: grabbing;
}

/* Overlay grid (visual only) */
.overlayGrid {
    display: none;
    position: absolute;
    inset: 12px;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

/* Placeholders while empty */
.previewEmpty {
    position: absolute;
    inset: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.6);
    font-size: 0.95rem;
    text-align: center;
}

/* Drag & drop */
.dropzone {
    outline: 2px dashed rgba(255,255,255,.2);
    border-radius: 12px;
    padding: 8px;
}
.dropzone.is-drag {
    outline-color: var(--accent);
    background: rgba(78,161,255,.08);
}

/* (Legacy) canvasWrap – behalten für Altstellen */
.canvasWrap {
    position: relative;
    background: #0b0e13;
    border: 1px solid #2a2f3a;
    border-radius: 12px;
    padding: 10px;
}
.canvasWrap canvas {
    display: block;
    max-width: 100%;
    image-rendering: pixelated;
    background: #000;
}
.canvasWrap .layer {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: 2;
}

/* =====================
   Color selection
   ===================== */
.colorSection {
    display: grid;
    gap: 14px;
}
@media (min-width:720px) {
    .colorSection {
        grid-template-columns: 1fr 1fr;
    }
}

.colorGroup {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
}
.colorGroupTitle {
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.colorGrid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
}
.swatch {
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,.35);
    background: var(--sw, #000);
    cursor: pointer;
}
.swatch.on {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* =====================
   Status / Pills
   ===================== */
.status {
    font-size: 0.95rem;
}
.status.ok {
    color: var(--ok);
}
.status.err {
    color: var(--err);
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.15);
}
.pill.pending {
    color: #997a00;
    background: #332b00;
    border-color: #4d3d00;
}
.pill.approved {
    color: #094;
    background: #0a2b1f;
    border-color: #0f3a2a;
}
.pill.rejected {
    color: #b33;
    background: #2b0a0a;
    border-color: #3a0f0f;
}
.pill::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.9;
}

/* (Legacy) badge mapping – falls irgendwo noch genutzt */
.badge {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #2a2f3a;
    color: #ddd;
}
.badge.ok {
    background: #2e7d32;
}
.badge.pending {
    background: #8a6d2e;
}
.badge.rej {
    background: #7d2e2e;
}

/* =====================
   Lists / Items
   ===================== */
.list {
    display: grid;
    gap: 12px;
}
.itemCard {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    gap: 10px;
}
.itemRow {
    display: grid;
    gap: 10px;
    align-items: center;
    grid-template-columns: 100px 1fr;
}
@media (min-width:560px) {
    .itemRow {
        grid-template-columns: 120px 1fr;
    }
}
.itemThumb {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}
.itemThumb img {
    position: relative;
    border-radius: 8px;
    max-width: 100%;
    max-height: 120px;
}
.itemActions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* =====================
   Hero / Empty states
   ===================== */
.hero {
    max-width: 680px;
    text-align: center;
    padding: 40px 20px;
}
.hero .title {
    font-size: 36px;
    font-weight: 900;
    margin: 0 0 8px;
}
@media (min-width:640px) {
    .hero .title {
        font-size: 40px;
    }
}
.hero .subtitle {
    color: var(--muted);
    margin-bottom: 20px;
}

/* =====================
   Stats tweaks
   ===================== */
#stats div {
    margin-top: 2px;
}
#stats b {
    font-weight: 600;
}

/* Bilder nur zeigen, wenn geladen */
.previewImg {
    display: none;
}
.previewImg.is-loaded {
    display: block;
}

/* =====================
   Galerie (responsive Stufen)
   ===================== */
.galleryGrid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
@media (min-width:520px) {
    .galleryGrid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}
@media (min-width:880px) {
    .galleryGrid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

.gCard {
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px;
    background: var(--panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.gThumb {
    aspect-ratio: 1 / 1;
    background: #0b0e13;
    display: grid;
    place-items: center;
    height: 350px;
}
.gThumb img {
    width: 100%;
    height: 350px;
    object-fit: contain;
    display: block;
}
.gMeta {
    padding: 10px;
    display: grid;
    gap: 8px;
}
.gTitle {
    font-weight: 600;
    line-height: 1.2;
}
.gSub {
    font-size: 0.9rem;
    color: var(--muted);
}
.gPos {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    opacity: 0.9;
}
.gActions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.gActions .btn {
    flex: 1 1 auto;
    min-width: 0;
}
.gActions .btn:hover {
    background: var(--accent-hover);
}

.gActions .btn-muted:hover {
    background: rgba(255, 255, 255, .2);
}
/* --- Mobile Topbar Fixes --- */
.topbar {
    /* schon vorhanden – ergänzt um safe areas optional: */
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}

/* Grid-Kind darf schrumpfen, sonst kollabiert die Nav bei wenig Platz */
.topbar .nav {
    min-width: 0;
}

/* < 560px: Nav in eine zweite Zeile legen */
@media (max-width: 560px) {
    .topbar {
        display: grid;
        grid-template-columns: 1fr auto;
        /* Brand | Auth */
        grid-template-areas: "brand auth" "nav nav";
        row-gap: 8px;
    }
    .brand {
        grid-area: brand;
    }
    .nav {
        grid-area: nav;
    }
    .auth {
        grid-area: auth;
        justify-self: end;
    }

    /* Nav horizontal scrollbar & gut klickbar */
    .nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav a {
        flex: 0 0 auto;
        padding: 8px 12px;
        /* etwas größer für Daumen */
        border-radius: 10px;
        white-space: nowrap;
    }
}

/* Verhindert natives Bildziehen/Selektieren in den Previews */
.previewBox .previewImg {
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

/* Original-Bild auch vollständig über Transform skalieren */
#origImg {
    max-width: none;
}
