/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f8f6f3;
  --card: #ffffff;
  --primary: #7c9a82;
  --primary-dark: #5a7d62;
  --primary-light: #e8f0ea;
  --checked: #b8c4ba;
  --text: #2d3436;
  --text-light: #636e72;
  --text-muted: #a0a4a7;
  --danger: #d4726a;
  --danger-light: #fdf0ef;
  --border: #e8e4df;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

.view {
  min-height: 100vh;
  padding-bottom: calc(2rem + var(--safe-bottom));
}

.hidden {
  display: none !important;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-large {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  border-radius: var(--radius);
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s;
  line-height: 1;
}

.btn-icon:active {
  background: rgba(0,0,0,0.05);
}

.btn-back {
  font-size: 1.5rem;
  margin-right: 0.25rem;
}

.btn-danger-icon {
  color: var(--danger);
}

/* === Welcome Screen === */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: gentle-bounce 3s ease-in-out infinite;
}

@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-container h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-light);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.welcome-actions {
  width: 100%;
  max-width: 320px;
  margin-top: 2rem;
}

.divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 1rem;
}

.join-form {
  display: flex;
  gap: 0.5rem;
}

.join-form input {
  flex: 1;
}

input[type="text"] {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--primary);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  min-height: 1.3em;
}

/* === Share Code === */
.share-code {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 0.5rem;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 1rem 2rem;
  border-radius: var(--radius);
  margin: 1.5rem 0 1rem;
  font-family: "SF Mono", "Menlo", monospace;
}

/* === App Header === */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(1rem + var(--safe-top)) 1.25rem 1rem;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Lists Overview === */
.lists-container {
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.list-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card);
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}

.list-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-lg);
}

.list-card-emoji {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}

.list-card-info {
  flex: 1;
  min-width: 0;
}

.list-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-card-count {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 0.15rem;
}

.list-card-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* === FAB === */
.fab {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  right: calc(50% - 240px + 1rem);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 2rem;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(124,154,130,0.4);
  transition: transform 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  line-height: 1;
}

@media (max-width: 480px) {
  .fab {
    right: 1.5rem;
  }
}

.fab:active {
  transform: scale(0.92);
  background: var(--primary-dark);
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem;
  padding-bottom: calc(1.5rem + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.modal-content input {
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.modal-actions .btn {
  flex: 1;
}

/* === Emoji Picker === */
.emoji-picker {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.emoji-option {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.emoji-option:active {
  transform: scale(0.9);
}

.emoji-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* === Add Item Bar === */
.add-item-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 0.75rem;
  position: sticky;
  top: calc(3.5rem + var(--safe-top));
  background: var(--bg);
  z-index: 9;
}

.add-item-bar input {
  flex: 1;
}

.btn-add {
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 400;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* === Items === */
.items-container {
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.item-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--card);
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: opacity 0.3s ease, transform 0.3s ease;
  -webkit-user-select: none;
  user-select: none;
}

.item-card.checked {
  opacity: 0.55;
}

.item-checkbox {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
  color: transparent;
}

.item-checkbox:active {
  transform: scale(0.85);
}

.item-card.checked .item-checkbox {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 1rem;
  transition: all 0.2s;
  word-break: break-word;
}

.item-card.checked .item-name {
  text-decoration: line-through;
  color: var(--checked);
}

.item-quantity {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.1rem;
}

.item-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.item-card:hover .item-delete,
.item-card:active .item-delete {
  opacity: 1;
}

/* Always show on touch devices */
@media (hover: none) {
  .item-delete {
    opacity: 0.6;
  }
}

.item-delete:active {
  color: var(--danger);
  background: var(--danger-light);
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-light);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* === Settings === */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.setting-label {
  color: var(--text-light);
  font-size: 0.9rem;
}

.setting-value {
  font-weight: 700;
  font-family: "SF Mono", "Menlo", monospace;
  letter-spacing: 0.15rem;
  color: var(--primary-dark);
}

/* === Checked section divider === */
.checked-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.checked-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* === Sync Indicator === */
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
  margin-left: 0.5rem;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(2rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* === Category Headers === */
.category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.25rem 0.4rem;
  margin-top: 0.5rem;
}

.category-header:first-child {
  margin-top: 0;
}

.category-header-icon {
  font-size: 1.1rem;
}

.category-header-name {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
}

.category-header-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* === Category Picker === */
.category-picker {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.category-chip {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.category-chip:active {
  transform: scale(0.95);
}

.category-chip.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}

.category-chip.new-cat {
  border-style: dashed;
  color: var(--text-light);
}

.input-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

/* === Empty Category === */
.category-empty {
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* === Add Item Date Row (Termine) === */
.add-item-date-row {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 0.75rem;
}

.add-item-date-row input[type="date"],
.add-item-date-row input[type="time"],
.add-item-date-row select {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.add-item-date-row input:focus {
  border-color: var(--primary);
}

/* === Item Date (Termine) === */
.item-date {
  font-size: 0.78rem;
  color: var(--primary-dark);
  margin-top: 0.15rem;
  font-weight: 500;
}

.item-termin {
  border-left: 3px solid var(--primary);
}

.item-termin.checked {
  border-left-color: var(--checked);
}

/* === Checked section: reactivate hint === */
.checked-divider-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 0.25rem;
}

/* === Utility === */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
