/* ─── Design Tokens from DESIGN.md ─── */
:root {
  --surface: #f8f9ff;
  --surface-dim: #cbdbf5;
  --surface-bright: #f8f9ff;
  --surface-container-lowest: #ffffff;
  --surface-container-low: #eff4ff;
  --surface-container: #e5eeff;
  --surface-container-high: #dce9ff;
  --surface-container-highest: #d3e4fe;
  --on-surface: #0b1c30;
  --on-surface-variant: #4d4354;
  --inverse-surface: #213145;
  --inverse-on-surface: #eaf1ff;
  --outline: #7e7386;
  --outline-variant: #cfc2d7;
  --surface-tint: #861fdd;
  --primary: #7800ce;
  --on-primary: #ffffff;
  --primary-container: #9333ea;
  --on-primary-container: #f6e6ff;
  --inverse-primary: #ddb8ff;
  --secondary: #0058be;
  --on-secondary: #ffffff;
  --secondary-container: #2170e4;
  --on-secondary-container: #fefcff;
  --tertiary: #784700;
  --on-tertiary: #ffffff;
  --tertiary-container: #9a5c00;
  --on-tertiary-container: #ffe8d4;
  --error: #ba1a1a;
  --on-error: #ffffff;
  --error-container: #ffdad6;
  --on-error-container: #93000a;
  --primary-fixed: #f0dbff;
  --primary-fixed-dim: #ddb8ff;
  --on-primary-fixed: #2c0051;
  --on-primary-fixed-variant: #6800b4;
  --secondary-fixed: #d8e2ff;
  --secondary-fixed-dim: #adc6ff;
  --on-secondary-fixed: #001a42;
  --on-secondary-fixed-variant: #004395;
  --tertiary-fixed: #ffdcbc;
  --tertiary-fixed-dim: #ffb86b;
  --on-tertiary-fixed: #2c1700;
  --on-tertiary-fixed-variant: #683d00;
  --background: #f8f9ff;
  --on-background: #0b1c30;
  --success: #22c55e;
  --container-padding: 16px;
  --gutter: 12px;
  --item-gap: 8px;
  --section-margin: 24px;
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-sm: 0.25rem;
  --radius: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font-family);
  background: var(--background);
  color: var(--on-background);
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

/* ─── App Shell ─── */
.app-shell {
  width: 100%; max-width: 672px; background: var(--surface);
  display: flex; flex-direction: column; position: relative;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

/* ─── Top Bar ─── */
.topbar {
  flex-shrink: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 var(--container-padding); height: 56px;
  background: var(--surface-container-low);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-container-high);
}
.topbar-btn {
  background: none; border: none; color: var(--primary); cursor: pointer;
  padding: 8px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.topbar-btn:active { background: var(--surface-container-high); }
.topbar-title { font-size: 18px; font-weight: 700; line-height: 24px; color: var(--on-surface); }

/* ─── Main Content ─── */
.main-content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px var(--container-padding);
  display: flex; flex-direction: column; gap: 12px;
}

/* ─── Search ─── */
.search-wrapper { position: relative; width: 100%; }
.search-wrapper .material-symbols-outlined {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--outline); font-size: 20px; pointer-events: none;
}
.search-input {
  width: 100%; background: var(--surface-container-lowest);
  border: 1px solid var(--outline-variant); border-radius: var(--radius-xl);
  padding: 10px 10px 10px 38px;
  font-family: var(--font-family); font-size: 16px; color: var(--on-surface);
  outline: none; transition: border 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(120,0,206,0.15); }
.search-input::placeholder { color: var(--outline); }

/* ─── Dropdown ─── */
.search-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--surface-container-lowest);
  border: 1px solid var(--outline-variant); border-radius: var(--radius-lg);
  box-shadow: 0 10px 25px rgba(0,0,0,0.12); z-index: 40;
  max-height: 240px; overflow-y: auto; overflow-x: hidden; display: none;
}
.search-dropdown.active { display: block; }

