@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

/* Hide body until theme is applied to prevent FOUC */
html:not([data-theme]) body {
  visibility: hidden;
}

/* ─── Theme tokens (OUTSIDE @layer → max cascade priority) ─── */

:where(html) {
  --radius: 0.75rem;
  --background: 0 0% 98%;
  --foreground: 0 0% 9%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 9%;
  --popover: 0 0% 100%;
  --popover-foreground: 0 0% 9%;
  --primary: 217 91% 50%;
  --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 96%;
  --secondary-foreground: 0 0% 9%;
  --muted: 0 0% 96%;
  --muted-foreground: 0 0% 45%;
  --accent: 0 0% 96%;
  --accent-foreground: 0 0% 9%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 9%;
  --border: 0 0% 90%;
  --input: 0 0% 90%;
  --ring: 217 91% 50%;
  --glow-primary: 0 0 20px hsl(217 91% 50% / 0.15);
  --glow-success: 0 0 20px hsl(142 71% 45% / 0.15);
  --sidebar-background: 0 0% 100%;
  --sidebar-foreground: 0 0% 9%;
  --sidebar-primary: 217 91% 50%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 0 0% 96%;
  --sidebar-accent-foreground: 0 0% 9%;
  --sidebar-border: 0 0% 90%;
  --sidebar-ring: 217 91% 50%;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
}

/* Checkout em tema claro: ignora tema do dashboard e força cores claras */
[data-checkout-theme="light"] {
  --background: 0 0% 100%;
  --foreground: 0 0% 9%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 9%;
  --border: 0 0% 90%;
  --input: 0 0% 96%;
  --muted: 0 0% 96%;
  --muted-foreground: 0 0% 45%;
  --ring: 0 0% 9%;
}

html[data-theme="default"] {
  --background: 222 47% 11%;
  --foreground: 210 40% 98%;
  --card: 217 33% 17%;
  --card-foreground: 210 40% 98%;
  --popover: 217 33% 17%;
  --popover-foreground: 210 40% 98%;
  --primary: 217 91% 60%;
  --primary-foreground: 0 0% 100%;
  --secondary: 217 33% 17%;
  --secondary-foreground: 215 20% 88%;
  --muted: 217 33% 22%;
  --muted-foreground: 215 20% 75%; /* Boosted from 65% for AAA/AA contrast */
  --accent: 217 33% 22%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 210 40% 98%;
  --success: 160 84% 39%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 222 47% 11%;
  --border: 217 33% 26%;
  --input: 217 33% 26%;
  --ring: 217 91% 60%;
  --glow-primary: 0 0 20px hsl(217 91% 60% / 0.3);
  --glow-success: 0 0 20px hsl(160 84% 39% / 0.3);
  --sidebar-background: 222 47% 9%;
  --sidebar-foreground: 215 20% 88%;
  --sidebar-primary: 217 91% 60%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 217 33% 17%;
  --sidebar-accent-foreground: 210 40% 98%;
  --sidebar-border: 217 33% 22%;
  --sidebar-ring: 217 91% 60%;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
}

html[data-theme="light"] {
  --background: 0 0% 97%;
  --foreground: 0 0% 9%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 9%;
  --popover: 0 0% 100%;
  --popover-foreground: 0 0% 9%;
  --primary: 211 100% 50%;
  --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 96%;
  --secondary-foreground: 0 0% 9%;
  --muted: 0 0% 95%;
  --muted-foreground: 0 0% 40%;
  --accent: 211 100% 96%;
  --accent-foreground: 211 100% 40%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 9%;
  --border: 0 0% 89%;
  --input: 0 0% 89%;
  --ring: 211 100% 50%;
  --glow-primary: none;
  --glow-success: none;
  --sidebar-background: 0 0% 100%;
  --sidebar-foreground: 0 0% 9%;
  --sidebar-primary: 211 100% 50%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 211 100% 96%;
  --sidebar-accent-foreground: 211 100% 40%;
  --sidebar-border: 0 0% 89%;
  --sidebar-ring: 211 100% 50%;
}

