:root {
  --bg: #0d1210;
  --surface: #171e1a;
  --text: #edf4ef;
  --muted: #a7b3ab;
  --green: #4fbd83;
  --green-dark: #8addad;
  --green-soft: #203c2d;
  --border: #34423a;
  --danger: #d45b5b;
  --danger-soft: #462626;
  --shadow: 0 12px 32px rgba(0, 0, 0, .34);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input { font: inherit; }
input { font-size: 17px !important; } /* Safari darf Eingabefelder nicht automatisch vergrößern */
button { cursor: pointer; }
::selection { background: #315d43; color: #ffffff; }
input, button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(79,189,131,.42); outline-offset: 2px; }
.hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, env(safe-area-inset-left));
  background: rgba(18,24,21,.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.app-header h1 { margin: 0; font-size: clamp(1.35rem, 4vw, 2rem); }
.status { margin: .25rem 0 0; color: var(--muted); font-size: .9rem; }
main { width: min(980px, 100%); margin: 0 auto; padding: 1rem; }
.view { display: none; }
.view.active { display: block; }
.toolbar, .section-head, .inline-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}
.section-head { margin-bottom: 1rem; }
.section-head h2, .section-head p { margin: 0; }
.section-head p { margin-top: .35rem; color: var(--muted); }
.shopping-head { align-items: flex-start; }

