/* =============================
   CSS Custom Properties
   ============================= */
:root {
  --color-primary:       #1565c0;
  --color-primary-light: #1e88e5;
  --color-primary-pale:  #e3f2fd;
  --color-bg:            #f0f4f8;
  --color-surface:       #ffffff;
  --color-text:          #212121;
  --color-text-muted:    #757575;
  --color-purchased:     #9e9e9e;
  --color-border:        #e0e0e0;
  --color-danger:        #ef5350;
  --color-danger-hover:  #c62828;
  --color-drag-over:     #e3f2fd;
  --color-item-hover:    #fafafa;
  --color-danger-bg:     #fce4e4;
  --radius:              10px;
  --radius-sm:           6px;
  --shadow:              0 1px 4px rgba(0, 0, 0, 0.10);
  --shadow-sticky:       0 2px 8px rgba(0, 0, 0, 0.15);
}

/* =============================
   Dark Theme
   ============================= */
[data-theme="dark"] {
  --color-primary:       #90caf9;
  --color-primary-light: #bbdefb;
  --color-primary-pale:  #1a2a3a;
  --color-bg:            #121212;
  --color-surface:       #1e1e1e;
  --color-text:          #e0e0e0;
  --color-text-muted:    #9e9e9e;
  --color-purchased:     #616161;
  --color-border:        #2e2e2e;
  --color-danger:        #ef9a9a;
  --color-danger-hover:  #ef5350;
  --color-drag-over:     #1a2a3a;
  --color-item-hover:    #262626;
  --color-danger-bg:     #3e2020;
  --shadow:              0 1px 4px rgba(0, 0, 0, 0.40);
  --shadow-sticky:       0 2px 8px rgba(0, 0, 0, 0.55);
}

/* =============================
   Reset & Base
   ============================= */

/* Ensure the HTML `hidden` attribute always wins over any display rule */
[hidden] { display: none !important; }

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  border: none;
  background: none;
}

ul {
  list-style: none;
}

/* =============================
   App Shell
   ============================= */
#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =============================
   Header
   ============================= */
.app-header {
  background: var(--color-primary);
  color: #fff;
  padding: 16px 20px 12px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

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

#theme-toggle-btn,
#search-toggle-btn,
#lang-toggle-btn,
#share-btn {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1.2rem;
  color: #fff;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
}

#theme-toggle-btn:hover,
#search-toggle-btn:hover,
#lang-toggle-btn:hover,
#share-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

#search-toggle-btn.active {
  background: rgba(255, 255, 255, 0.35);
}

/* =============================
   Search Bar (in header)
   ============================= */
.search-bar {
  margin-top: 10px;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.95rem;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#search-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

#search-input:focus {
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.22);
}

.offline-banner {
  margin-top: 6px;
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  display: inline-block;
}

/* =============================
   Add Bar (sticky)
   ============================= */
.add-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  padding: 12px 16px;
  box-shadow: var(--shadow-sticky);
  display: flex;
  gap: 8px;
  align-items: center;
}

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

#item-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem; /* prevents iOS zoom */
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.15s;
}

#item-input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
}

#add-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.1s;
}

#add-btn:hover {
  background: var(--color-primary-light);
}

#add-btn:active {
  transform: scale(0.93);
}

/* =============================
   Browse Button (in add bar)
   ============================= */
.browse-btn {
  height: 46px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.browse-btn:hover,
.browse-btn.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-pale);
}

/* =============================
   Autocomplete Dropdown
   ============================= */
#autocomplete-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sticky);
  z-index: 100;
  overflow: hidden;
}

#autocomplete-list li {
  padding: 13px 14px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--color-border);
}

#autocomplete-list li:last-child {
  border-bottom: none;
}

#autocomplete-list li:hover,
#autocomplete-list li[aria-selected="true"] {
  background: var(--color-primary-pale);
  color: var(--color-primary);
}

/* =============================
   Loading State
   ============================= */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 60px 20px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============================
   Categories Container
   ============================= */
#categories-container {
  flex: 1;
  padding: 12px 12px 0;
}

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

.empty-state p:first-child {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.empty-state p:last-child {
  font-size: 0.9rem;
}

/* =============================
   Category Sections
   ============================= */
.category {
  background: var(--color-surface);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: opacity 0.15s, box-shadow 0.15s;
}

.category.dragging {
  opacity: 0.45;
  box-shadow: none;
}

.category.drag-over {
  outline: 2.5px dashed var(--color-primary);
  background: var(--color-drag-over);
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  background: var(--color-primary-pale);
  border-bottom: 1px solid var(--color-border);
  cursor: grab;
  user-select: none;
  touch-action: none; /* required for touch drag */
  -webkit-user-select: none;
}

.category-header:active {
  cursor: grabbing;
}

.drag-handle {
  color: var(--color-primary);
  font-size: 1.2rem;
  opacity: 0.7;
  flex-shrink: 0;
}

.category-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 1;
}