.dropdown-item {
  position: relative;
  display: flex; align-items: center;
  padding: 0 40px 0 40px; cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--surface-container);
  min-height: 44px;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover, .dropdown-item:active { background: var(--surface-container-low); }

.dropdown-item-text {
  font-size: 14px; font-weight: 500; color: var(--on-surface);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 10px 8px;
  flex: 1; min-width: 0;
}
.dropdown-item-icon {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 40px;
  font-size: 18px; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.dropdown-item-delete {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 40px;
  background: none; border: none; color: var(--error);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; opacity: 0.5; transition: opacity 0.2s;
  padding: 0;
}
.dropdown-item-delete:hover { opacity: 1; }

/* ─── Sections ─── */
.section { display: flex; flex-direction: column; gap: var(--item-gap); }
.section-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.section-title { font-size: 16px; font-weight: 600; line-height: 22px; color: var(--on-surface); }
.section-badge {
  background: var(--primary-container); color: var(--on-primary-container);
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
  padding: 1px 7px; border-radius: var(--radius-full);
}
.section.comprados { opacity: 0.6; }
.section.comprados .section-title { color: var(--on-surface-variant); }
.section.comprados .section-badge { background: var(--surface-container-high); color: var(--on-surface-variant); }

/* ─── Empty State ─── */
.empty-state { padding: 8px 0; color: var(--outline); font-size: 13px; text-align: left; }

/* ─── Item Card ─── */
.item-card {
  background: var(--surface-container-lowest);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  border: 1px solid var(--surface-container);
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.3s ease;
  animation: slideIn 0.25s ease;
}
.item-card.purchased {
  opacity: 0.5;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes checkBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

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

.checkbox {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--outline-variant); background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s; padding: 0;
}
.checkbox:hover { border-color: var(--primary); }
.checkbox.checked {
  background: var(--success); border-color: var(--success);
  animation: checkBounce 0.3s ease;
}
.checkbox.checked::after {
  content: ''; display: block; width: 5px; height: 9px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin-top: -1px;
}

.item-info { display: flex; flex-direction: column; min-width: 0; }
.item-name {
  font-size: 15px; font-weight: 600; color: var(--on-surface);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-card.purchased .item-name { text-decoration: line-through; color: var(--on-surface-variant); }
.item-note { font-size: 13px; color: var(--outline); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.qty-controls {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-container-low); border-radius: var(--radius); padding: 2px;
}
.qty-btn {
  width: 26px; height: 26px; border: none; background: transparent;
  border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--on-surface-variant); font-size: 18px; font-weight: 500;
  transition: background 0.15s; padding: 0; line-height: 1;
}
.qty-btn:hover, .qty-btn:active { background: var(--surface-container-high); }
.qty-value { font-size: 13px; font-weight: 500; width: 18px; text-align: center; color: var(--on-surface); }

.note-btn {
  height: 26px; border: none; background: transparent;
  border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  color: var(--outline); font-size: 12px; font-weight: 700;
  transition: background 0.15s;
  margin-right: 4px; padding: 0 8px; white-space: nowrap;
}
.note-btn:hover, .note-btn:active { background: var(--surface-container-high); }
.note-btn.has-note {
  background: var(--primary-container); color: var(--on-primary-container);
  position: relative;
}
.note-btn.has-note::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: var(--radius);
  border: 2px solid var(--primary-container);
  animation: noteGlow 2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes noteGlow {
  0%, 100% { opacity: 0; transform: scale(1); border-color: var(--primary-container); }
      50%      { opacity: 0.5; transform: scale(1.06); border-color: var(--primary); }
}
.note-btn.peeling {
  animation: peelOpen 0.4s ease-out;
}
@keyframes peelOpen {
  0%   { transform: scale(1) rotate(0deg); }
  30%  { transform: scale(1.15) rotate(-5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ─── Bottom Nav ─── */
.bottom-nav {
  flex-shrink: 0; z-index: 50;
  display: flex; justify-content: space-evenly;
  padding: 2px var(--container-padding);
  padding-bottom: max(2px, env(safe-area-inset-bottom, 2px));
  background: var(--surface-container-lowest);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
  border-top: 1px solid var(--surface-container);
}
.tab-btn {
  display: flex; flex-direction: row; align-items: center; justify-content: center;
  gap: 6px; padding: 0 22px; border: none; border-radius: var(--radius-full);
  cursor: pointer; font-family: var(--font-family); font-size: 12px; font-weight: 700;
  letter-spacing: 0.05em; color: var(--on-surface-variant);
  background: transparent; transition: all 0.25s ease; height: 52px;
}
.tab-btn:active { transform: scale(0.95); }
.tab-btn .material-symbols-outlined { font-size: 20px; }
.tab-btn.active {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: var(--on-primary);
  box-shadow: 0 4px 12px rgba(120,0,206,0.3);
  animation: tabPop 0.3s ease;
}
@keyframes tabPop {
  0% { transform: scale(0.9); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ─── Action Button ─── */
.action-container { display: flex; justify-content: center; padding: 8px 0; }
.clear-btn {
  padding: 6px 20px; border-radius: var(--radius-full);
  border: 1px solid var(--error); color: var(--error);
  background: var(--error-container); font-family: var(--font-family);
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 6px; transition: background 0.2s;
}
.clear-btn:hover, .clear-btn:active { background: var(--error); color: var(--on-error); }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11,28,48,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--surface-container-lowest); border-radius: var(--radius-xl);
  box-shadow: 0 25px 50px rgba(0,0,0,0.2);
  width: 100%; max-width: 400px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  animation: slideUp 0.25s ease;
}
.modal-title { font-size: 17px; font-weight: 600; color: var(--on-surface); }
.modal-note-readonly {
  min-height: 70px; padding: 12px;
  background: var(--surface-container-low); border-radius: var(--radius);
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
}
.modal-input {
  width: 100%; background: var(--surface-container-low);
  border: 1px solid var(--outline-variant); border-radius: var(--radius);
  padding: 10px; font-family: var(--font-family); font-size: 16px;
  color: var(--on-surface); outline: none; resize: vertical; min-height: 70px;
}
.modal-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(120,0,206,0.15); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btn {
  padding: 8px 18px; border-radius: var(--radius-full); border: none;
  font-family: var(--font-family); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.modal-btn:active { transform: scale(0.96); }
.modal-btn.primary {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: var(--on-primary);
}
.modal-btn.secondary { background: var(--surface-container-high); color: var(--on-surface-variant); }

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 110; background: var(--inverse-surface); color: var(--inverse-on-surface);
  padding: 10px 18px; border-radius: var(--radius-xl);
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.show { opacity: 1; pointer-events: auto; }

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { 100% { transform: rotate(360deg); } }
.animate-spin { animation: spin 0.8s linear infinite; }

/* ─── Material Symbols ─── */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined'; font-weight: normal; font-style: normal;
  font-size: 24px; line-height: 1; letter-spacing: normal; text-transform: none;
  display: inline-block; white-space: nowrap; direction: ltr;
  -webkit-font-smoothing: antialiased; font-variation-settings: 'FILL' 0;
}
.material-symbols-outlined.filled { font-variation-settings: 'FILL' 1; }

/* ─── Drag & Drop ─── */
.item-card.dragging {
  opacity: 0.4;
  transform: scale(0.98);
  box-shadow: none;
}
.item-card.drag-over {
  border: 2px dashed var(--primary);
  box-shadow: 0 4px 16px rgba(120,0,206,0.2);
  transform: scale(1.02);
}
.item-card[draggable="true"] {
  cursor: grab;
}
.item-card[draggable="true"]:active {
  cursor: grabbing;
}
.drag-handle {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex-shrink: 0;
  color: var(--outline-variant); font-size: 16px;
  cursor: grab; margin-right: 2px;
  -webkit-touch-callout: none;
  user-select: none;
}

/* ─── Confetti ─── */
.confetti-container {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 200; overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 2px;
  animation: confettiFall 1.2s ease-out forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg) scale(0.3); opacity: 0; }
}

/* ─── Desktop ─── */
@media (min-width: 672px) { .app-shell { border-radius: 0; } }
