/* =============================================
   ThuChi – App CSS
   Dark mode, Midnight Indigo, mobile-first, premium
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* =============================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ============================================= */
:root {
  /* ── Backgrounds ───────────────────────────────── */
  --bg-primary:    #09090f;   /* near-black, faint violet tint      */
  --bg-surface:    #13131c;   /* card / surface                     */
  --bg-elevated:   #1c1c29;   /* elevated, hover, pill              */
  --bg-input:      #0f0f18;   /* input fields                       */

  /* ── Accent – Indigo / Violet ──────────────────── */
  --accent:        #818cf8;   /* indigo-400  – primary accent       */
  --accent-dim:    #6366f1;   /* indigo-500  – slightly deeper      */
  --accent-dark:   #4f46e5;   /* indigo-600  – button gradients     */
  --accent-glow:   rgba(129, 140, 248, 0.14);
  --accent-glow2:  rgba(129, 140, 248, 0.07);

  /* ── Text ──────────────────────────────────────── */
  --text-primary:  #f1f5f9;   /* slate-100  */
  --text-secondary:#cbd5e1;   /* slate-300  */
  --text-muted:    #94a3b8;   /* slate-400  */
  --text-faint:    #64748b;   /* slate-500  */
  --text-disabled: #3f4557;   /* muted placeholder / labels */

  /* ── Borders ───────────────────────────────────── */
  --border:        #2a2a3d;
  --border-subtle: #1c1c2b;
  --border-focus:  #818cf8;

  /* ── Semantic ──────────────────────────────────── */
  --danger:        #f87171;
  --danger-bg:     rgba(248, 113, 113, 0.11);
  --danger-border: rgba(248, 113, 113, 0.28);

  --warning:       #fbbf24;
  --warning-bg:    rgba(251, 191, 36, 0.10);

  --success:       #34d399;
  --success-bg:    rgba(52, 211, 153, 0.11);

  --info:          #60a5fa;
  --info-bg:       rgba(96, 165, 250, 0.10);

  /* ── Typography ────────────────────────────────── */
  --font:          'Inter', system-ui, -apple-system, sans-serif;
  --fs-xs:         11px;
  --fs-sm:         13px;
  --fs-base:       15px;
  --fs-md:         16px;
  --fs-lg:         18px;
  --fs-xl:         22px;
  --fs-2xl:        28px;
  --fs-3xl:        36px;

  /* ── Spacing ────────────────────────────────────── */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;

  /* ── Border Radius ──────────────────────────────── */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-full: 9999px;

  /* ── Shadows ────────────────────────────────────── */
  --shadow-sm:     0 1px 4px rgba(0,0,0,0.35);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:     0 8px 40px rgba(0,0,0,0.6);
  --shadow-accent: 0 0 24px rgba(129,140,248,0.22);

  /* ── Layout ─────────────────────────────────────── */
  --nav-height:    64px;
  --header-height: 56px;
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
}

/* =============================================
   RESET & BASE
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

/* =============================================
   APP SHELL
   ============================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-primary);
}

/* Header */
#app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-md);
  background: rgba(9, 9, 15, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
}

#header-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.3px;
  flex: 1;
}

#header-actions {
  display: flex;
  gap: var(--sp-sm);
  align-items: center;
}

/* View Container */
#view-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  overscroll-behavior-y: contain;
}

/* =============================================
   VIEWS (TABS)
   ============================================= */
.view {
  display: none;
  min-height: calc(100dvh - var(--header-height) - var(--nav-height));
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: block;
}

/* =============================================
   BOTTOM NAVIGATION
   ============================================= */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  background: rgba(13, 13, 22, 0.90);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  height: var(--nav-height);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px 4px;
  position: relative;
  transition: transform 0.15s ease;
  border-radius: var(--r-md);
}

.nav-item:active { transform: scale(0.9); }

.nav-icon {
  font-size: 22px;
  line-height: 1;
  transition: filter 0.2s, transform 0.2s;
  filter: grayscale(30%) opacity(0.6);
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-disabled);
  transition: color 0.2s;
  letter-spacing: 0.2px;
}

.nav-item.active .nav-icon {
  filter: none;
  transform: scale(1.1);
  filter: drop-shadow(0 0 6px var(--accent));
}