html[data-theme="dark"] {
  --background: 0 0% 10%;
  --foreground: 0 0% 98%;
  --card: 0 0% 13%;
  --card-foreground: 0 0% 98%;
  --popover: 0 0% 13%;
  --popover-foreground: 0 0% 98%;
  --primary: 217 91% 60%;
  --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 15%;
  --secondary-foreground: 0 0% 90%;
  --muted: 0 0% 18%;
  --muted-foreground: 0 0% 63%;
  --accent: 0 0% 18%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 98%;
  --success: 160 84% 39%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 9%;
  --border: 0 0% 22%;
  --input: 0 0% 22%;
  --ring: 217 91% 60%;
  --glow-primary: 0 0 20px hsl(217 91% 60% / 0.25);
  --glow-success: 0 0 20px hsl(160 84% 39% / 0.3);
  --sidebar-background: 0 0% 8%;
  --sidebar-foreground: 0 0% 90%;
  --sidebar-primary: 217 91% 60%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 0 0% 18%;
  --sidebar-accent-foreground: 0 0% 98%;
  --sidebar-border: 0 0% 22%;
  --sidebar-ring: 217 91% 60%;

  /* Bauhaus Dark Tokens */
  --bauhaus-card-bg: #151419;
  --bauhaus-card-separator: #2F2B2A;
  --bauhaus-card-accent: #156ef6;
  --bauhaus-card-radius: 2.25rem;
  --bauhaus-card-border-width: 2px;
  --bauhaus-card-inscription-top: #bfc7d5;
  --bauhaus-card-inscription-main: #f0f0f1;
  --bauhaus-card-inscription-sub: #a0a1b3;
  --bauhaus-card-inscription-progress-label: #b5b6c4;
  --bauhaus-card-inscription-progress-value: #e7e7f7;
  --bauhaus-card-progress-bar-bg: #363636;
  --bauhaus-chronicle-bg: #fff;
  --bauhaus-chronicle-fg: #151419;
  --bauhaus-chronicle-hover-fg: #fff;
}

/* ─── Rede social: temas customizados (admin) ─── */
.rede-theme-wrapper[data-rede-theme="light"] {
  --background: 0 0% 97%;
  --foreground: 0 0% 9%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 9%;
  --primary: 211 100% 50%;
  --primary-foreground: 0 0% 100%;
  --muted: 0 0% 95%;
  --muted-foreground: 0 0% 40%;
  --accent: 211 100% 96%;
  --accent-foreground: 211 100% 40%;
  --border: 0 0% 89%;
  --ring: 211 100% 50%;
}
.rede-theme-wrapper[data-rede-theme="dark"] {
  --background: 0 0% 10%;
  --foreground: 0 0% 98%;
  --card: 0 0% 13%;
  --card-foreground: 0 0% 98%;
  --primary: 217 91% 60%;
  --primary-foreground: 0 0% 100%;
  --muted: 0 0% 18%;
  --muted-foreground: 0 0% 63%;
  --accent: 0 0% 18%;
  --accent-foreground: 0 0% 98%;
  --border: 0 0% 22%;
  --ring: 217 91% 60%;
}
.rede-theme-wrapper[data-rede-theme="ocean"] {
  --background: 210 40% 96%;
  --foreground: 210 40% 12%;
  --card: 0 0% 100%;
  --card-foreground: 210 40% 12%;
  --primary: 199 89% 48%;
  --primary-foreground: 0 0% 100%;
  --muted: 210 30% 92%;
  --muted-foreground: 210 25% 45%;
  --accent: 199 89% 92%;
  --accent-foreground: 199 89% 30%;
  --border: 210 25% 88%;
  --ring: 199 89% 48%;
}
.rede-theme-wrapper[data-rede-theme="forest"] {
  --background: 120 20% 97%;
  --foreground: 120 30% 12%;
  --card: 0 0% 100%;
  --card-foreground: 120 30% 12%;
  --primary: 142 71% 45%;
  --primary-foreground: 0 0% 100%;
  --muted: 120 15% 92%;
  --muted-foreground: 120 15% 40%;
  --accent: 142 40% 92%;
  --accent-foreground: 142 50% 28%;
  --border: 120 15% 88%;
  --ring: 142 71% 45%;
}
.rede-theme-wrapper[data-rede-theme="purple"] {
  --background: 270 30% 97%;
  --foreground: 270 30% 12%;
  --card: 0 0% 100%;
  --card-foreground: 270 30% 12%;
  --primary: 262 83% 58%;
  --primary-foreground: 0 0% 100%;
  --muted: 270 20% 92%;
  --muted-foreground: 270 15% 45%;
  --accent: 262 60% 92%;
  --accent-foreground: 262 50% 35%;
  --border: 270 20% 88%;
  --ring: 262 83% 58%;
}

