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

:root {
  --bg:        #f7f7f5;
  --surface:   #ffffff;
  --surface-2: #f0f0ed;
  --surface-3: #e8e8e4;
  --border:    #e2e2de;
  --border-2:  #d0d0cb;
  --text:      #111110;
  --text-2:    #6b6b68;
  --text-3:    #b0b0ac;
  --accent:    #111110;
  --accent-fg: #ffffff;
  --green:     #1a6b3c;
  --green-bg:  #edf7f1;
  --green-bd:  #b8dfc8;
  --red:       #c0392b;
  --red-bg:    #fdf0ee;
  --red-bd:    #f5c6c1;
  --r-sm:      10px;
  --r-md:      14px;
  --r-lg:      18px;
  --f:         'DM Sans', -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #111110;
    --surface:   #1a1a18;
    --surface-2: #222220;
    --surface-3: #2a2a28;
    --border:    #2e2e2c;
    --border-2:  #3e3e3c;
    --text:      #f2f2ef;
    --text-2:    #8a8a86;
    --text-3:    #4a4a48;
    --accent:    #f2f2ef;
    --accent-fg: #111110;
    --green:     #4ade80;
    --green-bg:  #0d2b1a;
    --green-bd:  #1a4a2e;
    --red:       #e05c4b;
    --red-bg:    #2a1a18;
    --red-bd:    #5a2820;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f);
  font-weight: 400;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 6rem;
}

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

