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

:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --red: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ===== SCREENS ===== */
.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ===== AUTH ===== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
}

.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.auth-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.auth-title { font-size: 24px; font-weight: 700; text-align: center; color: var(--gray-900); }
.auth-subtitle { font-size: 14px; color: var(--gray-500); text-align: center; margin-bottom: 24px; }

.tab-row {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 20px;
}
.tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  transition: all .15s;
}
.tab.active {
  background: #fff;
  color: var(--gray-900);
  box-shadow: var(--shadow);
}

/* ===== INPUTS ===== */
.input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .15s;
  outline: none;
  margin-bottom: 12px;
}
.input:focus { border-color: var(--green); }
.input::placeholder { color: var(--gray-400); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); transform: scale(.97); }
.btn-ghost { background: transparent; color: var(--gray-500); border: 1.5px solid var(--gray-200); }
.btn-ghost:active { background: var(--gray-100); }
.btn-full { width: 100%; }

.icon-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:active { background: rgba(255,255,255,.2); }

.error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; text-align: center; }

/* ===== APP LAYOUT ===== */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* HEADER */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--green);
  color: #fff;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  padding-top: max(12px, env(safe-area-inset-top));
}
.header-title { font-size: 18px; font-weight: 700; }
.header-actions { display: flex; gap: 4px; }

/* STORE TABS */
.store-tabs-container {
  display: flex;
  align-items: center;
  background: #fff;
  border-bottom: 1.5px solid var(--gray-200);
  flex-shrink: 0;
  overflow: hidden;
}
.store-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.store-tabs::-webkit-scrollbar { display: none; }

.store-tab {
  padding: 12px 18px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  flex-shrink: 0;
}
.store-tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
  font-weight: 600;
}

.add-store-btn {
  padding: 0 14px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--gray-400);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 48px;
  transition: color .15s;
}
.add-store-btn:active { color: var(--green); }

/* ITEM LIST */
.item-list-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  color: var(--gray-400);
  text-align: center;
  gap: 12px;
}
.empty-icon { font-size: 48px; }
.empty-state p { font-size: 15px; line-height: 1.5; }

.item-list { list-style: none; padding: 0 12px; }

/* ITEM ROW */
.item-row {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: opacity .2s, transform .2s;
  touch-action: pan-y;
  position: relative;
}

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

.drag-handle {
  padding: 16px 6px 16px 14px;
  color: var(--gray-400);
  font-size: 18px;
  cursor: grab;
  flex-shrink: 0;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }

.item-checkbox-wrap {
  padding: 14px 10px 14px 4px;
  flex-shrink: 0;
}
.item-checkbox {
  width: 22px; height: 22px;
  border: 2px solid var(--gray-400);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
}
.item-checkbox.checked { background: var(--green); border-color: var(--green); }
.item-checkbox.checked::after { content: '✓'; color: #fff; font-size: 13px; font-weight: 700; }

.item-text {
  flex: 1;
  font-size: 16px;
  padding: 14px 0;
  line-height: 1.3;
  word-break: break-word;
  transition: all .15s;
}
.item-text.checked { text-decoration: line-through; color: var(--gray-400); }

.item-text-input {
  flex: 1;
  font-size: 16px;
  border: none;
  outline: none;
  padding: 14px 0;
  background: transparent;
  color: var(--gray-900);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}
.item-action-btn {
  width: 44px; height: 52px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--gray-400);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.item-action-btn:active { color: var(--gray-700); background: var(--gray-100); }
.item-action-btn.delete { color: var(--red); }
.item-action-btn.delete:active { color: #991b1b; }

/* Sortable ghost/drag states */
.sortable-ghost { opacity: 0.35; }
.sortable-drag { box-shadow: var(--shadow-lg) !important; transform: scale(1.02); }

/* ADD BAR */
.add-bar {
  background: #fff;
  border-top: 1.5px solid var(--gray-200);
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.add-form { display: flex; gap: 8px; }
.add-input { margin-bottom: 0; flex: 1; }
.add-btn { flex-shrink: 0; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 0;
}
.modal {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 75dvh;
  overflow-y: auto;
  animation: slideUp .2s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

.move-store-list, .manage-store-list { display: flex; flex-direction: column; gap: 8px; }

.move-store-btn {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  color: var(--gray-900);
}
.move-store-btn:active { background: var(--green-light); border-color: var(--green); }

.manage-store-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: #fff;
}
.manage-store-name {
  flex: 1;
  font-size: 15px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--gray-900);
}
.manage-store-rename {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity .15s;
}
.manage-store-rename:active { opacity: 1; }

.manage-store-delete {
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px 6px;
  flex-shrink: 0;
  transition: color .15s;
}
.manage-store-delete:active { color: var(--red); }

.manage-store-name[readonly] { cursor: default; color: var(--gray-700); }
.manage-store-name:not([readonly]) { background: #f0fdf4; border-color: var(--green); cursor: text; }

/* ===== SESSION BANNER ===== */
#session-banner { flex-shrink: 0; }

.session-start-banner {
  padding: 8px 12px;
  background: var(--gray-50);
  border-bottom: 1.5px solid var(--gray-200);
  display: flex;
  justify-content: center;
}
.btn-start-session {
  background: transparent;
  border: 1.5px dashed var(--green);
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  transition: all .15s;
}
.btn-start-session:active { background: var(--green-light); }

.session-active-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #fefce8;
  border-bottom: 1.5px solid #fde047;
  gap: 10px;
}
.session-active-banner span {
  font-size: 13px;
  font-weight: 500;
  color: #854d0e;
}
.btn-end-session {
  background: #16a34a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-end-session:active { background: var(--green-dark); }

/* ===== NO-SESSION TOAST ===== */
.no-session-toast {
  position: fixed;
  bottom: 80px;
  left: 12px;
  right: 12px;
  background: #1c1917;
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  animation: slideUpToast .2s ease-out;
}
@keyframes slideUpToast {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.no-session-toast button {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.no-session-toast button:active { background: var(--green-dark); }

/* ===== LIST TOOLBAR ===== */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 12px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.btn-smart-reorder {
  font-size: 12px;
  font-weight: 600;
  color: #4b5563;
  background: transparent;
  border: 1.5px solid #d1d5db;
  border-radius: 99px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all .15s;
}
.btn-smart-reorder:active { background: #f3f4f6; }

/* ===== SUGGESTIONS ===== */
#suggestions-container {
  background: #eff6ff;
  border-bottom: 1.5px solid #bfdbfe;
  padding: 10px 12px;
  flex-shrink: 0;
  max-height: 30dvh;
  overflow-y: auto;
}
.suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.suggestions-toggle {
  font-size: 13px;
  font-weight: 600;
  color: #1d4ed8;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}
.suggestions-header-actions {
  display: flex;
  gap: 6px;
}
.btn-add-all-suggestions {
  font-size: 12px;
  font-weight: 600;
  color: #1d4ed8;
  background: transparent;
  border: 1.5px solid #93c5fd;
  border-radius: 99px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all .15s;
}
.btn-add-all-suggestions:active { background: #dbeafe; }

.suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.suggestion-chip {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1.5px solid #bfdbfe;
  border-radius: 99px;
  overflow: hidden;
  transition: border-color .15s;
}
.suggestion-chip:hover { border-color: #3b82f6; }
.suggestion-add {
  display: flex;
  flex-direction: column;
  padding: 5px 10px 5px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  gap: 1px;
}
.suggestion-name { font-size: 13px; font-weight: 500; color: var(--gray-900); }
.suggestion-meta { font-size: 10px; color: #3b82f6; }
.suggestion-dismiss {
  padding: 5px 10px;
  background: transparent;
  border: none;
  border-left: 1px solid #bfdbfe;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 11px;
  transition: all .15s;
}
.suggestion-dismiss:active { background: #fee2e2; color: var(--red); }

/* ===== NO STORE STATE ===== */
.no-store-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  color: var(--gray-400);
  text-align: center;
  gap: 12px;
  padding: 24px;
}
.no-store-state .empty-icon { font-size: 48px; }
.no-store-state p { font-size: 15px; line-height: 1.5; }