.nav-item.active .nav-label {
  color: var(--accent);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 0 8px var(--accent);
}

/* =============================================
   CARDS
   ============================================= */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-md);
  margin: var(--sp-sm) var(--sp-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-sm);
}

/* =============================================
   CATEGORY ACCORDION
   ============================================= */
.categories-container {
  padding: 0 var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.category-group:hover {
  box-shadow: var(--shadow-sm);
}

.category-group.has-items {
  border-color: var(--border);
}

.category-header {
  display: flex;
  align-items: center;
  padding: 14px var(--sp-md);
  cursor: pointer;
  user-select: none;
  gap: 10px;
  transition: background 0.15s;
  position: relative;
  background: #25242f;
}

.category-header:active {
  background: var(--bg-elevated);
  transform: none;
}

.cat-emoji {
  font-size: 22px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.cat-info {
  flex: 1;
  min-width: 0;
}

.cat-name {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-primary);
}

.cat-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.cat-count {
  font-size: var(--fs-xs);
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-weight: 500;
}

.cat-value {
  font-size: var(--fs-xs);
  color: var(--accent);
  font-weight: 600;
}

.cat-chevron {
  font-size: 14px;
  color: var(--text-disabled);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.category-group.expanded .cat-chevron {
  transform: rotate(90deg);
}

.cat-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-disabled);
  font-size: 14px;
  border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.cat-edit-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-elevated);
}

/* Items list inside category */
.category-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  border-top: 0px solid var(--border-subtle);
}

.category-group.expanded .category-items {
  max-height: 2000px;
  border-top: 1px solid var(--border-subtle);
  transition: max-height 0.4s ease-in;
}

.item-row {
  display: flex;
  align-items: center;
  padding: 11px var(--sp-md);
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.15s;
}

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

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

.item-main {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.item-date {
  font-size: var(--fs-xs);
  color: var(--text-disabled);
}

.color-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-subtle);
}

.color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.item-price {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-disabled);
  font-size: 14px;
  transition: all 0.15s;
}

.btn-icon-sm:hover { background: var(--bg-elevated); color: var(--text-secondary); }
.btn-icon-sm.danger:hover { color: var(--danger); background: var(--danger-bg); }

/* Empty state */
.empty-category {
  padding: 16px var(--sp-md);
  text-align: center;
  color: var(--text-disabled);
  font-size: var(--fs-sm);
}

/* =============================================
   SEARCH & FILTER
   ============================================= */
.search-section {
  padding: var(--sp-md) var(--sp-md) var(--sp-sm);
}

.search-bar-wrap {
  position: relative;
}

.search-bar-wrap .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--text-disabled);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  padding: 0 16px 0 42px;
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow2);
}

.search-input::placeholder { color: var(--text-disabled); }

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: var(--sp-sm) var(--sp-md);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* =============================================
   FAB (Floating Action Button)
   ============================================= */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  right: max(16px, calc((100vw - 480px) / 2 + 16px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 20px rgba(129, 140, 248, 0.38);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 50;
}

.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(129, 140, 248, 0.5); }
.fab:active { transform: scale(0.94); }

/* =============================================
   INPUT TAB
   ============================================= */
.input-tab-inner {
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.input-hint {
  font-size: var(--fs-sm);
  color: var(--text-disabled);
  text-align: center;
  line-height: 1.5;
}

.textarea-wrap {
  position: relative;
}

.input-textarea {
  width: 100%;
  min-height: 120px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px var(--sp-md);
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--text-primary);
  outline: none;
  resize: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.6;
  display: block;
}

.input-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow2);
}

.input-textarea::placeholder {
  color: var(--text-disabled);
  font-size: var(--fs-sm);
}

.textarea-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 6px;
  gap: var(--sp-sm);
}

.char-count {
  font-size: var(--fs-xs);
  color: var(--text-disabled);
}

.parse-btn {
  width: 100%;
  height: 52px;
  border: none;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent-dark), var(--accent-dim), var(--accent));
  color: #ffffff;
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(129,140,248,0.3);
  letter-spacing: 0.2px;
}