h1 {
  font-size: 24px;
  font-weight: 300;
  letter-spacing: -0.5px;
  color: var(--text);
  margin-bottom: 4px;
}
.subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 2rem;
  letter-spacing: 0.1px;
}
.section-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Buttons */
.btn {
  font-family: var(--f);
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  letter-spacing: 0.1px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:active { opacity: 0.8; }

.btn-ghost {
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:active { background: var(--surface-2); color: var(--text); }

.btn-danger { color: var(--red); border-color: transparent; }
.btn-danger:active { background: var(--red-bg); }

.btn-sm   { padding: 8px 12px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; min-width: 34px; min-height: 34px; border-radius: var(--r-sm); }

/* Inputs */
input, select {
  font-family: var(--f);
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  outline: none;
  -webkit-appearance: none;
  width: 100%;
  transition: border-color 0.1s;
  letter-spacing: 0.1px;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus { border-color: var(--border-2); }
select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

/* Lists stack */
.lists-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 1.5rem;
}

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.list-card:first-child { border-radius: var(--r-md) var(--r-md) var(--r-sm) var(--r-sm); }
.list-card:last-child  { border-radius: var(--r-sm) var(--r-sm) var(--r-md) var(--r-md); }
.list-card:only-child  { border-radius: var(--r-md); }
.list-card:active { background: var(--surface-2); }

.list-card-icon {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-2);
}
.list-card-body { flex: 1; min-width: 0; }
.list-card-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.list-card-meta { font-size: 12px; color: var(--text-3); letter-spacing: 0.2px; }

/* New list form */
.new-list-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 1rem;
}
.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* List page */
.back-btn-row {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 1.5rem;
}
.list-page-title {
  font-size: 20px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-left: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-track {
  height: 2px;
  background: var(--surface-3);
  border-radius: 2px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* Add item */
.add-item-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 1.25rem;
}
.add-row-top { display: flex; gap: 8px; }
.add-row-top input { flex: 1; }
.add-row-bottom { display: flex; gap: 8px; }
.add-row-bottom input  { width: 72px; flex-shrink: 0; text-align: center; }
.add-row-bottom select { flex: 1; }

/* Items */
.items-list { display: flex; flex-direction: column; gap: 2px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.1s, background 0.1s;
}
.item-row:first-child { border-radius: var(--r-md) var(--r-md) var(--r-sm) var(--r-sm); }
.item-row:last-child  { border-radius: var(--r-sm) var(--r-sm) var(--r-md) var(--r-md); }
.item-row:only-child  { border-radius: var(--r-md); }
.item-row.dragging    { opacity: 0.3; border-style: dashed; }
.item-row.drag-over   { border-color: var(--border-2); background: var(--surface-2); }

.drag-handle {
  color: var(--text-3);
  cursor: grab;
  font-size: 16px;
  flex-shrink: 0;
  padding: 2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }

.item-check {
  width: 22px; height: 22px;
  border: 1.5px solid var(--border-2);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.item-check.checked { background: var(--green); border-color: var(--green); }
.item-check svg { display: none; }
.item-check.checked svg { display: block; }

.item-label {
  flex: 1;
  font-size: 15px;
  color: var(--text);
  line-height: 1.3;
  transition: color 0.15s;
}
.item-label.crossed { text-decoration: line-through; color: var(--text-3); }

.item-qty {
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.item-qty.crossed { text-decoration: line-through; color: var(--text-3); }

/* States */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
  font-size: 14px;
}
.loading-state {
  color: var(--text-3);
  font-size: 14px;
  padding: 1.5rem 0;
}
.error-banner {
  background: var(--red-bg);
  border: 1px solid var(--red-bd);
  color: var(--red);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 1rem;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #faf9f6;
  --surface:    #ffffff;
  --surface-2:  #f2f0eb;
  --border:     #e4e1d9;
  --border-2:   #ccc9c0;
  --text:       #1a1916;
  --text-2:     #6b6860;
  --text-3:     #a8a59e;
  --accent:     #1a1916;
  --danger:     #c0392b;
  --danger-bg:  #fdf0ee;
  --danger-bd:  #f5c6c1;
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --font:       'Georgia', serif;
  --font-ui:    system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #141412;
    --surface:   #1e1d1b;
    --surface-2: #272523;
    --border:    #333130;
    --border-2:  #464340;
    --text:      #f0ede8;
    --text-2:    #9a9790;
    --text-3:    #5c5a56;
    --accent:    #f0ede8;
    --danger:    #e05c4b;
    --danger-bg: #2a1a18;
    --danger-bd: #5a2820;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

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

/* Typography */
h1 {
  font-family: var(--font);
  font-size: 28px;
  font-weight: normal;
  color: var(--text);
  margin-bottom: 0.25rem;
  letter-spacing: -0.3px;
}
.subtitle {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 2rem;
}

/* Buttons */
.btn {
  font-family: var(--font-ui);
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.82; background: var(--accent); }

.btn-danger { color: var(--danger); border-color: var(--danger-bd); }
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm  { padding: 5px 10px; font-size: 12px; }
.btn-icon {
  padding: 5px;
  border-radius: var(--radius-sm);
  line-height: 1;
  border-color: transparent;
}
.btn-icon:hover { background: var(--surface-2); border-color: var(--border); }

/* Form elements */
input, select {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.12s;
  -webkit-appearance: none;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus { border-color: var(--border-2); }
select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* Lists grid */
.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 1.5rem;
}

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
  position: relative;
}
.list-card:hover {
  border-color: var(--border-2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.list-card-title {
  font-family: var(--font);
  font-weight: normal;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}
.list-card-meta { font-size: 12px; color: var(--text-3); }
.list-card-del {
  position: absolute;
  top: 10px; right: 10px;
  opacity: 0;
  transition: opacity 0.12s;
}
.list-card:hover .list-card-del { opacity: 1; }

/* New list form */
.new-list-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.form-group select,
.form-group input { min-width: 145px; }

/* List page */
.back-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1.5rem;
}
.list-title-display {
  font-family: var(--font);
  font-size: 24px;
  font-weight: normal;
  color: var(--text);
}

.progress-bar-wrap {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.add-item-row {
  display: flex;
  gap: 8px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.add-item-row input[type="text"] { flex: 1; min-width: 140px; }
.qty-wrap { display: flex; align-items: center; gap: 4px; }
.qty-wrap input  { width: 64px; text-align: center; }
.qty-wrap select { width: 76px; font-size: 13px; padding: 9px 24px 9px 8px; }

/* Items */
.items-list { display: flex; flex-direction: column; gap: 3px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: border-color 0.12s, background 0.12s;
  user-select: none;
}
.item-row.dragging  { opacity: 0.35; border-style: dashed; }
.item-row.drag-over { border-color: var(--border-2); background: var(--surface-2); }

.drag-handle {
  color: var(--text-3);
  cursor: grab;
  font-size: 15px;
  flex-shrink: 0;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }

.item-check {
  width: 18px; height: 18px;
  border: 1px solid var(--border-2);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}
.item-check.checked { background: var(--accent); border-color: var(--accent); }
.item-check svg { display: none; }
.item-check.checked svg { display: block; }

.item-label {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  transition: color 0.15s;
}
.item-label.crossed {
  text-decoration: line-through;
  color: var(--text-3);
}

.item-qty {
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}
.item-qty.crossed { text-decoration: line-through; color: var(--text-3); }

.item-del {
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}
.item-row:hover .item-del { opacity: 1; }

/* States */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
  font-size: 14px;
}
.loading-state {
  color: var(--text-3);
  font-size: 14px;
  padding: 1.5rem 0;
}
.error-banner {
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 1rem;
}