.item-count {
  font-size: 0.75rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: 12px;
  padding: 1px 8px;
  min-width: 24px;
  text-align: center;
}

/* =============================
   Item List
   ============================= */
.item-list {
  padding: 0;
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  min-height: 52px;
  transition: background 0.1s;
}

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

.item:hover {
  background: var(--color-item-hover);
}

/* =============================
   Check Button
   ============================= */
.check-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  background: transparent;
  color: var(--color-primary);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  min-width: 30px;
}

.check-btn:hover {
  background: var(--color-primary-pale);
}

.item.purchased .check-btn {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* =============================
   Item Name
   ============================= */
.item-name {
  flex: 1;
  font-size: 1rem;
  word-break: break-word;
  transition: color 0.2s, text-decoration 0.2s;
}

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

/* =============================
   Quantity Controls
   ============================= */
.qty-control {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  min-width: 26px;
  line-height: 1;
}

.qty-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-pale);
}

.qty-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.qty-num {
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 22px;
  text-align: center;
  color: var(--color-text);
}

.item.purchased .qty-num {
  color: var(--color-purchased);
}

/* =============================
   Delete Button
   ============================= */
.delete-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--color-text-muted);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  min-width: 32px;
}

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

/* =============================
   Undo Toast
   ============================= */
.undo-toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
  z-index: 200;
  font-size: 0.9rem;
  max-width: calc(100% - 32px);
  white-space: nowrap;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(16px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

#undo-btn {
  color: #90caf9;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.15s;
}

#undo-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* =============================
   Footer
   ============================= */
.app-footer {
  padding: 16px;
  text-align: center;
}

.footer-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.secondary-btn {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 8px 18px;
  transition: color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
}

.secondary-btn:hover,
.import-label:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

#clear-purchased-btn:hover {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* =============================
   Desktop Enhancements
   ============================= */
@media (min-width: 600px) {
  body {
    padding-top: 24px;
    padding-bottom: 24px;
  }

  #app {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    min-height: unset;
  }

  .app-header h1 {
    font-size: 1.6rem;
  }

  .undo-toast {
    bottom: 24px;
  }
}

/* =============================
   Quick Pick — Backdrop
   ============================= */
.qp-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 60;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* =============================
   Quick Pick — Bottom Sheet
   ============================= */
.quick-pick-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 600px);
  max-height: 65dvh;
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  z-index: 70;
  display: flex;
  flex-direction: column;
  animation: slideUpSheet 0.25s ease;
}

@keyframes slideUpSheet {
  from { transform: translateX(-50%) translateY(100%); }
  to   { transform: translateX(-50%) translateY(0);    }
}

/* Drag handle indicator */
.qp-drag-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.qp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 8px;
  flex-shrink: 0;
}

.qp-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.qp-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.3rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.qp-close-btn:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* =============================
   Quick Pick — Category Tabs
   ============================= */
.qp-tabs {
  display: flex;
  gap: 6px;
  padding: 0 16px 10px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  border-bottom: 1px solid var(--color-border);
}

.qp-tabs::-webkit-scrollbar { display: none; }

.qp-tab {
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1.5px solid var(--color-border);
  color: var(--color-text-muted);
  background: transparent;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.qp-tab:hover,
.qp-tab.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-pale);
}

/* =============================
   Quick Pick — Product Chips
   ============================= */
.qp-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 20px;
  overflow-y: auto;
  align-content: flex-start;
}

.qp-chip {
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.875rem;
  border: 1.5px solid var(--color-border);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}

.qp-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-pale);
}

.qp-chip:active {
  transform: scale(0.95);
}

/* Already on the list */
.qp-chip.in-list {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.qp-chip.in-list:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary-light);
}

/* =============================
   Shared List Banner
   ============================= */
.shared-banner {
  background: #00695c;
  color: #fff;
  text-align: center;
  padding: 8px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* =============================
   Share Panel Content
   ============================= */
.share-content {
  padding: 12px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.share-hint {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}

.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.share-url-input {
  flex: 1;
  padding: 9px 11px;
  font-size: 0.85rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  font-family: inherit;
  outline: none;
}

.share-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-danger {
  color: var(--color-danger) !important;
  border-color: var(--color-danger) !important;
}

.btn-danger:hover {
  background: var(--color-danger-bg) !important;
}
