/* ============ Design Tokens ============ */
:root {
  --bg:            oklch(20% 0.01 260);
  --surface:       oklch(25% 0.012 260);
  --surface-2:     oklch(30% 0.014 260);
  --surface-hi:    oklch(35% 0.016 260);
  --line:          oklch(40% 0.02 260 / 0.5);
  --text:          oklch(96% 0.005 260);
  --text-dim:      oklch(72% 0.01 260);
  --accent:        oklch(72% 0.19 55);   /* Signal-Orange */
  --accent-press:  oklch(66% 0.19 55);
  --accent-ink:    oklch(22% 0.04 55);
  --ok:            oklch(72% 0.16 150);
  --warn:          oklch(78% 0.16 85);
  --danger:        oklch(64% 0.2 25);

  --r-sm: 12px; --r-md: 18px; --r-lg: 26px; --r-full: 999px;
  --space: clamp(1rem, 0.7rem + 1.5vw, 1.4rem);
  --tap: 60px;
  --text-lg:  clamp(1.05rem, 1rem + 0.5vw, 1.25rem);
  --text-xl:  clamp(1.4rem, 1.2rem + 1.2vw, 2rem);
  --text-2xl: clamp(1.9rem, 1.5rem + 2vw, 2.8rem);
  --dur: 180ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --shadow: 0 8px 24px oklch(0% 0 0 / 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--text-lg);
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

/* ============ Login ============ */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--space);
  background: radial-gradient(120% 80% at 50% 0%, var(--surface-2), var(--bg));
}
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: clamp(1.5rem, 5vw, 2.5rem); box-shadow: var(--shadow);
}
.brand { font-size: var(--text-xl); font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 0.5rem; }
.brand-mark { color: var(--accent); }
.login-hint { color: var(--text-dim); margin: 0.4rem 0 1.4rem; }
#login-form { display: grid; gap: 0.9rem; }
input[type=password], input[type=text], input[type=number], select, textarea {
  width: 100%; min-height: var(--tap); padding: 0 1rem; font-size: var(--text-lg);
  background: var(--surface-2); color: var(--text); border: 2px solid var(--line);
  border-radius: var(--r-md); outline: none; transition: border-color var(--dur) var(--ease);
}
textarea { padding: 0.8rem 1rem; min-height: 3rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.error-msg { color: var(--danger); margin: 0.2rem 0 0; font-size: 0.95rem; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--tap); padding: 0 1.3rem; border: none; border-radius: var(--r-md);
  background: var(--surface-hi); color: var(--text); font-weight: 700;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), filter var(--dur);
}
.btn:active { transform: scale(0.97); }
.btn-lg { min-height: 66px; font-size: var(--text-lg); width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent-press); }
.btn-ghost { background: transparent; border: 2px solid var(--line); }
.btn-danger { background: transparent; border: 2px solid var(--danger); color: var(--danger); }
.btn-icon { min-height: var(--tap); min-width: var(--tap); padding: 0; border-radius: var(--r-md); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ============ App layout ============ */
#app { max-width: 720px; margin: 0 auto; padding: 0 var(--space) calc(var(--space) + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; padding: calc(env(safe-area-inset-top) + 0.7rem) var(--space) 0.7rem;
  margin: 0 calc(-1 * var(--space)) 0.6rem; background: linear-gradient(var(--bg) 70%, transparent);
  display: flex; align-items: center; gap: 0.6rem;
}
.max { max-width: 720px; margin-inline: auto; }
.search-wrap { flex: 1; position: relative; }
.search-wrap input { padding-left: 3rem; }
.search-wrap .ico { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: 1.2rem; }

.page-head { display: flex; align-items: center; gap: 0.7rem; margin: 0.3rem 0 1rem; }
.page-head h1 { font-size: var(--text-xl); margin: 0; letter-spacing: -0.02em; }
.back-btn { background: var(--surface); border: 1px solid var(--line); }
.spacer { flex: 1; }

