:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --primary-text: #065f46;
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #10b981;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  max-width: 100%;
  overflow-x: clip;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-card);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.04);
  padding-bottom: env(safe-area-inset-bottom, 20px);
  transition: max-width 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-x: clip;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background-color: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
  line-height: 1;
}

.brand-titles h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--bg-app);
  color: var(--text-main);
}

/* Live Status Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-online {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}
.status-online .status-dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-connecting {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}
.status-connecting .status-dot {
  background: #f59e0b;
  animation: pulse 1.2s infinite;
}

.status-offline {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}
.status-offline .status-dot {
  background: #ef4444;
}

/* Changed on this phone, not yet confirmed by the server. */
.item-card.pending {
  border-style: dashed;
}
.item-card.pending .item-name::after {
  content: ' · not synced';
  white-space: nowrap;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-subtle);
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

/* User Menu */
.user-menu {
  position: relative;
}

.btn-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.user-dropdown {
  position: absolute;
  right: 0;
  top: 44px;
  width: 180px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 8px;
  z-index: 50;
}

.dropdown-header {
  padding: 6px 8px;
}
.dropdown-header .user-name {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
}
.dropdown-header .user-handle {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.dropdown-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}
.dropdown-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.dropdown-item:hover {
  background: var(--bg-app);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 16px 20px 40px;
}

/* Add Item Form */
.add-box-container {
  margin-bottom: 20px;
}

.add-item-form {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.autocomplete-wrapper {
  position: relative;
  flex: 1;
}

.input-main {
  width: 100%;
  height: 46px;
  padding: 0 16px;
  font-size: 0.95rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  transition: all 0.15s ease;
}

.input-main:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-add {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 46px;
  padding: 0 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-add:hover {
  background: var(--primary-dark);
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 30;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--primary-light);
}

.autocomplete-item-name {
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--text-main);
}

.autocomplete-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-badge {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-weight: 600;
  background: var(--bg-app);
  color: var(--text-muted);
}

/* Form Options Row */
.options-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-pill-select,
.option-pill-input {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px 8px;
  font-size: 0.8rem;
}

.pill-label {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}

.pill-select {
  border: none;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
  outline: none;
  padding: 4px 0;
  cursor: pointer;
}

.pill-input {
  border: none;
  background: transparent;
  font-size: 0.8rem;
  color: var(--text-main);
  outline: none;
  width: 70px;
  padding: 4px 0;
}

/* Store Filter Bar */
.filter-section {
  margin-bottom: 24px;
}

.filter-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.btn-manage-stores-header {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-manage-stores-header:hover {
  background: var(--bg-app);
  color: var(--text-main);
  border-color: var(--text-subtle);
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.store-filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.store-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.store-pill:hover {
  border-color: var(--text-subtle);
}

.store-pill.active {
  background: var(--text-main);
  color: white;
  border-color: var(--text-main);
}

.store-pill .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  background: var(--bg-app);
  color: var(--text-muted);
}

.store-pill.active .badge {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* Items Section */
.items-section {
  touch-action: pan-y;
}

.items-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.items-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.item-count-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Category Grouped List */
.category-group {
  margin-bottom: 20px;
}

.category-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  padding-left: 4px;
}

.item-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Grocery Item Card */
.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
  touch-action: pan-y;
}

.item-card:hover {
  border-color: var(--text-subtle);
  box-shadow: var(--shadow-sm);
}

.item-card.completed {
  opacity: 0.65;
  background: var(--bg-app);
  border-color: transparent;
}

.item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.item-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.item-checkbox:hover {
  border-color: var(--primary);
}

.item-checkbox:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

.item-checkbox:checked::before {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2.2px solid white;
  border-bottom: 2.2px solid white;
  transform: rotate(-45deg) translate(1px, -1px);
}

.item-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.item-title-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.item-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  word-break: break-word;
}

.item-card.completed .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-qty {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.item-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.badge-aisle {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.badge-store {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.badge-store-wrapper {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.badge-store-select {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-full);
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  outline: none;
  cursor: pointer;
  appearance: auto;
  -webkit-appearance: auto;
  transition: all 0.15s ease;
}

.badge-store-select:hover,
.badge-store-select:focus {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}

.badge-store-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.badge-store-link:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
  box-shadow: 0 1px 3px rgba(29, 78, 216, 0.12);
}

.item-product-link {
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  opacity: 0.75;
  transition: all 0.15s ease;
}

.item-product-link:hover {
  opacity: 1;
  color: var(--primary-dark);
  background: var(--primary-light);
  transform: translateY(-1px);
}

.badge-author {
  font-size: 0.68rem;
  color: var(--text-subtle);
}

.item-note-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.item-note {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #b45309;
  background: #fef3c7;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  word-break: break-word;
}

.item-note:hover {
  background: #fde68a;
  color: #92400e;
}

.item-card.completed .item-note {
  opacity: 0.55;
  background: var(--bg-app);
  color: var(--text-muted);
}

/* Inline Note Editor */
.inline-note-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
  box-sizing: border-box;
}

.inline-note-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  font-size: 0.82rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  outline: none;
  transition: all 0.15s ease;
}

