/* ============================================
   Gia Đình Chi Tiêu - Mobile First Styles
   ============================================ */

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

:root {
  --primary: #059669;
  --primary-light: #34d399;
  --primary-dark: #047857;
  --secondary: #0ea5e9;
  --secondary-light: #38bdf8;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --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 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --nav-height: 64px;
  --header-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -2px rgba(0,0,0,0.2);
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

/* --- Page structure --- */
.page { display: none; height: 100%; }
.page.active { display: flex; flex-direction: column; }

/* --- Auth page --- */
#page-auth {
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  min-height: 100dvh;
  padding: 24px;
}
#page-auth.active { display: flex; }

.auth-container {
  width: 100%;
  max-width: 400px;
}
.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}
.auth-icon {
  font-size: 64px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-img {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.auth-logo h1 {
  color: white;
  font-size: 24px;
  font-weight: 700;
}
.auth-subtitle {
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  margin-top: 4px;
}

.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.auth-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
}

.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.auth-toggle a {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

/* --- Header --- */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
#page-title {
  font-size: 17px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn:active { transform: scale(0.95); }

/* --- Bottom Navigation --- */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
}
.nav-item.active {
  color: var(--primary);
}
.nav-item.active .nav-icon {
  transform: scale(1.1);
}
.nav-icon {
  font-size: 22px;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}
.nav-icon svg {
  width: 24px;
  height: 24px;
}
.nav-label {
  line-height: 1;
}

/* --- Main Content --- */
#app-content {
  flex: 1;
  padding: calc(var(--header-height) + 12px) 12px calc(var(--nav-height) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Cards --- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- Dashboard --- */
.today-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  padding: 24px 20px;
  position: relative;
  overflow: hidden;
}
.today-card::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -30%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}
.today-amount {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
  position: relative;
}
.today-label {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 4px;
  position: relative;
}
.today-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.15);
  position: relative;
}
.today-meta-item {
  text-align: center;
  flex: 1;
}
.today-meta-value {
  font-size: 16px;
  font-weight: 700;
}
.today-meta-label {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 2px;
}

/* Summary card (transactions page) */
.summary-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.summary-item {
  text-align: center;
  flex: 1;
}
.summary-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}
.summary-label {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 2px;
}
.summary-warn {
  color: #fbbf24 !important;
}

/* Deficit card (separate từ summary gradient) */
.deficit-card {
  background: #fef2f2 !important;
  border: 1px solid #fecaca !important;
  color: #dc2626;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 14px 16px !important;
}
.deficit-card strong {
  font-weight: 700;
}

/* Cycle progress */
.cycle-progress {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cycle-progress-ring {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}
.cycle-progress-info {
  flex: 1;
}
.cycle-progress-label {
  font-size: 12px;
  color: var(--text-muted);
}
.cycle-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.cycle-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Category budget bars */
.category-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.category-item:last-child { border-bottom: none; padding-bottom: 0; }
.category-item:first-child { padding-top: 0; }

.category-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.category-info { flex: 1; min-width: 0; }
.category-name {
  font-size: 14px;
  font-weight: 500;
}
.category-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.category-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.category-amount {
  text-align: right;
  flex-shrink: 0;
}
.category-spent {
  font-size: 14px;
  font-weight: 600;
}
.category-allocated {
  font-size: 11px;
  color: var(--text-muted);
}

/* --- Recent transactions list --- */
.txn-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.txn-item:last-child { border-bottom: none; }
.txn-cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.txn-info { flex: 1; min-width: 0; }
.txn-desc {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.txn-date {
  font-size: 11px;
  color: var(--text-muted);
}
.txn-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--danger);
  flex-shrink: 0;
}

/* --- Forms --- */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: all 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.form-input::placeholder { color: var(--text-muted); }
textarea.form-input { resize: vertical; min-height: 80px; }
select.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