/* ============ Dashboard ============ */
.hello { margin: 0.6rem 0 1.2rem; }
.hello h1 { font-size: var(--text-2xl); margin: 0; letter-spacing: -0.03em; }
.hello p { color: var(--text-dim); margin: 0.3rem 0 0; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 148px; padding: 1.1rem; border-radius: var(--r-lg); border: 1px solid var(--line);
  background: var(--surface); text-align: left; color: var(--text); overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur);
}
.tile:active { transform: scale(0.98); }
.tile .tile-ico { font-size: 2rem; }
.tile .tile-count { font-size: var(--text-2xl); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.tile .tile-label { color: var(--text-dim); font-weight: 600; overflow-wrap: anywhere; hyphens: auto; line-height: 1.2; }
.tile.accent { grid-column: span 2; min-height: auto; flex-direction: row; align-items: center; gap: 1rem;
  background: linear-gradient(120deg, var(--accent), var(--accent-press)); color: var(--accent-ink); border: none; }
.tile.accent .tile-ico { font-size: 1.8rem; }
.tile.accent .tile-count { font-size: var(--text-xl); }
.tile.accent .tile-label { color: var(--accent-ink); opacity: 0.8; }
.badge {
  position: absolute; top: 0.9rem; right: 0.9rem; min-width: 30px; height: 30px; padding: 0 0.5rem;
  display: grid; place-items: center; border-radius: var(--r-full); background: var(--warn);
  color: var(--accent-ink); font-weight: 800; font-size: 0.95rem;
}

.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-top: 0.9rem; }

/* ============ Item list ============ */
.item-list { display: grid; gap: 0.7rem; margin-top: 0.4rem; }
.item-card {
  display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 0.9rem;
  padding: 0.7rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  color: var(--text); text-align: left; width: 100%;
  transition: transform var(--dur) var(--ease), background var(--dur);
}
.item-card:active { transform: scale(0.99); background: var(--surface-2); }
.thumb {
  width: 76px; height: 76px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-size: 1.8rem; color: var(--text-dim); flex-shrink: 0;
}
.item-main { min-width: 0; }
.item-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--text-dim); font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; padding: 0.15rem 0.6rem; border-radius: var(--r-full); font-size: 0.8rem; font-weight: 700; }
.pill.loc { background: var(--surface-hi); color: var(--text-dim); }
.pill.gut { background: color-mix(in oklch, var(--ok) 25%, transparent); color: var(--ok); }
.pill.okay { background: color-mix(in oklch, var(--warn) 25%, transparent); color: var(--warn); }
.pill.defekt { background: color-mix(in oklch, var(--danger) 25%, transparent); color: var(--danger); }
.pill.low { background: var(--warn); color: var(--accent-ink); }

.stock-mini { text-align: right; }
.stock-mini .num { font-size: var(--text-xl); font-weight: 800; line-height: 1; }
.stock-mini .lbl { color: var(--text-dim); font-size: 0.78rem; }

/* ============ Detail / Form ============ */
.photo-hero {
  position: relative; width: 100%; aspect-ratio: 4/3; border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center; border: 1px solid var(--line); margin-bottom: 1rem;
}
.photo-hero img { width: 100%; height: 100%; object-fit: cover; }
.photo-hero .placeholder { display: grid; place-items: center; gap: 0.6rem; color: var(--text-dim); text-align: center; padding: 1rem; }
.photo-hero .placeholder .big { font-size: 3rem; }
.photo-overlay-btn {
  position: absolute; right: 0.8rem; bottom: 0.8rem; background: oklch(15% 0 0 / 0.7);
  color: var(--text); backdrop-filter: blur(6px); border: 1px solid var(--line);
}
.field { display: grid; gap: 0.35rem; margin-bottom: 0.9rem; }
.field label { color: var(--text-dim); font-weight: 600; font-size: 0.92rem; padding-left: 0.2rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.seg { display: flex; gap: 0.4rem; }
.seg button { flex: 1; min-height: 52px; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--surface-2); color: var(--text-dim); font-weight: 700; }
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--surface-hi); }

.suggest-bar { margin-bottom: 1rem; }
.suggest-note { font-size: 0.9rem; color: var(--text-dim); margin: 0.5rem 0.2rem 0; }
.suggest-note.err { color: var(--warn); }

.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); align-items: center; gap: 0.7rem; }
.stepper .val { text-align: center; font-size: var(--text-2xl); font-weight: 800; }
.stepper button { font-size: 1.8rem; }

.form-actions { display: grid; gap: 0.7rem; margin-top: 1.4rem; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.2rem 0 1rem; }

