/* =========================================================
   FlowPay Install Tracker — stylesheet
   Liquid-glass / spatial UI. Token system lives in :root.
   ========================================================= */

:root {
  /* --- Brand --- */
  --primary: #09ce80;
  --primary-ink: #067a4d;
  --primary-soft: #e3faf1;
  --secondary: #ffffff;

  /* --- Neutrals --- */
  --ink: #0d211a;
  --ink-muted: #55685f;
  --ink-faint: #93a39c;
  --surface: #eef8f3;
  --border: rgba(13, 33, 26, 0.09);

  /* --- Signal --- */
  --up: #09ce80;
  --down: #e5484d;
  --google-blue: #4285f4;
  --google-red: #ea4335;
  --google-yellow: #fbbc05;
  --google-green: #34a853;

  /* --- Liquid glass --- */
  --glass-bg: rgba(255, 255, 255, 0.5);
  --glass-bg-strong: rgba(255, 255, 255, 0.68);
  --glass-border: rgba(255, 255, 255, 0.75);
  --glass-blur: 22px;
  --shadow-soft: 0 8px 30px rgba(13, 33, 26, 0.10);
  --shadow-lifted: 0 24px 60px -12px rgba(13, 33, 26, 0.22);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 1px rgba(255, 255, 255, 0.15);

  /* --- Type --- */
  --font-display: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;

  /* --- Shape / motion --- */
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --radius-xl: 34px;
  --ease: cubic-bezier(.2,.8,.2,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ---------- Spatial background: animated liquid blobs ---------- */
.bg-scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 0%, #f4fffa 0%, transparent 55%),
    radial-gradient(ellipse at 100% 100%, #eafaf3 0%, transparent 55%),
    var(--surface);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  will-change: transform;
}
.blob-1 {
  width: 46vw; height: 46vw; top: -14vw; left: -10vw;
  background: radial-gradient(circle at 30% 30%, #09ce80, #bdf5dd 70%);
  animation: blobFloat1 26s ease-in-out infinite;
}
.blob-2 {
  width: 34vw; height: 34vw; bottom: -12vw; right: -8vw;
  background: radial-gradient(circle at 60% 40%, #6ee7c0, #eafaf3 70%);
  animation: blobFloat2 32s ease-in-out infinite;
}
.blob-3 {
  width: 24vw; height: 24vw; top: 40%; right: 18%;
  background: radial-gradient(circle at 50% 50%, #b9f3dd, transparent 70%);
  animation: blobFloat3 22s ease-in-out infinite;
  opacity: 0.4;
}
@keyframes blobFloat1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(4vw, 3vw) scale(1.08); }
  66%      { transform: translate(-3vw, 5vw) scale(0.96); }
}
@keyframes blobFloat2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-5vw, -4vw) scale(1.1); }
}
@keyframes blobFloat3 {
  0%, 100% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50%      { transform: translate(-2vw, 3vw) scale(1.15) rotate(20deg); }
}

/* ---------- Glass surface ---------- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft), var(--shadow-inset);
  position: relative;
}
.glass-strong { background: var(--glass-bg-strong); }
.glass::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 40%);
  pointer-events: none;
}

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 14px; z-index: 30; margin: 14px auto 0; max-width: 1080px; padding: 0 24px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-radius: 999px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand-name span { color: var(--primary); }
.brand-logo { border-radius: 9px; box-shadow: var(--shadow-soft); }
.topbar-link {
  font-size: 0.78rem; font-weight: 600; color: var(--ink-faint); text-decoration: none;
  padding: 6px 12px; border-radius: 999px; transition: color .2s var(--ease), background .2s var(--ease);
}
.topbar-link:hover { color: var(--ink); background: rgba(13,33,26,0.05); }

/* ---------- Page entrance animation ---------- */
.appear { opacity: 0; transform: translateY(18px) scale(0.98); animation: appearIn .8s var(--spring) forwards; }
@keyframes appearIn { to { opacity: 1; transform: translateY(0) scale(1); } }

