
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #121212;
  --surface: #1e1e2e;
  --surface2: #2a2a3e;
  --surface3: #313145;
  --accent: #c084fc;
  --accent2: #a855f7;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --selected: #7c3aed;
  --selected-border: #a855f7;
  --checked: #334155;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
  --radius-sm: 8px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 80px;
}

.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface3);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.topbar h1 { font-size: 1.1rem; font-weight: 600; color: var(--accent); letter-spacing: 0.5px; }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  background: var(--surface2);
  border: none; border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer;
  padding: 8px; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
  min-width: 40px; min-height: 40px;
}
.icon-btn:active { transform: scale(0.93); }
.icon-btn:hover { background: var(--surface3); }
.icon-btn.accent { background: var(--selected); color: #fff; }
.icon-btn.accent:hover { background: var(--accent2); }
.icon-btn.danger { background: #7f1d1d; color: #fca5a5; }
.icon-btn .material-icons-round { font-size: 22px; }

.view { display: none; }
.view.active { display: block; }

.categories-grid {
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}

.category-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--surface3);
  transition: border-color 0.2s;
}
.category-card.has-selected { border-color: var(--selected-border); }

.category-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}
.category-header:active { background: var(--surface2); }

.cat-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.cat-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.cat-icon .material-icons-round { font-size: 24px; color: var(--accent); }

.category-header .cat-name { flex: 1; font-weight: 600; font-size: 1rem; }
.category-header .cat-count {
  font-size: 0.75rem; background: var(--selected);
  color: #fff; border-radius: 20px; padding: 2px 8px;
  display: none;
}
.category-card.has-selected .cat-count { display: inline-block; }

.collapse-icon { color: var(--text-muted); transition: transform 0.3s; }
.category-card.collapsed .collapse-icon { transform: rotate(-90deg); }

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px; padding: 4px 12px 14px;
}
.category-card.collapsed .items-grid { display: none; }

.item-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  background: var(--surface2); position: relative;
  user-select: none;
}
.item-tile:active { transform: scale(0.93); }
.item-tile:hover { background: var(--surface3); }

.item-icon {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}
.item-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.item-icon .material-icons-round { font-size: 22px; color: var(--text-muted); }

.item-tile.selected .item-icon {
  border-color: var(--selected-border);
  background: var(--selected);
}
.item-tile.selected .item-icon .material-icons-round { color: #fff; }
.item-tile.selected::after {
  content: '✓';
  position: absolute; top: 4px; right: 4px;
  background: var(--success); color: #fff;
  border-radius: 50%; width: 16px; height: 16px;
  font-size: 10px; display: flex; align-items: center; justify-content: center;
  line-height: 16px; text-align: center;
}

.item-name {
  font-size: 0.68rem; text-align: center; color: var(--text-muted);
  line-height: 1.2; word-break: break-word; max-width: 80px;
}
.item-tile.selected .item-name { color: var(--text); }

.add-item-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s;
  background: var(--surface); border: 1.5px dashed var(--surface3);
  color: var(--text-muted); font-size: 0.68rem;
}
.add-item-tile:hover { border-color: var(--accent); color: var(--accent); }
.add-item-tile .material-icons-round { font-size: 22px; }

.add-category-btn {
  margin: 4px 16px 0;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px dashed var(--surface3);
  color: var(--text-muted); cursor: pointer; font-size: 0.9rem;
  transition: border-color 0.2s, color 0.2s;
}
.add-category-btn:hover { border-color: var(--accent); color: var(--accent); }

.list-container { padding: 16px; }
.list-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.list-header h2 { flex: 1; font-size: 1.1rem; color: var(--accent); }

.list-items { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: opacity 0.3s, background 0.2s;
  border: 1px solid var(--surface3);
}
.list-item.checked {
  opacity: 0.5; background: var(--checked);
  border-color: transparent;
}
.list-item.checked .item-label { text-decoration: line-through; color: var(--text-muted); }

.list-item input[type=checkbox] { display: none; }
.custom-checkbox {
  width: 24px; height: 24px; border-radius: 6px;
  border: 2px solid var(--surface3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: border-color 0.2s, background 0.2s;
}
.list-item.checked .custom-checkbox {
  background: var(--success); border-color: var(--success);
}
.custom-checkbox .material-icons-round { font-size: 16px; color: #fff; display: none; }
.list-item.checked .custom-checkbox .material-icons-round { display: block; }

.item-label { flex: 1; font-size: 0.95rem; }
.list-item-icon { width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
  background: var(--surface2); display: flex; align-items: center; justify-content: center; }
.list-item-icon img { width: 100%; height: 100%; object-fit: cover; }
.list-item-icon .material-icons-round { font-size: 18px; color: var(--text-muted); }

.delete-item-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; display: flex;
  border-radius: 4px; transition: color 0.2s;
}
.delete-item-btn:hover { color: var(--danger); }
.delete-item-btn .material-icons-round { font-size: 18px; }

.empty-list {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-list .material-icons-round { font-size: 64px; margin-bottom: 12px; display: block; opacity: 0.4; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 200; display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px; width: 100%; max-width: 600px;
  transform: translateY(30px); transition: transform 0.25s;
  border-top: 1px solid var(--surface3);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal h3 { font-size: 1rem; margin-bottom: 16px; color: var(--accent); }

.modal-input {
  width: 100%; padding: 12px 14px;
  background: var(--surface2); border: 1px solid var(--surface3);
  border-radius: var(--radius-sm); color: var(--text); font-size: 0.95rem;
  margin-bottom: 12px; outline: none;
  transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }

.icon-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px; max-height: 200px; overflow-y: auto; margin-bottom: 12px;
}
.icon-option {
  padding: 8px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 2px solid transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, background 0.2s;
}
.icon-option:hover { background: var(--surface3); }
.icon-option.selected { border-color: var(--accent); background: var(--selected); }
.icon-option .material-icons-round { font-size: 24px; color: var(--text-muted); }
.icon-option.selected .material-icons-round { color: #fff; }

.image-upload-label {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: var(--surface2);
  border: 1.5px dashed var(--surface3); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 0.85rem;
  margin-bottom: 12px; transition: border-color 0.2s;
}
.image-upload-label:hover { border-color: var(--accent); color: var(--accent); }
#catImagePreview, #itemImagePreview { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; display: none; }

.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  flex: 1; padding: 12px; border-radius: var(--radius-sm);
  border: none; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--selected); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-cancel { background: var(--surface2); color: var(--text-muted); }
.btn-cancel:hover { background: var(--surface3); }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #991b1b; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface3); color: var(--text);
  padding: 10px 20px; border-radius: 20px; font-size: 0.85rem;
  opacity: 0; transition: opacity 0.3s, transform 0.3s;
  z-index: 300; pointer-events: none; white-space: nowrap;
  border: 1px solid var(--surface2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

.loader {
  display: flex; align-items: center; justify-content: center;
  padding: 60px 20px; color: var(--text-muted); gap: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--surface3);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

body.light {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #e2e8f0;
  --surface3: #cbd5e1;
  --accent: #7c3aed;
  --accent2: #6d28d9;
  --text: #1e293b;
  --text-muted: #64748b;
  --selected: #7c3aed;
  --selected-border: #a855f7;
  --checked: #e2e8f0;
  --danger: #ef4444;
  --success: #16a34a;
}

.category-card.dragging {
  opacity: 0.4;
  border: 2px dashed var(--accent);
}
.category-card.drag-over {
  border: 2px solid var(--accent);
  background: var(--surface2);
}
.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  padding: 4px;
  display: flex;
  align-items: center;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle .material-icons-round { font-size: 20px; }