/* ============ Empty / states ============ */
.empty { text-align: center; color: var(--text-dim); padding: 3rem 1rem; }
.empty .big { font-size: 3rem; margin-bottom: 0.5rem; }
.center-load { display: grid; place-items: center; padding: 3rem; color: var(--text-dim); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Toast ============ */
#toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(200%);
  background: var(--surface-hi); color: var(--text); border: 1px solid var(--line); padding: 0.9rem 1.3rem;
  border-radius: var(--r-full); box-shadow: var(--shadow); z-index: 50; transition: transform 260ms var(--ease); max-width: 90vw;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ============ QR-Scanner Overlay ============ */
.scan-overlay {
  position: fixed; inset: 0; z-index: 60; background: #000;
  display: grid; place-items: center; overflow: hidden;
}
.scan-overlay video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: relative; width: min(70vw, 300px); aspect-ratio: 1; border-radius: var(--r-lg);
  box-shadow: 0 0 0 100vmax oklch(0% 0 0 / 0.55); border: 3px solid var(--accent);
}
.scan-hint {
  position: absolute; bottom: 22%; left: 0; right: 0; text-align: center; color: #fff;
  font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,.8); z-index: 2;
}
.scan-close {
  position: absolute; bottom: calc(2rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: auto; z-index: 2; background: #fff; color: var(--ink, #16181d); min-width: 60vw;
}

/* ============ Zubehör-Verknüpfungen ============ */
.tile-wide { grid-column: span 2; min-height: auto; flex-direction: row; align-items: center; gap: 1rem; }
.tile-wide .tile-ico { font-size: 1.8rem; }
.tile-wide .tile-count { font-size: var(--text-xl); }

.link-section { margin-top: 1.2rem; }
.link-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.link-chip {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.8rem 0.35rem 0.35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-full);
  color: var(--text); max-width: 100%;
}
.link-chip:active { transform: scale(0.97); }
.link-chip img, .link-chip-ico {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; flex-shrink: 0;
}
.link-chip-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-assign { width: 100%; }

