/* MyLists — Design System & Styles */

/* === Design Tokens === */
:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-muted: #6b7280;
  --color-text-light: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-light: #f3f4f6;

  --color-primary: #4F46E5;
  --color-primary-light: #818CF8;
  --color-primary-bg: #EEF2FF;

  --color-success: #10B981;
  --color-danger: #EF4444;
  --color-danger-bg: #FEF2F2;
  --color-warning: #F59E0B;

  /* Type badge colors */
  --color-packing: #3B82F6;
  --color-packing-bg: #DBEAFE;
  --color-shopping: #10B981;
  --color-shopping-bg: #D1FAE5;
  --color-todo: #F59E0B;
  --color-todo-bg: #FEF3C7;
  --color-custom: #6B7280;
  --color-custom-bg: #F3F4F6;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 200ms ease;
}

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

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

body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
}

/* === Typography === */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover { background: #4338CA; }
.btn-primary:active { transform: scale(0.98); }

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover { background: #DC2626; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-border-light); }

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary-bg); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* === Type Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-packing { background: var(--color-packing-bg); color: var(--color-packing); }
.badge-shopping { background: var(--color-shopping-bg); color: var(--color-shopping); }
.badge-todo { background: var(--color-todo-bg); color: var(--color-todo); }
.badge-custom { background: var(--color-custom-bg); color: var(--color-custom); }

/* === Header === */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 16px;
}

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

.header-title {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}
.header-back:hover { background: var(--color-border-light); }

.header-actions {
  display: flex;
  gap: 4px;
}

.header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1.125rem;
  color: var(--color-text-muted);
  -webkit-tap-highlight-color: transparent;
}
.header-btn:hover { background: var(--color-border-light); }

/* === Progress Bar === */
.progress-bar {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-success);
  border-radius: 2px;
  transition: width 400ms ease;
}

.progress-text {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* === Dashboard === */
.dashboard {
  padding: 16px;
}

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

.type-section {
  margin-bottom: 24px;
}

.type-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.type-icon {
  font-size: 1.125rem;
}

/* === List Cards === */
.list-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--color-border-light);
  -webkit-tap-highlight-color: transparent;
}
.list-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--color-border);
}
.list-card:active { transform: scale(0.99); }

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

.list-card-name {
  flex: 1;
  font-weight: 600;
  font-size: 1rem;
}

.list-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.list-card-progress {
  display: flex;
  align-items: center;
  gap: 6px;
}

.list-card-progress-bar {
  width: 60px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.list-card-progress-fill {
  height: 100%;
  background: var(--color-success);
  border-radius: 2px;
}

/* === FAB === */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.5);
}
.fab:active { transform: scale(0.95); }

/* === List View === */
.list-view {
  padding-bottom: 80px; /* Space for quick-add bar */
}

/* === Category Section === */
.category-section {
  margin-bottom: 4px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--color-surface);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--color-border-light);
  -webkit-tap-highlight-color: transparent;
}

.category-chevron {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  transition: transform var(--transition);
  width: 16px;
}

.category-chevron.collapsed {
  transform: rotate(-90deg);
}

.category-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9375rem;
}

.category-count {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

.category-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  padding: 4px 8px;
  margin-left: 4px;
  opacity: 0.4;
  transition: opacity 150ms;
  -webkit-tap-highlight-color: transparent;
}

.category-delete-btn:hover,
.category-delete-btn:active {
  opacity: 1;
}

.category-items {
  overflow: hidden;
  transition: max-height 300ms ease;
}

.category-items.collapsed {
  max-height: 0 !important;
}

.category-actions {
  display: flex;
  justify-content: flex-end;
  padding: 4px 16px 8px;
  background: var(--color-surface);
}

.category-batch-btn {
  font-size: 0.75rem;
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-family: var(--font);
}
.category-batch-btn:hover { text-decoration: underline; }

/* === Item Row === */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  min-height: 48px;
  position: relative;
  overflow: hidden;
  transition: opacity 300ms ease, transform 300ms ease;
  -webkit-tap-highlight-color: transparent;
}

.item-row.checking-out {
  opacity: 0;
  transform: translateX(-20px);
}