.parse-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 28px rgba(129,140,248,0.45); }
.parse-btn:active { transform: scale(0.97); }
.parse-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.parse-btn .spinner-inline {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Draft list */
.draft-section-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.draft-count-badge {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
}

.draft-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
  animation: slideUp 0.2s ease;
}

.draft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.draft-num {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 3px 10px;
  border-radius: var(--r-full);
  letter-spacing: 0.5px;
}

.draft-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-disabled);
  font-size: 18px;
  line-height: 1;
  padding: 2px;
  border-radius: var(--r-sm);
  transition: color 0.15s;
}

.draft-remove:hover { color: var(--danger); }

.draft-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.draft-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.draft-field.full-width {
  grid-column: 1 / -1;
}

.draft-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Confirm bar */
.confirm-bar {
  position: sticky;
  bottom: calc(var(--nav-height) + var(--safe-bottom));
  left: 0;
  right: 0;
  background: rgba(13, 13, 22, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: var(--sp-sm) var(--sp-md);
  display: flex;
  gap: 8px;
  z-index: 40;
  animation: slideUp 0.2s ease;
}

/* Recent items */
.recent-section {
  padding: 0 2px;
}

.recent-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.recent-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.recent-scroll::-webkit-scrollbar { display: none; }

.recent-card {
  flex-shrink: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: 10px 12px;
  min-width: 130px;
  max-width: 160px;
}

.recent-item-name {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-item-price {
  font-size: var(--fs-xs);
  color: var(--accent);
  font-weight: 600;
  margin-top: 3px;
}

.recent-item-date {
  font-size: var(--fs-xs);
  color: var(--text-disabled);
  margin-top: 1px;
}

/* =============================================
   SUMMARY TAB
   ============================================= */
.summary-inner {
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.summary-hero {
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-xl) var(--sp-md);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.summary-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 50% 30%, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none;
}

.hero-label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.hero-value {
  font-size: var(--fs-3xl);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: var(--fs-sm);
  color: var(--text-disabled);
  margin-top: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 14px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-disabled);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.bar-section-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.category-bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bar-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bar-item-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

.bar-item-value {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--accent);
}

.bar-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: var(--r-full);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  border-radius: var(--r-full);
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0;
}

.color-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.color-tag {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* =============================================
   MODALS
   ============================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  padding: 0;
}

.modal-overlay.hidden {
  display: none;
}

.modal-sheet {
  background: var(--bg-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: var(--safe-bottom);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--r-full);
  margin: 10px auto 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-md) var(--sp-sm);
}

.modal-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-elevated);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: all 0.15s;
}

.modal-close:hover { background: var(--danger-bg); color: var(--danger); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-sm) var(--sp-md) var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.modal-footer {
  padding: var(--sp-sm) var(--sp-md);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Form fields */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

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

/* =============================================
   FORM INPUTS (global)
   ============================================= */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 16px; /* 16px minimum to prevent iOS zoom */
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow2);
}

input::placeholder, textarea::placeholder {
  color: var(--text-disabled);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
  cursor: pointer;
}

select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent-dim));
  color: #ffffff;
  box-shadow: 0 2px 12px rgba(129,140,248,0.28);
}

.btn-primary:hover { box-shadow: 0 4px 20px rgba(129,140,248,0.45); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

.btn-full { width: 100%; }

/* =============================================
   TOAST NOTIFICATIONS
   ============================================= */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 400px;
  z-index: 500;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-lg);
  font-size: var(--fs-sm);
  font-weight: 500;
  backdrop-filter: blur(16px);
  animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-md);
  pointer-events: all;
}

.toast-icon { font-size: 18px; flex-shrink: 0; }

.toast.success { background: rgba(52,211,153,0.15); border: 1px solid rgba(52,211,153,0.28); color: #6ee7b7; }
.toast.error   { background: rgba(248,113,113,0.18); border: 1px solid rgba(248,113,113,0.3); color: #fca5a5; }
.toast.info    { background: rgba(96,165,250,0.18); border: 1px solid rgba(96,165,250,0.3); color: #93c5fd; }
.toast.warning { background: rgba(251,191,36,0.18); border: 1px solid rgba(251,191,36,0.3); color: #fcd34d; }

.toast.fade-out {
  animation: toastOut 0.3s ease forwards;
}

/* =============================================
   AUTH SCREEN
   ============================================= */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--header-height) - var(--nav-height));
  padding: var(--sp-lg);
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-xl);
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo {
  font-size: 56px;
  margin-bottom: var(--sp-md);
  display: block;
  filter: drop-shadow(0 0 20px rgba(129,140,248,0.45));
}

.auth-title {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-lg);
  line-height: 1.6;
}

