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

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-card: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --success: #30d158;
  --danger: #ff453a;
  --border: #d2d2d7;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --tap-size: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e1e3a;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --border: #38383a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* === Typography === */
h1 { font-size: 28px; font-weight: 700; margin-bottom: 16px; }
h2 { font-size: 22px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.header-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 17px;
  cursor: pointer;
  padding: 8px 0;
  min-height: var(--tap-size);
  display: flex;
  align-items: center;
}

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

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--tap-size);
  transition: background 0.15s, opacity 0.15s;
}

.btn:active { opacity: 0.7; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 8px 12px;
}
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 36px; }

/* === Cards & Lists === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.store-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s;
}

.store-card:active { background: var(--bg-secondary); }

.store-card-info h3 { margin-bottom: 2px; }
.store-card-info .subtitle { color: var(--text-secondary); font-size: 13px; }
.store-card-arrow { color: var(--text-secondary); font-size: 20px; }

/* === Item Lists === */
.department-group { margin-bottom: 20px; }
.department-header {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 8px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.item-row {
  display: flex;
  align-items: center;
  padding: 12px 4px;
  min-height: var(--tap-size);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
  cursor: pointer;
  transition: background 0.1s;
}

.item-row:active { background: var(--bg-secondary); }

.item-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  margin-right: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

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

.item-row.checked .item-checkbox::after {
  content: '\2713';
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

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

.item-name { font-size: 17px; flex: 1; }

.item-dept-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* === Trip Selection (checkboxes for picking items) === */
.select-row {
  display: flex;
  align-items: center;
  padding: 12px 4px;
  min-height: var(--tap-size);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
  cursor: pointer;
}

.select-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  margin-right: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.select-row.selected .select-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.select-row.selected .select-checkbox::after {
  content: '\2713';
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

/* === Search/Filter === */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-bar input:focus { border-color: var(--accent); }

.search-bar::before {
  content: '\1F50D';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
}

/* === Progress Bar === */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 8px;
}

.progress-track {
  flex: 1;
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* === Section Toggle === */
.section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.section-toggle .arrow {
  transition: transform 0.2s;
  font-size: 12px;
}

.section-toggle.collapsed .arrow { transform: rotate(-90deg); }

/* === Forms === */
.input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 17px;
  outline: none;
}

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

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* === PIN Entry === */
.pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  text-align: center;
}

.pin-screen h1 { font-size: 36px; margin-bottom: 8px; }
.pin-screen .subtitle { color: var(--text-secondary); margin-bottom: 32px; }

.pin-input {
  font-size: 32px;
  text-align: center;
  letter-spacing: 8px;
  width: 200px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  -webkit-text-security: disc;
}

.pin-input:focus { border-color: var(--accent); }
.pin-error { color: var(--danger); font-size: 14px; margin-top: 12px; }

/* === Offline Banner === */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ff9500;
  color: #fff;
  text-align: center;
  padding: 4px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1000;
  display: none;
}

.offline-banner.show { display: block; }

/* === FAB === */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.fab:active { transform: scale(0.95); }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  padding: 24px 16px;
  max-height: 80dvh;
  overflow-y: auto;
}

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

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn { flex: 1; }

/* === Drag handle for departments === */
.drag-handle {
  cursor: grab;
  padding: 8px;
  color: var(--text-secondary);
  font-size: 18px;
}

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

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

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

/* === Animations === */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.fade-in { animation: fadeIn 0.2s ease; }
.slide-up { animation: slideUp 0.25s ease; }
