:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #e8e8e8;
  --text2: #999;
  --accent: #4ade80;
  --accent-dim: #22543d;
  --danger: #f87171;
  --danger-dim: #7f1d1d;
  --pill-bg: #2a2a2a;
  --pill-active: #4ade80;
  --pill-active-text: #000;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #f0f0f0;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text2: #666;
  --accent: #16a34a;
  --accent-dim: #dcfce7;
  --danger: #dc2626;
  --danger-dim: #fee2e2;
  --pill-bg: #e8e8e8;
  --pill-active: #16a34a;
  --pill-active-text: #fff;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1 { font-size: 1.5rem; font-weight: 700; }

.header-right { display: flex; gap: 8px; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
  color: var(--text);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.active { border-color: var(--accent); background: var(--accent-dim); }

/* Search */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text2); }
.clear-search {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Category nav pills */
.category-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.category-nav::-webkit-scrollbar { display: none; }
.cat-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--pill-bg);
  color: var(--text2);
  border: none;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}
.cat-pill:hover { color: var(--text); }
.cat-pill.active { background: var(--pill-active); color: var(--pill-active-text); }
.cat-pill .pill-count {
  font-size: 0.72rem;
  opacity: 0.7;
  margin-left: 4px;
}

/* Add category */
.add-category form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text2); }

button {
  padding: 10px 16px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
}
button:hover { opacity: 0.85; }

/* Categories */
.category {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: all 0.2s;
}
.category.collapsed .category-items,
.category.collapsed .add-item { display: none; }

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.category.collapsed .category-header { border-bottom: none; }

.category-header h2 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.category-header h2:hover { color: var(--accent); }

.cat-count {
  font-size: 0.75rem;
  background: var(--surface2);
  color: var(--text2);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.category-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-icon {
  background: none;
  border: none;
  padding: 4px 8px;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text2);
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-dim); color: var(--danger); }

.chevron {
  font-size: 0.8rem;
  transition: transform 0.2s;
  color: var(--text2);
}
.category.collapsed .chevron { transform: rotate(-90deg); }

/* Items */
.category-items { padding: 4px 0; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  transition: background 0.15s;
}
.item:hover { background: var(--surface2); }
.item.highlight { background: var(--accent-dim); }

.item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.item-name {
  flex: 1;
  font-size: 0.93rem;
  cursor: pointer;
}
.item-name.checked {
  text-decoration: line-through;
  color: var(--text2);
}

.item .btn-icon { padding: 2px 6px; font-size: 0.85rem; }

/* Required star */
.req-star {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 2px;
  color: var(--border);
  transition: color 0.15s, transform 0.15s;
  flex-shrink: 0;
  line-height: 1;
}
.req-star:hover { color: #facc15; transform: scale(1.2); }
.req-star.required { color: #facc15; }

/* Reorder handles */
.reorder-handle {
  cursor: grab;
  color: var(--text2);
  font-size: 1rem;
  padding: 0 4px;
  user-select: none;
  display: none;
}
.reorder-mode .reorder-handle { display: block; }
.reorder-handle:active { cursor: grabbing; }

.item.dragging { opacity: 0.4; }
.item.drag-over { border-top: 2px solid var(--accent); }

/* Add item */
.add-item {
  display: flex;
  gap: 6px;
  padding: 6px 12px 10px;
}
.add-item input { font-size: 0.88rem; padding: 8px 12px; }
.add-item button { padding: 8px 12px; font-size: 0.85rem; }

/* Search results highlight */
.search-highlight { background: var(--accent-dim); padding: 1px 3px; border-radius: 3px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text2);
}
.empty-state .emoji { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* No results */
.no-results {
  text-align: center;
  padding: 32px 20px;
  color: var(--text2);
  font-size: 0.9rem;
}

footer {
  text-align: center;
  padding: 24px 0 16px;
  color: var(--text2);
  font-size: 0.8rem;
}

/* Edit input inline */
.edit-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: inherit;
  font-family: inherit;
  outline: none;
  width: 100%;
}

/* Smooth scroll */
html { scroll-behavior: smooth; }

@media (max-width: 480px) {
  .app { padding: 16px 12px; }
  h1 { font-size: 1.3rem; }
  .add-category form { flex-direction: column; }
  .add-category button { width: 100%; }
  .category-header { padding: 10px 14px; }
  .item { padding: 6px 14px; }
}