/* ─── Tailwind base layer (body + borders only) ─── */

@layer base {
  html {
    scroll-behavior: smooth;
    min-width: 0;
  }

  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground font-sans antialiased;
    font-family: 'DM Sans', system-ui, sans-serif;
    min-width: 0;
  }
}

@layer utilities {
  .text-gradient {
    @apply bg-clip-text text-transparent bg-gradient-to-r from-primary to-blue-400;
  }

  .glow-primary {
    box-shadow: var(--glow-primary);
  }

  .glow-success {
    box-shadow: var(--glow-success);
  }

  .glass {
    @apply bg-card/80 backdrop-blur-xl border border-border/50;
  }

  .animate-float {
    animation: float 6s ease-in-out infinite;
  }

  .animate-pulse-slow {
    animation: pulse 4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  .animate-fade-up {
    animation: fadeUp 0.6s ease-out forwards;
  }

  .animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
  }

  .animate-scroll {
    animation: scroll 30s linear infinite;
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-33.33%);
  }
}

/* Rede Financeira: transição de abas e entrada de nós no grafo */
@keyframes redeTabIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes redeNodeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.animate-rede-tab-in {
  animation: redeTabIn 0.35s ease-out forwards;
}

.animate-rede-node-in {
  animation: redeNodeIn 0.4s ease-out forwards;
}