.item-row.checking-in {
  animation: slideIn 300ms ease forwards;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.item-checkbox {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  background: transparent;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

/* Visual checkbox circle inside the tap target */
.item-checkbox::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  display: block;
  transition: all var(--transition);
  box-sizing: border-box;
}

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

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

.item-checkbox.checked::after {
  content: '✓';
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  position: absolute;
}

.item-name {
  flex: 1;
  font-size: 0.9375rem;
  word-break: break-word;
}

.item-name.checked {
  text-decoration: line-through;
  opacity: 0.5;
}

.item-category-label {
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.item-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--color-text-light);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.item-row:hover .item-delete,
.item-delete:focus {
  opacity: 1;
}

/* On touch devices, always show delete */
@media (hover: none) {
  .item-delete { opacity: 0.5; }
}

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

/* === Completed Section === */
.completed-section {
  margin-top: 8px;
  background: var(--color-border-light);
}

.completed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.completed-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.completed-clear-btn {
  font-size: 0.75rem;
  color: var(--color-danger);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-family: var(--font);
  font-weight: 500;
}
.completed-clear-btn:hover { text-decoration: underline; }

.completed-items {
  overflow: hidden;
  transition: max-height 300ms ease;
}

.completed-items.collapsed {
  max-height: 0 !important;
}

.completed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.completed-item-name {
  flex: 1;
  font-size: 0.875rem;
  text-decoration: line-through;
  opacity: 0.5;
}

.completed-item-cat {
  font-size: 0.75rem;
  color: var(--color-text-light);
}

/* === Quick Add Bar === */
.quick-add {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  display: flex;
  gap: 8px;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.quick-add-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.quick-add-row {
  display: flex;
  gap: 8px;
}

.quick-add-category-indicator {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}

.quick-add-category-indicator:hover {
  background: var(--color-border-light);
  color: var(--color-primary);
}

.quick-add-category-indicator span {
  font-weight: 600;
  color: var(--color-primary);
}

.quick-add input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  background: var(--color-bg);
}

.quick-add input:focus {
  border-color: var(--color-primary);
}

.quick-add button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--color-primary);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.quick-add button:active { transform: scale(0.95); }

/* === Modal / Dialog === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 200ms ease;
}

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

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp 200ms ease;
}

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

.modal h2 {
  margin-bottom: 16px;
}

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

/* === Form Elements === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus {
  border-color: var(--color-primary);
}

.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  background: var(--color-surface);
  cursor: pointer;
}

/* Type selector buttons */
.type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.type-option {
  padding: 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.type-option:hover { border-color: var(--color-primary); }

.type-option.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.type-option .type-emoji {
  display: block;
  font-size: 1.25rem;
  margin-bottom: 4px;
}

/* === Toast === */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  animation: toastIn 200ms ease, toastOut 200ms ease 1.8s forwards;
  box-shadow: var(--shadow-lg);
}

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

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

/* === Login === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 8px;
}

.login-card h1 {
  margin-bottom: 24px;
  color: var(--color-text);
}

.login-error {
  color: var(--color-danger);
  font-size: 0.875rem;
  margin-top: 8px;
  display: none;
}

.login-error.show {
  display: block;
}

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

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state p {
  margin-bottom: 16px;
  font-size: 0.9375rem;
}

/* === Settings === */
.settings-page {
  padding: 16px;
}

.settings-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.settings-section h3 {
  margin-bottom: 12px;
}

/* === Templates === */
.template-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--color-border-light);
  -webkit-tap-highlight-color: transparent;
}
.template-card:hover { box-shadow: var(--shadow); }

.template-editor {
  padding: 16px;
  padding-bottom: 80px;
}

.template-category {
  margin-bottom: 16px;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.template-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--color-border-light);
  font-weight: 600;
}

.template-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.9375rem;
}

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

/* === Overflow Menu === */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  border: 1px solid var(--color-border);
  overflow: hidden;
  z-index: 201;
  animation: menuIn 150ms ease;
}

@keyframes menuIn {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--color-text);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.menu-item:hover { background: var(--color-border-light); }
.menu-item.danger { color: var(--color-danger); }

.menu-divider {
  height: 1px;
  background: var(--color-border);
  margin: 4px 0;
}

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--color-text-muted);
}

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

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

/* === Utility === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* Mobile tweaks */
@media (max-width: 375px) {
  .modal { padding: 20px; }
  .type-selector { gap: 6px; }
}