main.view { padding: 36px 0 90px; }

/* ---------- Hero ---------- */
.hero { padding: 40px 42px; margin-bottom: 30px; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 28px; }
.hero-label { font-size: 0.95rem; color: var(--ink-muted); margin: 0 0 8px; }
.hero-number {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(3.2rem, 9vw, 5.6rem);
  line-height: 1; letter-spacing: -0.03em; color: var(--ink);
  background: linear-gradient(120deg, var(--ink) 40%, var(--primary-ink));
  -webkit-background-clip: text; background-clip: text;
}
.hero-number small {
  font-size: 0.32em; font-weight: 700; color: var(--ink-faint); margin-left: 10px; letter-spacing: 0;
  -webkit-text-fill-color: var(--ink-faint);
}
.hero-breakdown { margin: 10px 0 0; font-size: 0.86rem; color: var(--ink-muted); }
.hero-breakdown strong { color: var(--primary-ink); font-weight: 700; }

.hero-sub { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--ink-muted); font-size: 0.95rem; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; transition: transform .3s var(--spring); }
.chip.up { background: var(--primary-soft); color: var(--primary-ink); }
.chip.down { background: #fdecec; color: var(--down); }
.chip.pulse { animation: chipPulse .5s var(--spring); }
@keyframes chipPulse { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

.hero-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }

.btn {
  border: none; border-radius: 999px; padding: 13px 24px; font-weight: 700; font-size: 0.95rem;
  display: inline-flex; align-items: center; gap: 8px;
  transition: transform .2s var(--spring), box-shadow .2s var(--ease), filter .2s var(--ease);
}
.btn-primary {
  background: linear-gradient(135deg, #0eecA0, var(--primary)); color: #06301f;
  box-shadow: 0 10px 26px -8px rgba(9,206,128,.6), var(--shadow-inset);
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.04); }
.btn-primary:active { transform: translateY(0) scale(0.97); }
.btn-primary:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.btn-ghost {
  background: var(--glass-bg); backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border); color: var(--ink);
}
.btn-ghost:hover { transform: translateY(-2px); }
.btn-danger { background: rgba(229,72,77,0.12); color: #b81f24; border: 1px solid rgba(229,72,77,0.25); }
.btn-danger:hover { background: rgba(229,72,77,0.18); transform: translateY(-2px); }
.btn-sm { padding: 7px 14px; font-size: 0.78rem; border-radius: 10px; }
.install-hint { font-size: 0.78rem; color: var(--ink-faint); max-width: 220px; text-align: right; }

/* ---------- Stat cards (spatial tilt) ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 40px; perspective: 900px; }
.stat-card { padding: 20px 22px; transition: transform .35s var(--ease), box-shadow .35s var(--ease); transform-style: preserve-3d; }
.stat-card:hover { box-shadow: var(--shadow-lifted), var(--shadow-inset); }
.stat-card .k { font-size: 0.8rem; color: var(--ink-muted); margin-bottom: 6px; }
.stat-card .v { font-family: var(--font-display); font-size: 1.7rem; font-weight: 800; }

/* ---------- Sections ---------- */
.section { margin-bottom: 44px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; }
.section-head p { margin: 0; color: var(--ink-muted); font-size: 0.85rem; }

.panel { padding: 28px; }

/* ---------- Chart ---------- */
.chart-shell { position: relative; min-height: 260px; }
#barChart { width: 100%; height: 260px; display: block; }
.chart-legend { display: flex; gap: 18px; margin-top: 14px; font-size: 0.8rem; color: var(--ink-muted); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, rgba(13,33,26,0.06) 25%, rgba(13,33,26,0.12) 37%, rgba(13,33,26,0.06) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel-bar { height: 260px; }
.skel-line { height: 14px; margin-bottom: 8px; }

.lazy-section { opacity: 0; transform: translateY(16px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.lazy-section.in-view { opacity: 1; transform: translateY(0); }

img[loading="lazy"] { background: var(--border); min-height: 32px; }

/* ---------- Recommended ---------- */
.rec-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; perspective: 900px; }
.rec-card { padding: 20px; transition: transform .35s var(--ease), box-shadow .35s var(--ease); transform-style: preserve-3d; }
.rec-card:hover { box-shadow: var(--shadow-lifted), var(--shadow-inset); }
.rec-card .rec-icon {
  width: 36px; height: 36px; border-radius: 11px; background: var(--primary-soft); color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px; font-size: 1.05rem;
}
.rec-card h3 { font-size: 0.95rem; margin: 0 0 6px; }
.rec-card p { font-size: 0.82rem; color: var(--ink-muted); margin: 0; line-height: 1.5; }
.rec-card .rec-tag {
  display: inline-block; margin-top: 10px; font-size: 0.7rem; font-weight: 700;
  color: var(--primary-ink); background: var(--primary-soft); padding: 2px 8px; border-radius: 999px;
}

/* ---------- Google campaign badge ---------- */
.gcamp-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; color: var(--ink-muted); }

/* ---------- Admin ---------- */
.admin-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 20px; align-items: start; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 13px;
  font-size: 0.95rem; font-family: inherit; background: rgba(255,255,255,0.6); color: var(--ink);
  transition: box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,206,128,0.18);
}
.k-preview { margin-top: -6px; margin-bottom: 16px; font-size: 0.8rem; color: var(--primary-ink); font-weight: 700; min-height: 1em; }
.form-msg { margin-top: 14px; font-size: 0.85rem; font-weight: 600; min-height: 1.2em; }
.form-msg.ok { color: var(--primary-ink); }
.form-msg.err { color: var(--down); }

