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

:root {
  --accent:        #2d6a4f;
  --accent-hover:  #245a42;
  --accent-light:  #eaf4ee;
  --accent-dim:    #6aab86;
  --text:          #111827;
  --text-muted:    #6b7280;
  --bg:            #ffffff;
  --surface:       #f9fafb;
  --border:        #e5e7eb;
  --danger:        #dc2626;
  --danger-hover:  #b91c1c;
  --done-text:     #9ca3af;
  --done-bg:       #f3f4f6;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 4px rgba(0,0,0,.08);
  --shadow-lg:     0 4px 20px rgba(0,0,0,.14);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
}

input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,106,79,.12);
}

/* ── Shared components ───────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* Modal overlay */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h2 {
  font-size: 18px;
  margin-bottom: 20px;
}

.form-field {
  margin-bottom: 14px;
}
.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-field input,
.form-field select {
  width: 100%;
}

.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-field { flex: 1; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  z-index: 200;
  animation: fadeInUp .2s ease, fadeOut .3s ease 2.5s forwards;
  pointer-events: none;
  white-space: nowrap;
}
@keyframes fadeInUp  { from { opacity:0; transform: translateX(-50%) translateY(8px) } }
@keyframes fadeOut   { to   { opacity:0 } }

/* ── List view ───────────────────────────────────────────────────────────── */

body.list-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.list-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 0;
  flex-shrink: 0;
}

.list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.list-header-top h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.header-link {
  font-size: 13px;
  color: var(--text-muted);
}

.store-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 1px;
  scrollbar-width: none;
}
.store-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.list-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.list-main {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 80px;
}

.section-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 16px 4px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
  transition: background .1s;
}
.list-item:hover { background: var(--surface); }
.list-item.completed { background: var(--done-bg); }

.check-btn {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color .15s, background .15s, color .15s;
}
.check-btn:hover { border-color: var(--accent); color: var(--accent); }
.list-item.completed .check-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.item-name {
  font-size: 16px;
}
.list-item.completed .item-name {
  text-decoration: line-through;
  color: var(--done-text);
}

.item-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  min-width: 0;
}
.item-body:hover .item-name { text-decoration: underline; text-decoration-color: var(--border); }

.item-notes {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item.completed .item-notes { color: var(--done-text); }

.store-badge {
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}

.aisle-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.delete-item-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: 50%;
  opacity: 0;
  transition: opacity .15s, color .15s;
  font-size: 16px;
}
.list-item:hover .delete-item-btn { opacity: 1; }
.delete-item-btn:hover { color: var(--danger); }

.list-empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

.list-bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 12px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
}

.add-item-btn {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
}
.add-item-btn:hover { background: var(--accent-hover); }

.complete-trip-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}
.complete-trip-btn:hover { background: var(--border); }

/* ── Catalog view ────────────────────────────────────────────────────────── */

body.catalog-view {
  min-height: 100vh;
}

.catalog-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.catalog-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.catalog-header nav {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 14px;
}

.catalog-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.catalog-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.catalog-toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
}

/* Staples table */
.staples-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.staples-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.staples-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.staples-table tbody tr:hover { background: var(--surface); }

.staple-name {
  font-weight: 500;
}
.staple-notes {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.store-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.store-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 99px;
}
.store-chip.preferred::before {
  content: '★';
  font-size: 10px;
}
.store-chip-detail {
  color: var(--accent-dim);
  font-weight: 400;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.no-staples {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
}

/* Staple edit modal — store assignment list */
.store-assignment-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 14px;
}
.store-assignment-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.store-assignment-item:last-child { border-bottom: none; }
.assignment-store   { font-weight: 500; min-width: 90px; }
.assignment-detail  { flex: 1; color: var(--text-muted); font-size: 13px; }
.assignment-preferred { color: var(--accent); font-size: 13px; font-weight: 500; }

.add-store-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 14px;
}
.add-store-form h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-top: 8px;
}
.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  accent-color: var(--accent);
  padding: 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .catalog-main { padding: 16px 16px 48px; }
  .catalog-header { padding: 12px 16px; }
  .staples-table th:nth-child(2),
  .staples-table td:nth-child(2) { display: none; }
}
