/* Lagerverwaltung – gemeinsames Stylesheet (mobil zuerst) */

:root {
    --bg: #f2f4f7;
    --panel: #ffffff;
    --line: #e3e7ee;
    --text: #101828;
    --muted: #667085;
    --accent: #155eef;
    --accent-hover: #004eeb;
    --accent-soft: #eaf0ff;
    --danger: #c01c28;
    --danger-soft: #fdecec;
    --success: #137333;
    --success-soft: #e8f5ec;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06);
    --tabbar-h: 64px;
    --ease-out: cubic-bezier(.23, 1, .32, 1);
    --ease-drawer: cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; }

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

h2 { font-size: 17px; font-weight: 650; margin: 0 0 12px; letter-spacing: -.01em; }

p { margin: 0 0 12px; }

code { font-size: .9em; background: var(--bg); padding: 1px 5px; border-radius: 5px; }

.icon {
    width: 22px; height: 22px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* Bedienelemente: kein Doppeltipp-Zoom, keine Textauswahl beim langen Drücken */
button, .btn, .icon-btn, .chip, summary, .tabbar a {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* ---------- Kopfzeile & Navigation ---------- */

.app-header {
    position: sticky; top: 0; z-index: 20;
    background: var(--bg);
    padding-top: env(safe-area-inset-top);
}

.app-header-in {
    max-width: 760px; margin: 0 auto;
    padding: 12px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    display: flex; align-items: center; gap: 12px;
}

.app-header h1 {
    flex: 1; min-width: 0; margin: 0;
    font-size: 24px; font-weight: 700; letter-spacing: -.02em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.brand img { display: block; height: 46px; width: auto; max-width: 160px; }
/* Auf dem Handy ist auf Unterseiten kein Platz für Logo, Zurück-Pfeil und Titel. */
.has-back .brand { display: none; }

.icon-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px; margin-left: -8px;
    border-radius: 12px; color: var(--text);
    transition: transform 160ms var(--ease-out), background-color 150ms ease;
}
.icon-btn:active { transform: scale(.94); }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; justify-content: space-around;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, .94);
    border-top: 1px solid var(--line);
}

.tabbar a {
    flex: 1; max-width: 96px;
    display: grid; justify-items: center; gap: 2px;
    padding: 6px 0;
    font-size: 11px; font-weight: 500; color: var(--muted);
    border-radius: 12px;
    transition: transform 160ms var(--ease-out), color 150ms ease;
}
.tabbar a:active { transform: scale(.94); }
.tabbar a[aria-current="page"] { color: var(--accent); }

.has-tabbar .page { padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }

/* Kontomenü */
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }

.avatar {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: 50%;
    background: #dbe4ff; color: var(--accent);
    font-size: 13px; font-weight: 650;
    transition: transform 160ms var(--ease-out);
}
.avatar:active { transform: scale(.94); }