.inline-note-input:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}

.inline-note-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-inline-save {
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-inline-save:hover {
  background: var(--primary-dark);
}

.btn-inline-cancel {
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-inline-cancel:hover {
  background: var(--bg-card);
  color: var(--text-main);
}

.btn-inline-clear {
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 500;
  color: #dc2626;
  background: transparent;
  border: none;
  cursor: pointer;
  margin-left: auto;
  transition: all 0.15s ease;
}

.btn-inline-clear:hover {
  text-decoration: underline;
}

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

.btn-note-item {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-note-item:hover {
  color: #b45309;
  background: #fef3c7;
}

.btn-delete-item {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-delete-item:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-emoji {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-state h3 {
  color: var(--text-main);
  font-size: 1.05rem;
  margin-bottom: 4px;
}

/* Completed Section */
.completed-section {
  margin-top: 30px;
  border-top: 1.5px dashed var(--border);
  padding-top: 16px;
}

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

.toggle-completed-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.chevron {
  transition: transform 0.2s ease;
}

.chevron.open {
  transform: rotate(180deg);
}

.btn-subtle {
  background: transparent;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.btn-subtle:hover {
  background: var(--bg-app);
}

.text-danger {
  color: var(--danger);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  text-align: center;
  margin-bottom: 20px;
}

.modal-icon {
  font-size: 36px;
  display: block;
  margin-bottom: 8px;
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.modal-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-group input {
  height: 44px;
  padding: 0 14px;
  font-size: 0.95rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-primary {
  height: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-block {
  width: 100%;
  margin-top: 6px;
}

.auth-error {
  padding: 10px;
  background: var(--danger-light);
  color: #991b1b;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.auth-toggle {
  text-align: center;
  margin-top: 18px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary-dark);
  font-weight: 600;
  cursor: pointer;
  margin-left: 4px;
}

/* User Management Modal Styles */
.admin-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}

.admin-user-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.admin-user-info {
  display: flex;
  flex-direction: column;
}

.admin-user-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-user-handle {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.badge-role {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-role-admin {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.badge-role-member {
  background: var(--bg-app);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-user-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-user-action:hover {
  background: var(--bg-app);
  border-color: var(--text-subtle);
}

.btn-user-delete {
  color: var(--danger);
  border-color: #fecaca;
}

.btn-user-delete:hover {
  background: #fef2f2;
  border-color: #f87171;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: white;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 110;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Store Admin Modal Styles */
.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  text-align: left;
}

.modal-medium {
  max-width: 460px;
}

.color-picker-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text-main);
  transform: scale(1.1);
}

.admin-stores-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

.admin-store-wrapper {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
  transition: transform 0.15s ease;
}

.admin-store-wrapper.dragging {
  opacity: 0.4;
}

.admin-store-wrapper.drag-over .admin-store-item {
  border-color: var(--primary);
  box-shadow: 0 -3px 0 var(--primary);
}

.admin-store-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.admin-store-item.dragging {
  opacity: 0.4;
  border-style: dashed;
  background: var(--bg-app);
}

.admin-store-item.drag-over {
  border-color: var(--primary);
  box-shadow: 0 -3px 0 var(--primary);
}

.admin-store-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.drag-handle {
  color: var(--text-subtle);
  cursor: grab;
  font-size: 1.1rem;
  padding: 0 4px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.drag-handle:active {
  cursor: grabbing;
}

.store-reorder-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.btn-arrow-reorder {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 1px 4px;
  font-size: 0.65rem;
  line-height: 1;
  border-radius: 3px;
}

.btn-arrow-reorder:hover:not(:disabled) {
  background: var(--bg-app);
  color: var(--text-main);
}

.btn-arrow-reorder:disabled {
  opacity: 0.2;
  cursor: default;
}

.btn-store-color-edit {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1.5px var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  padding: 0;
}

.btn-store-color-edit:hover {
  transform: scale(1.25);
  box-shadow: 0 0 0 2px var(--primary);
}

.store-color-tray {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  margin-bottom: 4px;
  animation: fadeIn 0.15s ease;
  width: 100%;
  flex-wrap: wrap;
}

.color-swatch-sm {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.color-swatch-sm:hover {
  transform: scale(1.25);
}

.admin-store-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.admin-store-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.admin-store-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-delete-store-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-delete-store-action:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* Inline Delete Confirmation Actions */
.delete-confirm-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.btn-confirm-delete-action {
  padding: 5px 10px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.btn-confirm-delete-action:hover {
  background: #dc2626;
}

.btn-cancel-action {
  padding: 5px 8px;
  background: var(--bg-app);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-cancel-action:hover {
  background: var(--border);
  color: var(--text-main);
}

.btn-add-store-pill {
  border-style: dashed !important;
  color: var(--primary-dark) !important;
  background: var(--primary-light) !important;
  border-color: #a7f3d0 !important;
}

.btn-add-store-pill:hover {
  background: #a7f3d0 !important;
}

/* Security & Account Settings Tabs */
.security-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-app);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.security-tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.security-tab-btn:hover {
  color: var(--text-main);
}

.security-tab-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.security-tab-content {
  animation: fadeIn 0.15s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Responsive Dynamic Resize Rules
   ========================================================================== */

/* Tablets & Small Laptops (min-width: 768px) */
@media (min-width: 768px) {
  .app-container {
    max-width: 820px;
  }

  .options-row {
    flex-wrap: nowrap;
  }
}

/* Desktops (min-width: 1024px) */
@media (min-width: 1024px) {
  .app-container {
    max-width: 1160px;
  }

  .category-grouped-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 20px;
    align-items: start;
  }

  .category-group {
    break-inside: avoid;
    margin-bottom: 0;
  }

  .add-item-form {
    padding: 16px;
  }
}

/* Wide Desktops / Large Displays (min-width: 1440px) */
@media (min-width: 1440px) {
  .app-container {
    max-width: 1380px;
  }

  .category-grouped-list {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 24px;
  }
}

/* Mobile Screens (max-width: 767px) */
@media (max-width: 767px) {
  html:has(.main-content),
  body:has(.main-content),
  html.is-grocery-list,
  body.is-grocery-list {
    height: 100%;
    overflow: hidden;
  }

  .app-container:has(.main-content),
  .app-container-list {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }

  .app-container:has(.main-content) .app-header,
  .app-container-list .app-header {
    flex-shrink: 0;
    padding: 10px 14px;
  }

  .main-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px 12px 6px;
  }

  .add-box-container {
    flex-shrink: 0;
    margin-bottom: 8px;
  }

  .add-item-form {
    padding: 10px 12px;
  }

  .input-row {
    flex-direction: row;
    gap: 8px;
  }

  .input-main {
    height: 40px;
    font-size: 0.88rem;
  }

  .btn-add {
    width: auto;
    height: 40px;
    padding: 0 16px;
    flex-shrink: 0;
  }

  .options-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
  }

  .option-pill-select,
  .option-pill-input {
    width: 100%;
    max-width: none !important;
    padding: 3px 8px;
    box-sizing: border-box;
  }

  .pill-select,
  .pill-input {
    flex: 1;
    width: 100%;
    font-size: 0.78rem;
  }

  .filter-section {
    flex-shrink: 0;
    margin-bottom: 8px;
  }

  .filter-header-row {
    margin-bottom: 4px;
  }

  .items-section {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-right: 2px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }

  .items-header {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 10;
    margin-bottom: 8px;
    padding-top: 4px;
  }

  .header-brand {
    gap: 8px;
    min-width: 0;
  }

  /* The name gives way first, so the buttons never get pushed off screen. */
  .brand-titles {
    min-width: 0;
  }

  .brand-titles h1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Room for what matters in the aisle: Price Check, sync status, account.
     Home and Meals stay a tap away in the account menu. */
  .header-actions {
    flex: none;
    gap: 6px;
  }

  .header-actions .btn-optional {
    display: none !important; /* beats the inline display:flex on the links */
  }

  .brand-icon {
    font-size: 22px;
  }

  .brand-tagline {
    display: none;
  }

  .status-text {
    display: none;
  }

  /* Small screens drop the label, except when it is news: no signal, or
     changes still waiting to go out. */
  .status-offline .status-text,
  .status-waiting .status-text {
    display: inline;
  }

  .status-pill {
    padding: 5px 7px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
  }

  .item-card {
    padding: 10px 12px;
  }
}

