/* Alpine cloak: hide elements until Alpine initializes to prevent flash */
[x-cloak] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Loading spinner ─────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  border: 2.5px solid rgba(0, 0, 0, 0.1);
  border-top-color: #1B5E20;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
  display: inline-block;
}

/* White variant for dark backgrounds */
.spinner-white {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
}

/* ── Pro username gradient ──────────────────────────────────── */
.pro-name {
  background: linear-gradient(90deg, #1B5E20 0%, #2e7d32 55%, #FFC107 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Bottom nav safe area ────────────────────────────────────── */
.bottom-nav {
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 2px);
}

/* ── Hide scrollbar (tab bars, chip rows) ──────────────────── */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ── Page transition on route change ────────────────────────── */
@keyframes page-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

#page-content > * {
  animation: page-in 0.14s ease-out;
}

/* ═══════════════════════════════════════════════════════════════
   THEME SYSTEM
   Three palettes applied as a class on <html>.
   Key: 'cg_theme' in localStorage. Default: theme-light.
   Anti-flash inline <script> in index.html <head> sets the class
   synchronously before any paint.
═══════════════════════════════════════════════════════════════ */

html.theme-light {
  color-scheme: light;
  --bg-body:       #F9FAFB;
  --bg-page:       #F0F4F0;
  --bg-card:       #ffffff;
  --bg-secondary:  #f3f4f6;
  --bg-input:      #f9fafb;
  --border:        #e5e7eb;
  --border-light:  #f3f4f6;
  /* Semantic status surfaces */
  --bg-success-subtle:  #E8F5E9;
  --bg-warning-subtle:  #FFF8E1;
  --bg-danger-subtle:   #fef2f2;
  --bg-info-subtle:     #E0E7FF;
  --bg-purple-subtle:   #F3E8FF;
  /* Semantic status text */
  --text-success:      #1B5E20;
  --text-warning:      #b45309;
  --text-warning-soft: #92610a;
  --text-danger:       #dc2626;
  --text-info:         #4338ca;
  --text-purple:       #7c3aed;
  /* Semantic status borders */
  --border-success:    #A5D6A7;
  --border-warning:    #FFC107;
  --border-danger:     #fca5a5;
  --border-purple:     #D8B4FE;
  /* Poll fill bars */
  --poll-bar-voted:        #c8e6c9;
  --poll-bar-voted-strong: #1B5E20;
  --poll-bar-empty:        #f3f4f6;
}

html.theme-dim {
  color-scheme: dark;
  --bg-body:       #15202b;
  --bg-page:       #192230;
  --bg-card:       #1e2732;
  --bg-secondary:  #253341;
  --bg-input:      #2c3e4f;
  --text-primary:  #f7f9f9;
  --text-body:     #d1d9e0;
  --text-secondary:#8899a6;
  --text-muted:    #6c7a87;
  --text-dim:      #485563;
  --border:        #38444d;
  --border-light:  #2c3e4f;
  /* Semantic status surfaces */
  --bg-success-subtle:  rgba(34, 197, 94, 0.08);
  --bg-warning-subtle:  rgba(245, 158, 11, 0.08);
  --bg-danger-subtle:   rgba(220, 38, 38, 0.08);
  --bg-info-subtle:     rgba(99, 102, 241, 0.10);
  --bg-purple-subtle:   rgba(124, 58, 237, 0.10);
  /* Semantic status text */
  --text-success:      #86efac;
  --text-warning:      #fbbf24;
  --text-warning-soft: #f59e0b;
  --text-danger:       #f87171;
  --text-info:         #a5b4fc;
  --text-purple:       #c4b5fd;
  /* Semantic status borders */
  --border-success:    rgba(27, 94, 32, 0.30);
  --border-warning:    rgba(245, 158, 11, 0.30);
  --border-danger:     rgba(220, 38, 38, 0.30);
  --border-purple:     rgba(124, 58, 237, 0.30);
  /* Poll fill bars */
  --poll-bar-voted:        rgba(34, 197, 94, 0.18);
  --poll-bar-voted-strong: #4caf50;
  --poll-bar-empty:        #253341;
}

