:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-active: #283548;
  --bg-input: #0b1120;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-emerald: #34d399;
  --accent-blue: #38bdf8;
  --accent-amber: #fbbf24;
  --accent-rose: #f87171;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #34d399;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

html, body {
  min-height: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
}

.app-wrapper {
  width: 100%;
  max-width: 500px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 1rem) 1.25rem env(safe-area-inset-bottom, 1.25rem);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.nav-back:hover, .nav-back:active {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.text-accent {
  color: var(--accent-emerald);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.94);
  color: var(--accent-emerald);
  background: rgba(255, 255, 255, 0.12);
}

.btn-install {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* Add Item Form */
.add-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.85rem;
  margin-bottom: 0.9rem;
  box-shadow: var(--shadow);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.item-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  color: var(--text-main);
  outline: none;
}

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

.item-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
  font-size: 0.9rem;
}

.btn-add {
  background: var(--accent-emerald);
  color: #0f172a;
  border: none;
  border-radius: var(--radius-md);
  width: 48px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-add:active {
  transform: scale(0.94);
}

.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.2rem;
}

.cat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.category-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 500;
  outline: none;
}

/* Quick Add Pills */
.quick-add-section {
  margin-bottom: 1rem;
}

.quick-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.quick-pills {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  scrollbar-width: none;
}

.quick-pills::-webkit-scrollbar {
  display: none;
}

.quick-pill {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 9999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-pill:active {
  transform: scale(0.94);
  background: rgba(52, 211, 153, 0.2);
  border-color: var(--accent-emerald);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.filter-tabs {
  display: flex;
  gap: 0.35rem;
}

.filter-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.filter-tab.active {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-subtle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem;
}

.btn-subtle:hover, .btn-subtle:active {
  color: var(--accent-rose);
}

/* Items List */
.list-container {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.shopping-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.item-card {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  transition: all 0.2s ease;
  user-select: none;
}

.item-card.completed {
  opacity: 0.55;
  background: rgba(30, 41, 59, 0.4);
}

.item-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  margin-right: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.item-card.completed .item-checkbox {
  background: var(--accent-emerald);
  border-color: var(--accent-emerald);
  color: #0f172a;
}

.item-info {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
}

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

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

.item-cat-badge {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-delete-item {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.2);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  transition: color 0.15s ease;
}

.btn-delete-item:active {
  color: var(--accent-rose);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  color: rgba(255, 255, 255, 0.15);
  margin-bottom: 1rem;
}

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

.empty-state p {
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Footer Actions */
.app-footer {
  margin-top: auto;
  padding-top: 0.8rem;
  display: flex;
  gap: 0.6rem;
}

.action-btn {
  flex: 1;
  padding: 0.8rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.15s ease;
  border: none;
}

.btn-share {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-share:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  color: var(--accent-rose);
  border: 1px solid rgba(239, 68, 68, 0.2);
  flex: 0 0 auto;
  padding: 0.8rem 1rem;
}

.btn-danger:active {
  background: rgba(239, 68, 68, 0.25);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #334155;
  color: #fff;
  border: 1px solid var(--accent-emerald);
  padding: 0.6rem 1.25rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* iOS Prompt Modal */
.ios-prompt {
  position: fixed;
  bottom: 1.5rem;
  left: 1.25rem;
  right: 1.25rem;
  max-width: 440px;
  margin: 0 auto;
  background: #1e293b;
  border: 1px solid var(--accent-emerald);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.ios-prompt-content {
  position: relative;
}

.ios-prompt h3 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-emerald);
}

.ios-prompt ol {
  padding-left: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.ios-prompt strong {
  color: var(--text-main);
}

.close-ios {
  position: absolute;
  top: -4px;
  right: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}

.hidden {
  display: none !important;
}