.menu-panel {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
    width: 220px; padding: 14px;
    background: var(--panel); border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(16, 24, 40, .16), 0 0 0 1px var(--line);
    transform-origin: top right;
    transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
@starting-style {
    .menu[open] .menu-panel { opacity: 0; transform: scale(.96); }
}
.menu-user { font-size: 14px; color: var(--muted); }
.menu-user b { color: var(--text); font-weight: 600; }

/* ---------- Seite ---------- */

.page {
    max-width: 760px; margin: 0 auto;
    padding: 4px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}

.card {
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

.section-title {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    margin: 20px 4px 8px;
    font-size: 13px; font-weight: 600; color: var(--muted);
}
.section-title:first-child { margin-top: 4px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- Formulare ---------- */

.field, .page input[type="text"], .page input[type="password"], .page input[type="number"], .page select, dialog input[type="text"], dialog input[type="number"], dialog select {
    width: 100%; height: 46px;
    padding: 0 14px;
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--panel); color: var(--text);
    font: inherit; font-size: 16px; /* 16px verhindert das Hineinzoomen auf iOS */
    transition: border-color 150ms ease, box-shadow 150ms ease;
}
.page select, dialog select { padding-right: 36px; appearance: none;
    background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E") no-repeat right 14px center;
}
.field:focus, .page input:focus, .page select:focus, dialog input:focus, dialog select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(21, 94, 239, .15);
}

.form { display: grid; gap: 14px; }
.form label, .label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.qty { grid-template-columns: 110px 1fr; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.choice { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; font-size: 16px !important; font-weight: 400 !important; }
.choice input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 46px; padding: 0 18px;
    border: 0; border-radius: 12px;
    font: 600 15px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
    cursor: pointer; text-decoration: none;
    transition: transform 160ms var(--ease-out), background-color 150ms ease, box-shadow 150ms ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible, .tabbar a:focus-visible, .avatar:focus-visible, .item-link:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn .icon { width: 20px; height: 20px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn-link { height: auto; padding: 0; background: none; color: var(--accent); font-weight: 500; }

@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover { background: var(--accent-hover); }
    .btn-ghost:hover { background: #f8f9fb; }
    .btn-danger:hover { background: #a3151f; }
    .icon-btn:hover { background: rgba(16, 24, 40, .05); }
    .tabbar a:hover { color: var(--text); }
    .tabbar a[aria-current="page"]:hover { color: var(--accent); }
    .item-link:hover .item-title { color: var(--accent); }
    a.card:hover, .kiste:hover { box-shadow: 0 0 0 1px var(--line), var(--shadow); }
}

/* Schwebender Hinzufügen-Button */
.fab {
    position: fixed; z-index: 25;
    right: max(20px, env(safe-area-inset-right));
    bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
    height: 54px; padding: 0 22px 0 18px; border-radius: 18px;
    box-shadow: 0 8px 24px rgba(21, 94, 239, .35);
    transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out), background-color 150ms ease;
}
.has-selection .fab { opacity: 0; transform: scale(.9); pointer-events: none; }

/* ---------- Hinweise ---------- */

.notice { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 15px; }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice-success { background: var(--success-soft); color: var(--success); }
.notice-info { background: var(--accent-soft); color: #1d3f8f; }

/* ---------- Suche & Filter ---------- */

.search {
    position: relative; display: block;
}
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input.field {
    height: 50px; padding-left: 46px;
    border-color: transparent; border-radius: 16px; box-shadow: var(--shadow);
}

.filters {
    display: flex; gap: 8px;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
    margin: 10px -16px 0; padding: 0 16px 2px;
}
.filters::-webkit-scrollbar { display: none; }
.page .filters .field {
    flex: none; width: auto; height: 38px;
    border-radius: 999px; font-size: 16px; padding: 0 14px;
}
.page .filters select.field { max-width: 240px; padding-right: 34px; }
.page .filters input.field { width: 118px; }

/* ---------- Listen (Teile, Kisten, Verlauf, Benutzer) ---------- */

.list { display: grid; gap: 8px; }

.list-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: 18px 4px 8px; font-size: 13px; color: var(--muted);
}
.list-head label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.item {
    display: flex; align-items: center; gap: 12px;
    background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 12px 16px;
    transition: box-shadow 150ms ease;
}
.item:has(.artikel-checkbox:checked) { box-shadow: 0 0 0 2px var(--accent); }

.check { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
/* Große Tippfläche um das Kästchen, damit ein knapper Fehltipp nicht den Bearbeiten-Link trifft */
.check-hit { display: grid; place-items: center; align-self: stretch; margin: -12px 0 -12px -16px; padding: 0 6px 0 16px; cursor: pointer; }

.item-link { flex: 1; min-width: 0; color: inherit; display: grid; gap: 2px; border-radius: 8px; }
.item-title { font-weight: 600; overflow-wrap: anywhere; transition: color 150ms ease; }
.item-meta { font-size: 14px; color: var(--muted); }

.item-qty {
    flex: none; text-align: right;
    font-size: 22px; font-weight: 700; line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.item-qty small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }

.item .icon { color: #98a2b3; width: 18px; height: 18px; }

.badge {
    display: inline-block; min-width: 44px;
    padding: 4px 8px; border-radius: 8px;
    background: var(--accent-soft); color: var(--accent);
    font-size: 14px; font-weight: 650; text-align: center;
    font-variant-numeric: tabular-nums;
}

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Verlauf */
.log-entry { display: grid; gap: 4px; }
.log-entry .item-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pill {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600;
}
.pill-create { background: var(--success-soft); color: var(--success); }
.pill-update, .pill-move { background: var(--accent-soft); color: var(--accent); }
.pill-delete, .pill-restore { background: var(--danger-soft); color: var(--danger); }
.pill-ausleihe { background: #fff4e5; color: #b54708; }
.pill-rueckgabe { background: var(--success-soft); color: var(--success); }

/* Benutzer */
.user-row { display: grid; gap: 12px; }
.user-row-head { display: flex; align-items: center; gap: 12px; }
.user-row-head .avatar { width: 40px; height: 40px; }
.user-row-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.user-row-actions input { height: 40px !important; }
.user-row-actions .btn { height: 40px; }

/* ---------- Auswahlleiste (Verschieben) ---------- */

.selbar {
    position: fixed; z-index: 26;
    left: 50%; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom));
    width: min(560px, calc(100% - 24px));
    display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
    padding: 10px; border-radius: 18px;
    background: var(--text); color: #fff;
    box-shadow: 0 12px 32px rgba(16, 24, 40, .3);
    transform: translate(-50%, 0);
    transition: transform 240ms var(--ease-out), opacity 240ms var(--ease-out), visibility 240ms;
}
.selbar[hidden] {
    display: grid;
    opacity: 0; visibility: hidden; pointer-events: none;
    transform: translate(-50%, 16px);
    transition-duration: 160ms; /* ausblenden schneller als einblenden */
}
.selbar-count { grid-column: 1 / -1; padding: 2px 6px 0; font-size: 14px; font-weight: 600; }
.selbar select { height: 42px !important; border: 0 !important; }
.selbar .btn { height: 42px; }

/* ---------- Dialog als Bottom-Sheet ---------- */

dialog.sheet {
    width: 100%; max-width: 560px; max-height: 90dvh;
    margin: auto auto 0; padding: 0; border: 0;
    border-radius: 22px 22px 0 0;
    background: var(--panel); color: var(--text);
    overflow: auto;
    transform: translateY(0);
    transition: transform 380ms var(--ease-drawer), overlay 380ms allow-discrete, display 380ms allow-discrete;
}
dialog.sheet:not([open]) {
    transform: translateY(100%);
    transition-duration: 220ms;
}
@starting-style {
    dialog.sheet[open] { transform: translateY(100%); }
}
dialog.sheet::backdrop {
    background: rgba(16, 24, 40, .45);
    opacity: 1;
    transition: opacity 300ms ease, overlay 300ms allow-discrete, display 300ms allow-discrete;
}
dialog.sheet:not([open])::backdrop { opacity: 0; }
@starting-style {
    dialog.sheet[open]::backdrop { opacity: 0; }
}

.sheet-body { padding: 8px 20px calc(24px + env(safe-area-inset-bottom)); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-head .icon-btn { margin: 0 -8px 0 0; }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: start center; padding: max(48px, env(safe-area-inset-top)) 16px 48px; }
.login-shell { width: min(100%, 420px); }
.login-logo { display: block; width: min(180px, 60%); height: auto; margin: 8px auto 24px; }
.login-shell h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 18px; text-align: center; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin: 18px 0; }
.divider::before, .divider::after { content: ''; height: 1px; background: var(--line); flex: 1; }

/* ---------- Breite Bildschirme ---------- */

@media (min-width: 900px) {
    .app-header { border-bottom: 1px solid var(--line); margin-bottom: 20px; }
    .app-header-in { max-width: 1000px; padding-top: 10px; padding-bottom: 10px; }
    .app-header h1 { flex: none; font-size: 20px; margin-right: 8px; }
    .brand img { height: 52px; max-width: 200px; }
    .has-back .brand { display: block; }
    .has-back .icon-btn { margin-right: -8px; }
    .tabbar {
        position: static; flex: 1; justify-content: flex-start; gap: 2px;
        padding: 0; background: none; border: 0;
    }
    .tabbar a {
        flex: none; max-width: none;
        display: flex; align-items: center; gap: 8px;
        padding: 8px 12px; font-size: 14px; border-radius: 10px;
    }
    .tabbar a .icon { width: 18px; height: 18px; }
    .tabbar a[aria-current="page"] { background: var(--accent-soft); }
    .page, .has-tabbar .page { max-width: 1000px; padding-bottom: 120px; }
    .fab { bottom: 32px; right: max(32px, calc((100vw - 1000px) / 2)); }
    .selbar { bottom: 24px; }
    dialog.sheet { margin: auto; border-radius: 22px; transform: none; opacity: 1;
        transition: transform 220ms var(--ease-out), opacity 220ms var(--ease-out), overlay 220ms allow-discrete, display 220ms allow-discrete; }
    dialog.sheet:not([open]) { transform: scale(.96); opacity: 0; transition-duration: 150ms; }
    @starting-style {
        dialog.sheet[open] { transform: scale(.96); opacity: 0; }
    }
    .sheet-grip { display: none; }
    .sheet-body { padding-top: 20px; }
    .list.grid-2 { grid-template-columns: 1fr 1fr; }
}

/* Weniger Bewegung: nur Einblenden, keine Verschiebungen */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-property: opacity, color, background-color, box-shadow, visibility, overlay, display !important; }
    .selbar[hidden] { transform: translate(-50%, 0); }
    dialog.sheet:not([open]) { transform: none; opacity: 0; }
    @starting-style { dialog.sheet[open] { transform: none; opacity: 0; } }
}

/* ---------- Ausleihen ---------- */

.loan-overdue { box-shadow: 0 0 0 2px #f4b4b4, var(--shadow); }
.due-overdue { color: var(--danger); font-weight: 600; }
.due-soon { color: #b54708; font-weight: 600; }
.item-muted .item-title { color: var(--muted); }

.chip-toggle { display: inline-flex !important; align-items: center; gap: 8px; cursor: pointer; color: var(--text); white-space: nowrap; }
.chip-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.chip-toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.history-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.history-row:first-child { border-top: 0; padding-top: 0; }
.history-row:last-child { padding-bottom: 0; }

.section-title a { font-weight: 500; }

/* Kacheln im Verwaltungsbereich */
.tile { color: inherit; transition: transform 160ms var(--ease-out), box-shadow 150ms ease; }
.tile:active { transform: scale(.98); }
.tile-icon { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.tile-icon .icon { color: var(--accent); width: 22px; height: 22px; }
@media (hover: hover) and (pointer: fine) {
    .tile:hover .item-title { color: var(--accent); }
}