/* Quick amount chips */
.quick-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.amt-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--bg);
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.amt-chip:active {
  transform: scale(0.95);
}
.amt-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Category chips */
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--bg);
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.cat-chip:active {
  transform: scale(0.95);
}
.cat-chip.active {
  background: color-mix(in srgb, var(--chip-c, var(--primary)) 20%, var(--card-bg));
  border-color: var(--chip-c, var(--primary));
  color: var(--chip-c, var(--primary));
  font-weight: 600;
}

/* FAB (Floating Action Button) */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(0.92); }
.fab:hover { background: var(--primary-dark); }

/* --- 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;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
  animation: slideUp 0.25s ease;
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.modal-actions .btn { flex: 1; }

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

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(20px); pointer-events: none; }
.toast.success { background: var(--secondary); }
.toast.error { background: var(--danger); }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 14px; }

/* --- Transactions page --- */
.txn-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.txn-filters::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* --- Categories page --- */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.cat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.cat-card:active { transform: scale(0.97); }
.cat-card-color {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
  font-size: 20px;
}
.cat-card-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.cat-card-pct {
  font-size: 12px;
  color: var(--text-muted);
}
.cat-card-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: 2px solid var(--card-bg);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.cat-card:hover .cat-card-delete,
.cat-card:active .cat-card-delete,
.cat-card-delete:focus { opacity: 1; }
@media (hover: none) {
  .cat-card-delete { opacity: 1; }
}

/* Range slider */
.range-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}
.form-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.15s;
}
.form-range::-webkit-slider-thumb:hover { transform: scale(1.15); }
.form-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.range-value {
  text-align: center;
  min-width: 110px;
  flex-shrink: 0;
}
.range-pct {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.range-money {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Color picker */
.color-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.color-swatch.active { border-color: var(--text); transform: scale(1.15); }

/* --- Reports --- */
.report-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
}
.report-tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
}
.report-tab.active {
  background: var(--primary);
  color: white;
}

/* Daily spend bars (report) */
.daily-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding: 8px 0;
}
.daily-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.daily-bar {
  width: 100%;
  max-width: 24px;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.5s ease;
  cursor: pointer;
}
.daily-bar-label {
  font-size: 8px;
  color: var(--text-muted);
  margin-top: 4px;
  writing-mode: vertical-lr;
  text-orientation: mixed;
}

/* Category donut - simple CSS */
.donut-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0;
}
.donut {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  position: relative;
}
.donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  border-radius: 50%;
  width: 100px;
  height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.donut-center-value {
  font-size: 20px;
  font-weight: 800;
}
.donut-center-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* --- Settings --- */
.settings-section {
  margin-bottom: 24px;
}
.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding: 0 4px;
}
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.settings-item:last-child { border-bottom: none; }
.settings-item-label { font-size: 14px; font-weight: 500; }
.settings-item-value { font-size: 14px; color: var(--text-secondary); }

/* Toggle switch */
.toggle {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.active { background: var(--primary); }
.toggle-knob {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}
.toggle.active .toggle-knob { transform: translateX(20px); }

/* --- Responsive --- */
@media (min-width: 768px) {
  #app-content {
    max-width: 600px;
    margin: 0 auto;
  }
  .cat-grid { grid-template-columns: 1fr 1fr 1fr; }
}

@media (min-width: 1024px) {
  #app-content {
    max-width: 640px;
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 2px; }

/* --- Utility --- */
#install-pwa-btn.hidden { display: none; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--secondary); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* --- Jar cards (category breakdown) --- */
.jar-card + .jar-card { margin-top: 12px; }
.jar-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.jar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.jar-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.jar-info {
  flex: 1;
  min-width: 0;
}
.jar-name {
  font-size: 14px;
  font-weight: 600;
}
.jar-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}
.jar-pct {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
}
.jar-pct-ex {
  color: var(--danger);
}
.jar-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.jar-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.jar-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}
.jar-stat {
  flex: 1;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.jar-stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.jar-stat-value {
  display: block;
  font-size: 15px;
  font-weight: 700;
}
.jar-stat-danger {
  color: var(--danger);
}
.jar-footer {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}
.jar-footer-item {
  display: flex;
  align-items: center;
  gap: 3px;
}