button {
  border: 0;
  border-radius: 12px;
  padding: .8rem 1rem;
  font-weight: 750;
}
.primary { color: #07110b; background: var(--green); }
.primary:hover { background: var(--green-dark); }
.secondary { color: #c9f4da; background: var(--green-soft); border: 1px solid #315d43; }
.danger { color: white; background: #a84242; }
.wide { width: 100%; margin: 1.6rem 0 max(.5rem, env(safe-area-inset-bottom)); }
.icon-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; color: #c9f4da; background: var(--green-soft); border: 1px solid #315d43; font-size: 1.4rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.card {
  position: relative;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.list-card { cursor: pointer; }
.list-card:hover { border-color: #4f8f6b; transform: translateY(-1px); background: #1b241f; }
.list-card h3 { margin: 0 2rem .4rem 0; }
.list-card p { margin: 0; color: var(--muted); }
.delete-list { position: absolute; top: .55rem; right: .55rem; padding: .45rem; color: var(--danger); background: transparent; }
.empty { padding: 1.6rem 1rem; text-align: center; color: var(--muted); border: 2px dashed var(--border); border-radius: 16px; }

.inline-form input {
  color: var(--text);
  flex: 1 1 250px;
  min-width: 0;
  padding: .9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.list-stack { display: grid; gap: .65rem; margin-top: 1rem; }
.article-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.article-row button { padding: .55rem .75rem; color: var(--danger); background: var(--danger-soft); }

.group-title { display: flex; align-items: center; gap: .55rem; margin: 1.25rem 0 .65rem; }
.group-title h3 { margin: 0; }
.bought-title { margin-top: 1.8rem; }
.count-badge { min-width: 1.7rem; padding: .15rem .5rem; text-align: center; color: var(--green-dark); background: var(--green-soft); border-radius: 999px; font-size: .85rem; font-weight: 800; }
.shopping-list { display: grid; gap: .65rem; min-height: 20px; }
.shopping-item { position: relative; overflow: hidden; border-radius: 15px; touch-action: pan-y; }
.swipe-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding-right: 1.1rem; color: white; background: var(--danger); font-weight: 800; }
.item-row {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 42px minmax(80px, 1fr) minmax(100px, 132px) 46px;
  align-items: center;
  gap: .65rem;
  padding: .58rem .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 15px;
  transition: transform .16s ease, opacity .16s ease;
}
.drag-handle {
  display: grid;
  place-items: center;
  width: 40px;
  height: 42px;
  padding: 0;
  border-radius: 10px;
  color: #aab8b0;
  background: #222d27;
  font-size: 1.35rem;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
body.is-sorting { user-select: none; }
.item-name { min-width: 0; overflow-wrap: anywhere; font-weight: 780; }
.item-quantity { color: var(--text); width: 100%; min-width: 0; height: 38px; padding: .38rem .58rem; background: #202923; border: 1px solid #435248; border-radius: 9px; box-shadow: inset 0 1px 2px rgba(0,0,0,.22); }
.item-quantity:hover { border-color: #5f7567; }
.item-quantity:focus { border-color: var(--green); background: #253129; outline: 2px solid rgba(79,189,131,.2); outline-offset: 1px; }
.buy-toggle {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--green);
  background: var(--surface);
  border: 2px solid var(--green);
  border-radius: 50%;
  font-size: 1.2rem;
}
.buy-toggle:hover { background: var(--green-soft); }
input::placeholder { color: #7f8d84; opacity: 1; }
.shopping-item.dragging .item-row { opacity: .45; }
.shopping-item.drop-before { box-shadow: 0 -4px 0 var(--green); }
.shopping-item.drop-after { box-shadow: 0 4px 0 var(--green); }
.bought .item-row { color: #93a098; background: #222b26; }
.bought .item-name { text-decoration: line-through; }
.bought .drag-handle { visibility: hidden; }
.bought .buy-toggle { color: white; background: var(--green); }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; background: rgba(0,0,0,.72); }
.modal { width: min(540px, 100%); max-height: 86vh; overflow: auto; padding: 1.1rem; background: #171e1a; border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.modal h3 { margin-top: 0; }
.modal-input { color: var(--text); background: #111713; width: 100%; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1rem; }
.choice-list { display: grid; gap: .55rem; max-height: 55vh; overflow: auto; }
.choice-row { background: #121814; display: flex; align-items: center; gap: .7rem; padding: .72rem; border: 1px solid var(--border); border-radius: 12px; }
.choice-row input { transform: scale(1.2); }
.toast { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 90; width: min(92%, 540px); padding: .9rem 1rem; transform: translateX(-50%); color: white; background: #26332c; border: 1px solid #3c5145; border-radius: 12px; box-shadow: var(--shadow); }
.toast button { float: right; padding: 0; color: #9ce0b9; background: transparent; }

@media (max-width: 660px) {
  .toolbar > button, .shopping-head > button { width: 100%; }
  .shopping-list { gap: .5rem; }
  .item-row {
    grid-template-columns: 36px minmax(70px, 1fr) minmax(86px, 112px) 40px;
    gap: .42rem;
    padding: .52rem .55rem;
  }
  .drag-handle { width: 34px; height: 38px; font-size: 1.2rem; }
  .buy-toggle { width: 38px; height: 38px; }
  .item-quantity { height: 36px; padding: .32rem .48rem; }
  .item-name { font-size: .98rem; }
}

@media (max-width: 370px) {
  .item-row {
    grid-template-columns: 32px minmax(60px, 1fr) minmax(78px, 96px) 36px;
    gap: .32rem;
    padding-inline: .45rem;
  }
  .drag-handle { width: 32px; }
  .buy-toggle { width: 36px; height: 36px; }
}

/* iPhone/iPad: Fokus-Zoom zuverlässig unterbinden */
@supports (-webkit-touch-callout: none) {
  input, textarea, select { font-size: 17px !important; transform: translateZ(0); }
}

/* Version 2.6: kompakte Synchronisationsleiste */
.header-title { min-width: 0; }
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  flex-wrap: nowrap;
}
.sync-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 42px;
  padding: .62rem .78rem;
  color: var(--text);
  background: #222d27;
  border: 1px solid var(--border);
  white-space: nowrap;
  font-size: .88rem;
}
.sync-btn span { font-size: 1.05rem; line-height: 1; }
.sync-btn:hover { border-color: var(--green); background: #29372f; }
.sync-btn.upload { color: #b8f0cf; }
.sync-btn.download { color: #c8d9ff; }
.sync-btn:disabled { opacity: .55; cursor: wait; }
.sync-info { color: var(--muted); font-size: .9rem; line-height: 1.45; }
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  width: fit-content;
  margin-top: .35rem;
  padding: .25rem .55rem;
  color: var(--muted);
  background: #202923;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .78rem;
  line-height: 1.2;
}
.status-dot { width: .55rem; height: .55rem; flex: 0 0 auto; border-radius: 50%; background: #d9a441; box-shadow: 0 0 0 3px rgba(217,164,65,.12); }
.sync-status[data-state="synced"] .status-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(79,189,131,.12); }
.sync-status[data-state="offline"] .status-dot { background: #d45b5b; box-shadow: 0 0 0 3px rgba(212,91,91,.13); }
.sync-status[data-state="busy"] .status-dot { background: #79a9ff; animation: statusPulse 1s infinite alternate; }
@keyframes statusPulse { to { opacity: .35; transform: scale(.75); } }

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  .sync-btn { font-size: .8rem; padding: .56rem .62rem; }
}

@media (max-width: 520px) {
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .65rem;
    padding-block: .8rem;
  }
  .header-title h1 { font-size: clamp(1.18rem, 5.8vw, 1.5rem); }
  .header-actions { gap: .38rem; }
  .sync-btn { min-height: 40px; padding: .52rem .58rem; }
  .header-actions .icon-btn { flex: 0 0 40px; width: 40px; height: 40px; }
}

@media (max-width: 370px) {
  .sync-btn { font-size: .76rem; padding-inline: .48rem; gap: .24rem; }
  .sync-status { font-size: .72rem; }
}


/* Version 3.0 – größere Schrift und moderne App-Optik */
:root { --surface-glow: rgba(79,189,131,.08); }
body { letter-spacing: .005em; }
.view.active { animation: viewIn .22s ease both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.card, .article-row, .item-row, .summary-card { transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.primary, .secondary, .sync-btn, .icon-btn { transition: transform .14s ease, background .14s ease, border-color .14s ease; }
button:active { transform: scale(.97); }

.home-summary { display: grid; grid-template-columns: minmax(145px, .7fr) minmax(220px, 1.3fr); gap: .75rem; margin-bottom: 1rem; }
.summary-card { display: flex; flex-direction: column; justify-content: center; min-height: 82px; padding: .9rem 1rem; background: linear-gradient(145deg, #1c2721, #171e1a); border: 1px solid var(--border); border-radius: 17px; box-shadow: var(--shadow); }
.summary-number { color: var(--green); font-size: 2rem; line-height: 1; font-weight: 850; }
.summary-label { margin-top: .25rem; color: var(--muted); font-size: .88rem; }
.backup-card strong { margin-top: .25rem; font-size: 1rem; }
.search-box { display: flex; align-items: center; gap: .55rem; margin-top: .9rem; padding: .12rem .75rem; color: var(--muted); background: #151d18; border: 1px solid var(--border); border-radius: 13px; }
.search-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--surface-glow); }
.search-box input { width: 100%; min-width: 0; padding: .78rem 0; color: var(--text); background: transparent; border: 0; outline: 0; }
.modal-search { margin: 0 0 .8rem; }
.frequent-badge { margin-left: auto; padding: .18rem .45rem; color: #b8f0cf; background: var(--green-soft); border-radius: 999px; font-size: .7rem; font-weight: 800; }

.item-name { font-size: 1.28rem; line-height: 1.22; }
.item-quantity { font-size: 1.08rem; font-weight: 650; }
.group-title h3 { font-size: 1.28rem; }
.shopping-head h2 { font-size: clamp(1.65rem, 5vw, 2.15rem); }
.shopping-head p { color: #a8d7ba; font-size: 1rem; font-weight: 650; }
.item-row:hover { border-color: #3e674d; box-shadow: 0 5px 18px rgba(0,0,0,.16); }
.buy-toggle { transition: transform .14s ease, background .14s ease; }
.buy-toggle:active { transform: scale(.9); }

@media (max-width: 660px) {
  .home-summary { grid-template-columns: 1fr 1.45fr; }
  .summary-card { min-height: 72px; padding: .75rem .8rem; }
  .summary-number { font-size: 1.75rem; }
  .item-name { font-size: 1.16rem; }
  .item-quantity { font-size: 1.02rem; }
  .group-title h3 { font-size: 1.2rem; }
  .shopping-head p { font-size: .94rem; }
}
@media (max-width: 390px) {
  .home-summary { grid-template-columns: 1fr; }
  .item-name { font-size: 1.1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Version 3.1: Kategorien */
.article-create-form select,
.article-category-select,
.article-name-edit,
.category-name-edit {
  color: var(--text);
  min-width: 0;
  padding: .78rem .85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.article-create-form select { flex: 0 1 220px; }
.category-heading {
  display: flex;
  align-items: center;
  gap: .52rem;
  margin: 1rem 0 .45rem;
  padding: .38rem .2rem;
  color: #dce8e0;
  font-size: .92rem;
  letter-spacing: .01em;
}
.category-heading:first-child { margin-top: .2rem; }
.category-dot {
  width: .8rem;
  height: .8rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--category-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--category-color) 20%, transparent);
}
.category-count {
  margin-left: auto;
  min-width: 1.6rem;
  padding: .08rem .42rem;
  text-align: center;
  color: var(--muted);
  background: #202923;
  border-radius: 999px;
  font-size: .76rem;
}
.article-edit-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 220px) auto;
}
.article-edit-row button,
.category-row button { padding: .55rem .75rem; color: var(--danger); background: var(--danger-soft); }
.category-form { margin-bottom: 1rem; }
.color-picker-label {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: var(--muted);
  padding: .45rem .65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.color-picker-label input,
.category-color-edit {
  width: 46px;
  height: 36px;
  padding: 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
}
.category-row {
  display: grid;
  grid-template-columns: auto minmax(130px, 1fr) auto auto;
  align-items: center;
  gap: .75rem;
  padding: .72rem .85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.category-usage { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.shopping-list .category-heading { margin-top: .8rem; padding-left: .35rem; }
.shopping-list .category-heading + .shopping-item { margin-top: 0; }
.frequent-badge { margin-left: auto; color: #9ce0b9; }
@media (max-width: 660px) {
  .toolbar > button { width: 100%; }
  .article-create-form select { flex: 1 1 100%; width: 100%; }
  .article-edit-row { grid-template-columns: minmax(0, 1fr) minmax(105px, 42%) auto; gap: .45rem; padding: .62rem; }
  .article-edit-row button { grid-column: 3; }
  .category-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .category-usage { grid-column: 2; }
  .category-row button { grid-column: 3; grid-row: 1 / span 2; }
}


/* Listenabhängige Reihenfolge der Kategorien */
.category-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.category-card .category-row {
  border: 0;
  border-radius: 0;
  background: transparent;
}
.category-position-section {
  padding: 0 .85rem .85rem;
  border-top: 1px solid var(--border);
}
.category-position-title {
  padding: .72rem 0 .55rem;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.category-position-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: .55rem;
}
.category-position-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  align-items: center;
  gap: .5rem;
  padding: .48rem .55rem;
  background: #18201b;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.category-position-field span {
  overflow: hidden;
  color: var(--text);
  font-size: .9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.category-position-field input {
  width: 64px;
  min-width: 0;
  padding: .38rem .32rem;
  text-align: center;
  color: var(--text);
  background: #101612;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 17px;
}
.category-position-empty {
  color: var(--muted);
  font-size: .88rem;
}
@media (max-width: 660px) {
  .category-position-grid { grid-template-columns: 1fr; }
}


/* Sortierung der Kategorienverwaltung */
.category-sort-toolbar {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin: 0 0 1rem;
  padding: .75rem .85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.category-sort-toolbar label {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
  white-space: nowrap;
}
.category-sort-toolbar select {
  flex: 1;
  min-width: 0;
}
@media (max-width: 520px) {
  .category-sort-toolbar { align-items: stretch; flex-direction: column; gap: .45rem; }
}

/* Version 3.5: Größere Kategorieüberschriften und Artikelnamen in Einkaufslisten */
.shopping-list .category-heading {
  gap: .78rem;
  margin-top: 1.15rem;
  margin-bottom: .55rem;
  padding: .52rem .4rem;
  font-size: 1.48rem;
  line-height: 1.2;
  font-weight: 850;
  letter-spacing: .005em;
}
.shopping-list .category-heading strong {
  font-size: inherit;
  font-weight: 850;
}
.shopping-list .category-dot {
  width: 1.28rem;
  height: 1.28rem;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--category-color) 22%, transparent);
}
.shopping-list .item-name {
  font-size: 1.38rem;
  line-height: 1.25;
}
@media (max-width: 660px) {
  .shopping-list .category-heading { font-size: 1.4rem; }
  .shopping-list .category-dot { width: 1.2rem; height: 1.2rem; }
  .shopping-list .item-name { font-size: 1.28rem; }
}
@media (max-width: 390px) {
  .shopping-list .category-heading { font-size: 1.32rem; }
  .shopping-list .category-dot { width: 1.12rem; height: 1.12rem; }
  .shopping-list .item-name { font-size: 1.2rem; }
}

/* Version 3.6: Sicheres Schließen mit Hinweis auf ungesicherte Änderungen */
.sync-btn.close-app {
  border-color: #755f35;
  background: #2a2418;
  color: #f4d58a;
}
.sync-btn.close-app:hover { background: #352d1d; }
.closed-screen {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  background: var(--bg);
}
.closed-screen.hidden { display: none; }
.closed-card {
  width: min(100%, 430px);
  padding: 2rem 1.4rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.closed-icon {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  border-radius: 50%;
  font-size: 2.5rem;
  font-weight: 900;
  color: #0e1a13;
  background: #62d795;
}
.closed-card h2 { margin: 0 0 .7rem; font-size: 1.7rem; }
.closed-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.close-question-actions,
.close-error-actions { flex-wrap: wrap; }
@media (max-width: 600px) {
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .sync-btn.close-app { flex-basis: auto; }
  .close-question-actions button,
  .close-error-actions button { flex: 1 1 100%; }
}


/* Version 3.7: Kategorien je Einkaufsliste durch Verschieben sortieren */
.category-sort-toolbar { justify-content: space-between; }
.category-sort-toolbar > div { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.category-list-label { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
#categoryListName { overflow: hidden; font-size: 1.08rem; text-overflow: ellipsis; white-space: nowrap; }
.category-sort-card { position: relative; touch-action: pan-y; }
.category-sort-card.dragging { opacity: .48; }
.category-sort-card.drop-before::before,
.category-sort-card.drop-after::after { content: ''; position: absolute; left: .5rem; right: .5rem; height: 3px; border-radius: 3px; background: var(--accent); z-index: 5; }
.category-sort-card.drop-before::before { top: -3px; }
.category-sort-card.drop-after::after { bottom: -3px; }
.category-sort-card .category-row { grid-template-columns: auto auto auto minmax(0, 1fr) auto auto; }
.category-drag-handle { width: 42px; min-width: 42px; height: 42px; padding: 0; cursor: grab; touch-action: none; font-size: 1.25rem; }
.category-drag-handle:active { cursor: grabbing; }
.category-order-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: var(--muted); background: #101612; border: 1px solid var(--border); font-weight: 800; }
.category-delete-button { white-space: nowrap; }
.wide-select { width: 100%; margin-top: .45rem; }
@media (max-width: 660px) {
  .category-sort-toolbar { align-items: stretch; flex-direction: column; }
  .category-sort-toolbar button { width: 100%; }
  .category-sort-card .category-row { grid-template-columns: auto auto auto minmax(0, 1fr) auto; }
  .category-usage { grid-column: 4; }
  .category-delete-button { grid-column: 5; grid-row: 1 / span 2; }
}

/* Version 3.8: Mac-Sortierung und Artikelbearbeitung je Kategorie */
.category-sort-card { user-select: none; }
.category-sort-card input { user-select: text; }
.category-drag-handle[draggable="true"] { -webkit-user-drag: element; }
.category-modal-dot { display: inline-block; width: 18px; height: 18px; margin-right: .55rem; border-radius: 50%; vertical-align: -.12rem; background: var(--category-color); box-shadow: 0 0 0 3px color-mix(in srgb, var(--category-color) 20%, transparent); }
.category-modal-help { margin-top: -.25rem; color: var(--muted); }
.category-article-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .65rem; margin: 1rem 0; }
.category-article-add .modal-input { margin: 0; }
.category-article-edit-list { display: flex; flex-direction: column; gap: .55rem; max-height: min(52vh, 520px); padding-right: .15rem; overflow-y: auto; }
.category-article-edit-row { display: grid; grid-template-columns: minmax(150px, 1.4fr) minmax(130px, 1fr) auto; gap: .55rem; align-items: center; padding: .55rem; border: 1px solid var(--border); border-radius: .8rem; background: #101612; }
.category-article-edit-row input,
.category-article-edit-row select { width: 100%; min-width: 0; }
.danger-small { padding: .62rem .75rem; color: var(--danger); background: var(--danger-soft); }
.category-articles-empty { padding: 1.25rem .8rem; }
@media (max-width: 650px) {
  .category-article-add { grid-template-columns: 1fr; }
  .category-article-edit-row { grid-template-columns: minmax(0, 1fr) auto; }
  .category-article-category { grid-column: 1; }
  .category-article-delete { grid-column: 2; grid-row: 1 / span 2; }
}


/* Version 3.9: Kategorien ohne sichtbare Positionsfelder verschieben */
.category-sort-card { cursor: grab; }
.category-sort-card:active { cursor: grabbing; }
.category-sort-card .category-row { grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
.category-order-number,
.category-position-section,
.category-position-grid,
.category-position-field { display: none !important; }
.category-drag-handle {
  width: 52px;
  min-width: 52px;
  height: 48px;
  font-size: 1.6rem;
  line-height: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.category-sort-card input,
.category-sort-card button:not(.category-drag-handle) { cursor: auto; }
@media (max-width: 660px) {
  .category-sort-card .category-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .category-usage { grid-column: 2; }
  .category-delete-button { grid-column: 3; grid-row: 1 / span 2; }
  .category-drag-handle { grid-column: 4; grid-row: 1 / span 2; align-self: stretch; height: 100%; min-height: 58px; }
}


/* Version 4.0: Ganze Kategoriezeile als Ziehfläche, ohne Griffleiste */
.category-sort-card .category-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.category-drag-handle { display: none !important; }
.category-sort-card { cursor: grab; }
.category-sort-card.dragging,
.category-sort-card.touch-dragging { cursor: grabbing; touch-action: none; }
.category-sort-card input,
.category-sort-card button,
.category-sort-card select,
.category-sort-card textarea,
.category-sort-card label { cursor: auto; }
@media (max-width: 660px) {
  .category-sort-card .category-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .category-usage { grid-column: 2; }
  .category-delete-button { grid-column: 3; grid-row: 1 / span 2; }
}


/* Version 4.2: Kein Safari-Doppeltipp-Zoom beim Öffnen einer Kategorie */
.category-sort-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.category-sort-card.touch-dragging {
  touch-action: none;
}

/* Version 4.9: Safe-Area-Korrektur beim Start aus der Startseiten-Web-App */
body {
  min-height: 100dvh;
}

.app-header {
  padding-top: calc(1rem + env(safe-area-inset-top));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
}

main {
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
}

@media (max-width: 520px) {
  .app-header {
    padding-top: calc(.8rem + env(safe-area-inset-top));
    padding-right: max(.8rem, env(safe-area-inset-right));
    padding-bottom: .8rem;
    padding-left: max(.8rem, env(safe-area-inset-left));
  }
}


/* Abschlussansicht beim direkten Start der Einkaufslisten-Web-App */
.app-closed-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
  background: #050806;
  text-align: center;
}

.app-closed-card {
  max-width: 420px;
}

.app-closed-icon {
  width: 84px;
  height: 84px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(130, 230, 170, 0.75);
  border-radius: 50%;
  font-size: 46px;
  color: #8ee5ad;
  background: rgba(70, 170, 110, 0.12);
}

.app-closed-card h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 8vw, 3rem);
}

.app-closed-card p {
  margin: 0;
  font-size: 1.15rem;
  color: #b9c6bd;
}


/* UI-Anpassung: Schließen technisch vorhanden lassen, aber vollständig ausblenden */
#appCloseBtn {
    display: none !important;
}

/* UI-Anpassung: Laden und Sichern größer darstellen */
#serverUploadBtn,
#serverDownloadBtn {
    font-size: 1.12rem;
    font-weight: 700;
    padding: 0.82rem 1.2rem;
    min-height: 50px;
}


/* Deutlichere Trennung zwischen offenen und gekauften Artikeln */
.bought-title {
  margin-top: 2.8rem !important;
  padding-top: 1.2rem;
  border-top: 3px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.05);
  padding-left: .8rem;
  padding-right: .8rem;
  padding-bottom: .55rem;
  border-radius: .7rem .7rem 0 0;
}

#boughtItems {
  background: rgba(255, 255, 255, 0.05);
  padding: .75rem .8rem 1rem;
  border-radius: 0 0 .7rem .7rem;
}