.auth-note {
  font-size: var(--fs-xs);
  color: var(--text-disabled);
  margin-top: var(--sp-md);
  line-height: 1.6;
}

/* User profile card */
.user-card {
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-md);
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.user-email {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.user-status {
  font-size: var(--fs-xs);
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.household-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-md);
}

.household-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-disabled);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.household-name {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text-primary);
}

.invite-code {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 4px;
  text-align: center;
  background: var(--accent-glow);
  padding: 10px;
  border-radius: var(--r-md);
  margin-top: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.invite-code:hover { background: var(--accent-glow2); }

/* Settings section in account */
.settings-section {
  padding: var(--sp-md);
}

.settings-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-disabled);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: var(--sp-sm);
  padding: 0 4px;
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  padding: 14px var(--sp-md);
  gap: var(--sp-sm);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.15s;
}

.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--bg-elevated); }

.settings-row-icon { font-size: 20px; width: 28px; text-align: center; }
.settings-row-label { flex: 1; font-size: var(--fs-base); color: var(--text-primary); }
.settings-row-value { font-size: var(--fs-sm); color: var(--text-disabled); }

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-xl) var(--sp-lg);
  text-align: center;
  color: var(--text-disabled);
  min-height: 200px;
}

.empty-state .empty-emoji {
  font-size: 56px;
  margin-bottom: var(--sp-md);
  opacity: 0.7;
  filter: grayscale(20%);
}

.empty-state .empty-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-disabled);
  margin-bottom: 6px;
}

.empty-state .empty-desc {
  font-size: var(--fs-sm);
  color: var(--text-disabled);
  opacity: 0.7;
  line-height: 1.6;
}

/* =============================================
   LOADING SPINNER
   ============================================= */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: var(--sp-xl) auto;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  flex-direction: column;
  gap: var(--sp-md);
}

.loading-text {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  animation: pulse 1.5s ease-in-out infinite;
}

/* =============================================
   CONFIRM DIALOG (special modal)
   ============================================= */
.confirm-dialog {
  background: var(--bg-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 480px;
  padding: var(--sp-lg) var(--sp-lg) calc(var(--sp-lg) + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

.confirm-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.confirm-message {
  font-size: var(--fs-base);
  color: var(--text-muted);
  margin-bottom: var(--sp-lg);
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* =============================================
   SEARCH RESULTS
   ============================================= */
.search-results {
  padding: 0 var(--sp-md);
}

.search-result-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
  gap: 10px;
}

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

.result-cat-badge {
  font-size: var(--fs-xs);
  padding: 3px 8px;
  background: var(--bg-elevated);
  border-radius: var(--r-full);
  color: var(--text-muted);
  white-space: nowrap;
}

mark {
  background: rgba(129, 140, 248, 0.20);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

/* =============================================
   SECTION DIVIDERS
   ============================================= */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-md) var(--sp-sm);
}

.section-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

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

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

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

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

@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */
.text-accent   { color: var(--accent); }
.text-muted    { color: var(--text-muted); }
.text-disabled { color: var(--text-disabled); }
.text-danger   { color: var(--danger); }
.text-sm       { font-size: var(--fs-sm); }
.text-xs       { font-size: var(--fs-xs); }
.font-bold     { font-weight: 700; }
.font-semibold { font-weight: 600; }
.mt-sm { margin-top: var(--sp-sm); }
.mt-md { margin-top: var(--sp-md); }
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.w-full { width: 100%; }

/* Page-level padding for views */
.view-padding { padding: var(--sp-md); }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

/* =============================================
   RESPONSIVE (Desktop preview)
   ============================================= */
@media (min-width: 480px) {
  #app {
    box-shadow: 0 0 60px rgba(0,0,0,0.5);
  }

  .toast-container {
    max-width: 440px;
  }
}
