:root {
    --yellow: #f2b705;
    --yellow-d: #d99a00;
    --brown: #5c3d2e;
    --brown-d: #3e2a1f;
    --bg: #faf6ee;
    --surface: #fff;
    --border: #e6dccb;
    --text: #2b2118;
    --muted: #7a6a5a;
    --danger: #b3261e;
    --ok: #2e7d32;
    --radius: 12px;
    --nav-w: 250px;
    --top-h: 56px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
h1 { font-size: clamp(1.4rem, 2.5vw, 1.9rem); margin: 0 0 1rem; color: var(--brown-d); }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; color: var(--brown); }
a { color: var(--brown); }
.muted { color: var(--muted); }

/* Kopfzeile + Navigation */
.topbar {
    position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 30;
    display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
    background: var(--brown); color: #fff;
    padding-top: env(safe-area-inset-top); height: calc(var(--top-h) + env(safe-area-inset-top));
}
.brand { color: var(--yellow); font-weight: 700; font-size: 1.15rem; text-decoration: none; display: flex; align-items: center; gap: .5rem; }
.brand-dot { width: .8em; height: .8em; border-radius: 50%; background: var(--yellow); display: inline-block; margin-right: .4rem; }
.topbar .brand-dot { margin: 0; }
.who { margin-left: auto; opacity: .85; font-size: .95rem; }
.burger { background: none; border: 0; color: #fff; font-size: 1.6rem; width: 44px; height: 44px; cursor: pointer; }

.sidebar {
    position: fixed; top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: 0; left: 0; width: var(--nav-w); z-index: 25;
    background: var(--surface); border-right: 1px solid var(--border);
    padding: .75rem; overflow-y: auto; display: flex; flex-direction: column; gap: .15rem;
    transform: translateX(-100%); transition: transform .2s;
}
.nav-link {
    display: flex; align-items: center; gap: .6rem; min-height: 44px; padding: .4rem .75rem;
    border-radius: 10px; color: var(--text); text-decoration: none;
}
.nav-link:hover { background: #f5ecd6; }
.nav-link.active { background: var(--yellow); color: var(--brown-d); font-weight: 600; }
.nav-link.off { opacity: .55; }
.nav-link small { margin-left: auto; font-size: .7rem; }
.nav-link .ico { width: 1.5em; text-align: center; }
.nav-h { margin: 1rem .75rem .25rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.logout { margin-top: auto; padding-top: 1rem; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
body.nav-open .sidebar { transform: none; }
body.nav-open .scrim { display: block; }

.main { padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
body.has-nav .main { margin-top: calc(var(--top-h) + env(safe-area-inset-top)); }
body.bare .main { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }
body.bare .main > * { width: 100%; }

@media (min-width: 900px) {
    .burger { display: none; }
    .sidebar { transform: none; }
    body.has-nav .main { margin-left: var(--nav-w); padding: 1.5rem 2rem; }
    .scrim { display: none !important; }
}

/* Karten, Kacheln */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 440px; }
.card.center { text-align: center; max-width: 440px; }
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.tile {
    display: flex; flex-direction: column; gap: .35rem; padding: 1.25rem; min-height: 150px;
    background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--yellow);
    border-radius: var(--radius); color: var(--text); text-decoration: none; transition: transform .1s, box-shadow .1s;
}
a.tile:hover, a.tile:active { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(92,61,46,.15); }
.tile.off { opacity: .6; border-top-color: var(--border); }
.tile-ico { font-size: 2rem; }
.badge { align-self: flex-start; background: var(--border); color: var(--brown); border-radius: 99px; padding: .1rem .6rem; }

/* Formulare */
label { display: block; margin-bottom: .9rem; font-weight: 500; }
input:not([type=checkbox]), select, textarea {
    display: block; width: 100%; min-height: 44px; margin-top: .25rem; padding: .5rem .75rem;
    font: inherit; font-size: 16px; color: var(--text); background: #fff;
    border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--yellow); border-color: var(--yellow-d); }
label.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-weight: 400; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brown); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1rem; }
.checks { display: flex; flex-wrap: wrap; gap: 0 1.5rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1.1rem;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    color: var(--brown-d); background: var(--yellow); border: 1px solid var(--yellow-d); border-radius: 10px;
}
.btn:hover { background: var(--yellow-d); }
.btn-secondary { background: #fff; color: var(--brown); border-color: var(--border); }
.btn-secondary:hover { background: #f5ecd6; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline { display: inline; }

.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert-ok { background: #e8f5e9; color: var(--ok); border-color: #b7dcb9; }
.alert-err { background: #fdecea; color: var(--danger); border-color: #f2b8b5; }

.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f5ecd6; color: var(--brown); font-size: .85rem; }
tr:last-child td { border-bottom: 0; }

/* Filament */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; align-items: center; }
.filters input, .filters select { margin-top: 0; }
.swatch { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); vertical-align: -.15em; margin-right: .3rem; }
.swatch.lg { width: .9em; height: .9em; }
.row-link { color: var(--text); text-decoration: none; display: inline-block; padding: .4rem 0; }
.row-link:hover { text-decoration: underline; }
.bar { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: .25rem; min-width: 120px; }
.bar > span { display: block; height: 100%; background: var(--yellow-d); }
.bar.warn > span { background: var(--danger); }
.bar.big { height: 18px; margin-bottom: .75rem; }
.badge-warn { background: #fdecea; color: var(--danger); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.inline-fields { display: flex; gap: .5rem; }
.inline-fields > * { flex: 1; }
input[type=color] { padding: .2rem; }

/* Strass-Editor */
.sv-ed { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1000px) { .sv-ed { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; } }
.sv-stage { padding: .5rem; margin: 0; }
.sv-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .5rem; }
#cv { display: block; width: 100%; height: 62vh; min-height: 320px; background: #efe8d8; border-radius: 8px; touch-action: none; user-select: none; -webkit-user-select: none; }
@media (min-width: 1000px) { #cv { height: calc(100vh - 14rem); } }
.sv-side .card { margin-bottom: 1rem; }
.sv-side h2 { margin-top: 0; }
.sv-shape { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .25rem .5rem; border-radius: 10px; cursor: pointer; }
.sv-shape.sel { background: #f5ecd6; outline: 2px solid var(--yellow); }
.sv-shape .n { flex: 1; }
.sv-props { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.sv-props label { margin-bottom: .6rem; font-size: .9rem; }
.sv-props .full { grid-column: 1 / -1; }
.sv-stat { display: flex; align-items: center; gap: .5rem; min-height: 32px; }
.sv-stat b { margin-left: auto; }

[hidden] { display: none !important; }

/* Strass-Editor: Arbeitsbereich bleibt stehen, Werkzeuge scrollen */
.sv-stage { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top) + .5rem); z-index: 5; }
#cv { height: 44vh; }
@media (min-width: 1000px) {
    #cv { height: calc(100vh - 16rem); }
    .sv-side { max-height: calc(100vh - 9.5rem); overflow-y: auto; overscroll-behavior: contain; padding-right: .25rem; }
}

/* Strass-Editor: Werkzeuge */
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin-bottom: .75rem; }
.seg .btn { padding: .4rem .5rem; }
.seg .btn.active { background: var(--brown); color: #fff; border-color: var(--brown-d); }
.sv-toolbar .btn { min-width: 44px; }
.sv-toolbar .btn:disabled { opacity: .4; cursor: default; }

/* Filament-Übersicht gruppiert */
.print-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; padding: .6rem 1rem; }
.print-bar .check { margin: 0; }
table.grouped .grp-h td { background: #f5ecd6; border-top: 2px solid var(--yellow); white-space: normal; }
table.grouped .grp-h .actions { justify-content: flex-end; }

/* Diamond-Painting-Inventar */
.dp-flags { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1.25rem; margin-top: .5rem; }
.dp-flags .check { margin: 0; }
.seg-inline { margin-left: auto; display: flex; gap: .5rem; }
.seg-inline .btn.active { background: var(--brown); color: #fff; border-color: var(--brown-d); }
.dp-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.dp-tiles.small { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.dp-tile { display: flex; flex-direction: column; gap: .15rem; padding: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
a.dp-tile:hover, a.dp-tile:active { box-shadow: 0 4px 12px rgba(92,61,46,.18); }
.dp-sw { display: block; height: 64px; border-radius: 8px; border: 1px solid rgba(0,0,0,.25); }
.dp-sw.sm { width: 36px; height: 24px; }
.dp-code { font-weight: 700; margin-top: .25rem; }
.dp-name { font-size: .85rem; color: var(--muted); line-height: 1.2; }
.dp-meta { font-size: .8rem; }
.dp-badges { display: flex; flex-wrap: wrap; gap: .2rem; min-height: 1.1rem; }
.dp-b { font-size: .68rem; background: var(--border); color: var(--brown); border-radius: 99px; padding: 0 .45rem; }
.dp-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.dp-chip { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: .3rem .8rem; background: #fff; border: 1px solid var(--border); border-radius: 99px; font: inherit; cursor: pointer; }
.dp-chip:hover { background: #f5ecd6; }
.dp-dot { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); }
.dp-dot.lg { width: .9em; height: .9em; }
.dp-row { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; }
.dp-row .dp-sw { width: 64px; flex: none; }
.dp-info { flex: 1 1 160px; }
.dp-q { flex: 0 0 auto; min-width: 7rem; text-align: right; }
.dp-adj { display: flex; align-items: center; gap: .4rem; }
.dp-adj .btn { min-width: 52px; font-size: 1.3rem; }
.dp-adj .dp-amt { width: 6rem; margin-top: 0; text-align: center; }
.dp-adj .dp-unit { width: 5rem; margin-top: 0; }

/* Bildgenerator */
.bg-view { overflow: auto; max-height: calc(100vh - 16rem); min-height: 280px; background: #ece4d2; border-radius: 8px; }
.bg-view canvas { display: block; background: #fff; }
.bg-ed #cv { height: auto; min-height: 0; background: #fff; width: auto; touch-action: auto; border-radius: 0; }
table.need td, table.need th { padding: .45rem .5rem; white-space: normal; }
.dp-sym { display: inline-block; min-width: 1.6em; text-align: center; font-weight: 700; border: 1px solid var(--border); border-radius: 6px; }
.bad { color: var(--danger); font-weight: 600; }