.table-scroll { max-height: 520px; overflow-y: auto; border-radius: var(--radius-md); }
table.recent { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.recent th, table.recent td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.recent th { color: var(--ink-muted); font-weight: 600; font-size: 0.74rem; position: sticky; top: 0; background: rgba(255,255,255,0.85); backdrop-filter: blur(8px); }
table.recent tbody tr { transition: background .2s var(--ease); }
table.recent tbody tr:hover { background: rgba(9,206,128,0.05); }
.source-pill { font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(13,33,26,0.05); border: 1px solid var(--border); }
.row-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.6); display: inline-flex; align-items: center; justify-content: center;
  transition: transform .15s var(--spring), background .2s var(--ease);
}
.icon-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.9); }
.icon-btn.danger:hover { background: rgba(229,72,77,0.12); }
.edit-row input { padding: 6px 8px; font-size: 0.85rem; border-radius: 7px; }
.danger-zone { border: 1px dashed rgba(229,72,77,0.35); background: rgba(229,72,77,0.05); }

/* ---------- Footer ---------- */
.footer { padding: 26px 0 60px; display: flex; align-items: center; justify-content: space-between; color: var(--ink-faint); font-size: 0.82rem; }
.footer a { color: var(--ink-faint); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--secondary); padding: 12px 22px; border-radius: 999px;
  font-size: 0.86rem; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .3s var(--ease), transform .3s var(--spring); z-index: 50; box-shadow: var(--shadow-lifted);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal (reset confirm) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(13,33,26,0.35); display: flex; align-items: center; justify-content: center;
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity .25s var(--ease);
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal-card { width: min(420px, calc(100% - 40px)); padding: 28px; transform: scale(0.92) translateY(10px); transition: transform .3s var(--spring); }
.modal-backdrop.show .modal-card { transform: scale(1) translateY(0); }
.modal-card h3 { margin: 0 0 10px; font-family: var(--font-display); }
.modal-card p { color: var(--ink-muted); font-size: 0.9rem; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .rec-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; padding: 30px 24px; }
  .hero-actions { align-items: flex-start; width: 100%; }
  .install-hint { text-align: left; }
  .topbar { top: 8px; padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .blob { animation: none !important; }
}