html.theme-black {
  color-scheme: dark;
  --bg-body:       #000000;
  --bg-page:       #050505;
  --bg-card:       #111111;
  --bg-secondary:  #1a1a1a;
  --bg-input:      #1c1c1e;
  --text-primary:  #e7e9ea;
  --text-body:     #adb5bd;
  --text-secondary:#71767b;
  --text-muted:    #536471;
  --text-dim:      #3c4348;
  --border:        #2f3336;
  --border-light:  #1c1c1c;
  /* Semantic status surfaces */
  --bg-success-subtle:  rgba(34, 197, 94, 0.06);
  --bg-warning-subtle:  rgba(245, 158, 11, 0.06);
  --bg-danger-subtle:   rgba(220, 38, 38, 0.06);
  --bg-info-subtle:     rgba(99, 102, 241, 0.08);
  --bg-purple-subtle:   rgba(124, 58, 237, 0.08);
  /* Semantic status text */
  --text-success:      #86efac;
  --text-warning:      #fbbf24;
  --text-warning-soft: #f59e0b;
  --text-danger:       #f87171;
  --text-info:         #a5b4fc;
  --text-purple:       #c4b5fd;
  /* Semantic status borders */
  --border-success:    rgba(27, 94, 32, 0.25);
  --border-warning:    rgba(245, 158, 11, 0.25);
  --border-danger:     rgba(220, 38, 38, 0.25);
  --border-purple:     rgba(124, 58, 237, 0.25);
  /* Poll fill bars */
  --poll-bar-voted:        rgba(34, 197, 94, 0.14);
  --poll-bar-voted-strong: #4caf50;
  --poll-bar-empty:        #1a1a1a;
}

/* ── Dark mode overrides ─────────────────────────────────────── */

html:not(.theme-light) body {
  background-color: var(--bg-body) !important;
}