/* Auswahl-Dialog */
.picker-overlay {
  position: fixed; inset: 0; z-index: 55; background: oklch(0% 0 0 / 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.picker-sheet {
  width: min(640px, 100%); max-height: 85dvh; display: flex; flex-direction: column; gap: 0.8rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
.picker-head { display: flex; align-items: center; gap: 0.7rem; }
.picker-head h2 { font-size: var(--text-lg); margin: 0; flex: 1; }
.picker-list { overflow-y: auto; display: grid; gap: 0.5rem; }
.picker-row {
  display: grid; grid-template-columns: 28px 56px 1fr; align-items: center; gap: 0.8rem;
  padding: 0.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.picker-row input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }
.picker-row .thumb { width: 56px; height: 56px; font-size: 1.4rem; }
.picker-name { min-width: 0; font-weight: 600; }
.picker-name small { color: var(--text-dim); font-weight: 500; }

/* ============ Material-Kategorien, Raster, Haltbarkeit ============ */
.seg-wrap { flex-wrap: wrap; }
.seg-wrap button { flex: 1 1 45%; min-height: 48px; font-size: 0.95rem; }
.opened-toggle { width: 100%; min-height: var(--tap); }
.opened-toggle[aria-pressed="true"] { border-color: var(--warn); color: var(--warn); }
.barcode-row { display: grid; grid-template-columns: 1fr var(--tap); gap: 0.6rem; }

.warn-tile {
  grid-column: span 2; min-height: auto; flex-direction: row; align-items: center; gap: 1rem;
  background: color-mix(in oklch, var(--warn) 18%, var(--surface)); border-color: var(--warn);
}
.warn-tile .tile-count { font-size: var(--text-xl); }
.warn-tile .tile-label { color: var(--text); opacity: 0.85; }

/* Raster */
.matrix-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
table.matrix { border-collapse: separate; border-spacing: 4px; width: max-content; min-width: 100%; }
table.matrix th, table.matrix td { padding: 0; }
table.matrix thead th {
  font-size: 0.85rem; color: var(--text-dim); font-weight: 700; text-align: center;
  min-width: 52px; padding: 0.3rem 0;
}
table.matrix .corner { font-size: 0.75rem; text-align: left; padding-right: 0.5rem; white-space: nowrap; }
table.matrix .rowhead {
  position: sticky; left: 0; z-index: 1; background: var(--bg);
  font-size: 0.9rem; font-weight: 800; color: var(--text); text-align: right;
  padding-right: 0.6rem; min-width: 48px;
}
.matrix .cell {
  min-width: 52px; height: 52px; border-radius: var(--r-sm); text-align: center;
  font-weight: 800; font-size: 1rem; vertical-align: middle;
}
.matrix .cell.has  { background: color-mix(in oklch, var(--ok) 26%, var(--surface)); color: var(--text); }
.matrix .cell.low  { background: var(--warn); color: var(--accent-ink); }
.matrix .cell.empty-cell { background: var(--surface); color: var(--text-dim); opacity: 0.5; }
.matrix .cell.has:active, .matrix .cell.low:active { transform: scale(0.95); }
.matrix-legend { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.8rem; }
.matrix-legend .dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.matrix-legend .dot.has  { background: color-mix(in oklch, var(--ok) 26%, var(--surface)); }
.matrix-legend .dot.low  { background: var(--warn); }
.matrix-legend .dot.none { background: var(--surface); }

/* ============ Aufenthaltsort & Einkaufsliste ============ */
.pill.here { background: color-mix(in oklch, var(--accent) 25%, transparent); color: var(--accent); }
.place-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.place-btn {
  min-height: 46px; padding: 0 1rem; border-radius: var(--r-full);
  border: 2px solid var(--line); background: var(--surface-2); color: var(--text-dim); font-weight: 700;
}
.place-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-hi); color: var(--text); }
.place-btn.place-other { border-style: dashed; }

.add-row { display: grid; grid-template-columns: 1fr auto; gap: 0.6rem; }
.add-row .qty-input { width: 90px; }
.add-row .btn { min-width: var(--tap); }
.site-filter { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.4rem; margin-bottom: 0.6rem; }
.chip {
  flex: 0 0 auto; padding: 0.5rem 1rem; border-radius: var(--r-full);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-dim); font-weight: 700;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.shop-row {
  display: grid; grid-template-columns: var(--tap) 1fr auto; align-items: center; gap: 0.8rem;
  padding: 0.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.shop-row.done { opacity: 0.5; }
.shop-row.done .item-name { text-decoration: line-through; }
.shop-row .check {
  width: 46px; height: 46px; border-radius: var(--r-sm); border: 2px solid var(--line);
  background: var(--surface-2); color: var(--ok); font-size: 1.4rem; font-weight: 800;
}
.shop-row .check[aria-pressed="true"] { border-color: var(--ok); background: color-mix(in oklch, var(--ok) 20%, transparent); }
.shop-main { min-width: 0; }

/* Objekte & Entnahme */
select { width: 100%; min-height: var(--tap); padding: 0 1rem; font-size: var(--text-lg);
  background: var(--surface-2); color: var(--text); border: 2px solid var(--line);
  border-radius: var(--r-md); outline: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) center, calc(100% - 14px) center;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; }
select:focus { border-color: var(--accent); }
.linklike { background: none; border: none; padding: 0; color: var(--accent); font-weight: 700; text-decoration: underline; }
.shop-row .rename, .shop-row .del { min-height: 44px; min-width: 44px; }
.site-row { grid-template-columns: 34px 1fr auto auto; gap: 0.5rem; }
.site-ico { font-size: 1.3rem; text-align: center; }

/* ============ Filterleiste ============ */
.filterbar { display: grid; gap: 0.5rem; margin-bottom: 0.8rem; }
.chip-row { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.3rem; }
.chip-row::-webkit-scrollbar { height: 0; }
.filter-foot { border-top: 1px solid var(--line); padding-top: 0.6rem; }
.chip.reset { border-style: dashed; color: var(--text-dim); }
#count-note { margin: 0 0 0.6rem 0.2rem; }
/* Werkzeug-Kategorien */
#seg-cat button { flex: 1 1 30%; min-height: 46px; font-size: 0.9rem; padding: 0 0.6rem; }
.cat-free { margin-top: 0.5rem; font-size: 0.95rem; min-height: 48px; }
.pill.cat { background: color-mix(in oklch, var(--accent) 20%, transparent); color: var(--accent); }
/* Schnellschalter am Verbrauchsmaterial */
.flag-row { display: grid; gap: 0.6rem; }
.flag-btn {
  min-height: var(--tap); padding: 0 1rem; border-radius: var(--r-md);
  border: 2px solid var(--line); background: var(--surface-2);
  color: var(--text-dim); font-weight: 700; font-size: var(--text-lg); text-align: left;
}
.flag-btn:active { transform: scale(0.98); }
.flag-btn.on { border-color: var(--accent); background: color-mix(in oklch, var(--accent) 18%, var(--surface)); color: var(--text); }