/* Landing SaaS: animações de entrada e fundo hero */
@keyframes heroGradientShift {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}
@keyframes fadeUpIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
.animate-hero-bg {
  animation: heroGradientShift 8s ease-in-out infinite;
}
/* both = aplica estado inicial durante o delay, evita flash */
.animate-fade-up-in {
  animation: fadeUpIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.animate-scale-in {
  animation: scaleIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@media (prefers-reduced-motion: reduce) {
  .animate-hero-bg,
  .animate-fade-up-in,
  .animate-scale-in,
  .animate-fade-up,
  .animate-float {
    animation: none !important;
  }
}

/* PWA safe areas for mobile */
.safe-bottom {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Horizontal scroll suave no mobile (abas, etc.) */
.scroll-touch {
  -webkit-overflow-scrolling: touch;
}

/* Esconde scrollbar mantendo rolagem (menu sidebar: completo sem barra rolagem) */
.scrollbar-none {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.scrollbar-none::-webkit-scrollbar {
  display: none;
}

.safe-top {
  padding-top: env(safe-area-inset-top, 0px);
}

/* Mobile scroll optimization */
@media (max-width: 767px) {
  .mobile-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
}

/* Funil de tráfego: formato trapezoidal (evita “torto” no mobile) */
.clip-path-funnel-1 { clip-path: polygon(0 0, 100% 0, 96% 100%, 4% 100%); }
.clip-path-funnel-2 { clip-path: polygon(0 0, 100% 0, 92% 100%, 8% 100%); }
.clip-path-funnel-3 { clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%); }
.clip-path-funnel-4 { clip-path: polygon(0 0, 100% 0, 82% 100%, 18% 100%); }

/* Canvas React Flow: botões +/- do zoom visíveis no tema claro/escuro */
.react-flow__controls button {
  background: hsl(var(--card)) !important;
  color: hsl(var(--foreground)) !important;
  border: 1px solid hsl(var(--border)) !important;
  fill: hsl(var(--foreground));
}
.react-flow__controls button:hover {
  background: hsl(var(--muted)) !important;
}
.react-flow__controls button:disabled {
  opacity: 0.5;
}

/* Layout: #root é tela cheia por padrão; App.tsx adiciona .app-boxed só nas rotas do app (dashboard, auth, etc.). */

@layer utilities {
  .bg-dotted-grid {
    background-image: radial-gradient(circle, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
    background-size: 24px 24px;
  }
  
  .dark .bg-dotted-grid {
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  }
  
  .glass-card {
    @apply bg-white/70 dark:bg-black/40 backdrop-blur-xl border border-black/5 dark:border-white/10 rounded-[32px] transition-all duration-300;
  }

  .glass-input {
    @apply bg-white/5 backdrop-blur-md border border-white/10 rounded-full px-6 py-4 focus:ring-2 focus:ring-blue-500/50 outline-none transition-all duration-300;
  }
  
  .text-glow-blue {
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
  }
  
  .text-glow-blue-light {
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
  }

  /* Orbital Timeline utilities */
  .shadow-orbital {
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
  }

  .scale-125 {
    transform: scale(1.25);
  }

  .scale-150 {
    transform: scale(1.5);
  }

  .opacity-70 {
    opacity: 0.7;
  }

  .opacity-50 {
    opacity: 0.5;
  }
}

/* Animations for Orbital Timeline */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* Base custom utility wrappers */
.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ─── Database with REST API Animations ─── */
.database {
  offset-anchor: 10px 0px;
  animation: database-animation-path;
  animation-iteration-count: infinite;
  animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  animation-duration: 4s;
  animation-delay: 1s;
  will-change: transform, offset-distance; /* Force GPU layer for non-composited animation */
  transform: translateZ(0);
}

.db-light-1 {
  offset-path: path("M 31 10 v 15 q 0 5 5 5 h 59 q 5 0 5 5 v 25");
}

.db-light-2 {
  offset-path: path("M 77 10 v 10 q 0 5 5 5 h 13 q 5 0 5 5 v 25");
}

.db-light-3 {
  offset-path: path("M 124 10 v 10 q 0 5 -5 5 h -14 q -5 0 -5 5 v 25");
}

.db-light-4 {
  offset-path: path("M 170 10 v 15 q 0 5 -5 5 h -60 q -5 0 -5 5 v 25");
}

@keyframes database-animation-path {
  0% {
    offset-distance: 0%;
  }
  100% {
    offset-distance: 100%;
  }
}

.animate-ping {
  animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* ─── MenuBar Animations (Premium Bottom Menu) ─── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tooltip-content {
  display: inline-block;
  white-space: nowrap;
}

.tooltip-content-wrapper {
  position: relative;
  height: 16px;
  overflow: hidden;
  animation: fadeIn 150ms ease-out;
}

.tooltip-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  opacity: 1;
  transform: translateY(0);
  transition: all 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-state='closed'] {
  opacity: 0;
  transition: opacity 150ms ease-out;
}

[data-state='open'] {
  opacity: 1;
  transition: opacity 150ms ease-out, width 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(-100%);
    opacity: 0;
  }
}

.tooltip-content.slide-in {
  animation: slideIn 150ms ease-out;
}

.tooltip-content.slide-out {
  animation: slideOut 150ms ease-out;
}

@keyframes slideInUp {
  from {
    transform: translateY(-5px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.tooltip-animation {
  animation: fadeIn 0.3s ease-in-out, slideInUp 0.3s ease-in-out;
}