/* Page-level bg — Tailwind arbitrary-value classes */
html:not(.theme-light) .bg-\[\#F9FAFB\] { background-color: var(--bg-body)      !important; }
html:not(.theme-light) .bg-\[\#F0F4F0\] { background-color: var(--bg-page)      !important; }

/* Cards / surfaces */
html:not(.theme-light) .bg-white        { background-color: var(--bg-card)       !important; }
html:not(.theme-light) .bg-gray-50      { background-color: var(--bg-secondary)  !important; }
html:not(.theme-light) .bg-gray-100     { background-color: var(--bg-input)      !important; }
html:not(.theme-light) .bg-gray-200     { background-color: var(--bg-secondary)  !important; }

/* Tinted icon-chip backgrounds (settings rows) */
html:not(.theme-light) .bg-\[\#E8F5E9\] { background-color: rgba(27,  94,  32, 0.22) !important; }
html:not(.theme-light) .bg-\[\#EFF6FF\] { background-color: rgba(37,  99, 235, 0.18) !important; }
html:not(.theme-light) .bg-\[\#FFF8E1\] { background-color: rgba(180, 83,   9, 0.18) !important; }

/* Text */
html:not(.theme-light) .text-gray-900 { color: var(--text-primary)   !important; }
html:not(.theme-light) .text-gray-800 { color: var(--text-primary)   !important; }
html:not(.theme-light) .text-gray-700 { color: var(--text-body)      !important; }
html:not(.theme-light) .text-gray-600 { color: var(--text-body)      !important; }
html:not(.theme-light) .text-gray-500 { color: var(--text-secondary) !important; }
html:not(.theme-light) .text-gray-400 { color: var(--text-muted)     !important; }
html:not(.theme-light) .text-gray-300 { color: var(--text-dim)       !important; }
html:not(.theme-light) .text-gray-200 { color: var(--text-dim)       !important; }

/* Borders */
html:not(.theme-light) .border-gray-200 { border-color: var(--border)       !important; }
html:not(.theme-light) .border-gray-100 { border-color: var(--border-light) !important; }
html:not(.theme-light) .border-gray-50  { border-color: var(--border-light) !important; }

/* Divide utility (poll voting option rows) */
html:not(.theme-light) .divide-gray-100 > :not([hidden]) ~ :not([hidden]) {
  border-color: var(--border-light) !important;
}

/* Touch-feedback active states */
html:not(.theme-light) .active\:bg-gray-50:active  { background-color: var(--bg-secondary) !important; }
html:not(.theme-light) .active\:bg-gray-100:active { background-color: var(--bg-input)     !important; }

/* Form inputs */
html:not(.theme-light) input,
html:not(.theme-light) textarea,
html:not(.theme-light) select {
  color: var(--text-primary) !important;
  background-color: var(--bg-input) !important;
  border-color: var(--border) !important;
}

html:not(.theme-light) input::placeholder,
html:not(.theme-light) textarea::placeholder { color: var(--text-muted) !important; }
html:not(.theme-light) .placeholder-gray-400::placeholder { color: var(--text-muted) !important; }

/* Toggle thumb — keep visually distinct on dark tracks */
html:not(.theme-light) button > .absolute.bg-white.rounded-full.shadow {
  background-color: #d8d8d8 !important;
}

/* Spinner — adapt track colour to dark backgrounds */
html:not(.theme-light) .spinner:not(.spinner-white) {
  border-color: rgba(255, 255, 255, 0.12);
  border-top-color: #4caf50;
}

/* Merchant filter chips — button-scoped override so inactive pill
   buttons surface correctly when bg-white is applied via Alpine :class */
html:not(.theme-light) button.bg-white {
  background-color: var(--bg-secondary) !important;
}

/* Amber */
html:not(.theme-light) .bg-amber-50          { background-color: rgba(180,  83,   9, 0.12) !important; }
html:not(.theme-light) .border-amber-100      { border-color:     rgba(180,  83,   9, 0.2)  !important; }
html:not(.theme-light) .border-amber-200      { border-color:     rgba(180,  83,   9, 0.3)  !important; }
html:not(.theme-light) .border-amber-200\/80  { border-color:     rgba(180,  83,   9, 0.24) !important; }
html:not(.theme-light) .border-amber-300      { border-color:     rgba(180,  83,   9, 0.4)  !important; }
html:not(.theme-light) .text-amber-800        { color: #fbbf24 !important; }
html:not(.theme-light) .text-amber-700        { color: #f59e0b !important; }
html:not(.theme-light) .text-amber-600        { color: #f59e0b !important; }

/* Green */
html:not(.theme-light) .bg-green-50           { background-color: rgba(27,  94,  32, 0.12) !important; }
html:not(.theme-light) .border-green-100      { border-color:     rgba(27,  94,  32, 0.2)  !important; }
html:not(.theme-light) .border-green-300      { border-color:     rgba(27,  94,  32, 0.4)  !important; }
html:not(.theme-light) .text-\[\#2e7d32\]     { color: #86efac !important; }

/* Blue */
html:not(.theme-light) .bg-blue-50            { background-color: rgba(37,   99, 235, 0.12) !important; }
html:not(.theme-light) .border-blue-100       { border-color:     rgba(37,   99, 235, 0.2)  !important; }

/* Orange */
html:not(.theme-light) .bg-orange-50          { background-color: rgba(234,  88,  12, 0.12) !important; }
html:not(.theme-light) .border-orange-100     { border-color:     rgba(234,  88,  12, 0.2)  !important; }

/* Red */
html:not(.theme-light) .bg-red-50             { background-color: rgba(220,  38,  38, 0.12) !important; }
html:not(.theme-light) .border-red-100        { border-color:     rgba(220,  38,  38, 0.2)  !important; }
html:not(.theme-light) .border-red-200        { border-color:     rgba(220,  38,  38, 0.3)  !important; }

/* Notification unread row (Alpine :class bg-[#F0F7F0]) — light green tint in dark mode */
html:not(.theme-light) .bg-\[\#F0F7F0\] { background-color: rgba(34, 197, 94, 0.08) !important; }

