/* ============================================================================
   DINDIN AI — PREMIUM FINTECH DESIGN SYSTEM
   Palette:
     Deep Black:    #09090D
     Graphite:      #12131A
     Surface:       #191B24
     Elevated:      #222530
     White:         #F7F7FB
     Gray:          #A5A8B5
     Primary:       #8050F5
     Light Purple:  #A47BFF
     Income Green:  #25D987
     Expense Red:   #FF626C
     Comp. Blue:    #528CFF
   ============================================================================ */

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

:root,
.dark {
  --dd-bg-deep: #09090D;
  --dd-bg-graphite: #12131A;
  --dd-surface: #191B24;
  --dd-surface-elevated: #222530;
  --dd-text-primary: #F7F7FB;
  --dd-text-secondary: #A5A8B5;
  --dd-purple: #8050F5;
  --dd-purple-light: #A47BFF;
  --dd-green: #25D987;
  --dd-red: #FF626C;
  --dd-blue: #528CFF;

  /* Override Tailwind / Shadcn CSS Variables */
  --background: 240 18% 4%;
  --foreground: 240 33% 98%;
  --card: 230 18% 12%;
  --card-foreground: 240 33% 98%;
  --popover: 229 17% 16%;
  --popover-foreground: 240 33% 98%;
  --primary: 257 89% 64%;
  --primary-foreground: 240 33% 98%;
  --primary-glow: 258 100% 74%;
  --secondary: 220 100% 66%;
  --secondary-foreground: 240 33% 98%;
  --muted: 229 17% 16%;
  --muted-foreground: 228 11% 68%;
  --accent: 257 89% 64% / 0.14;
  --accent-foreground: 258 100% 74%;
  --success: 153 70% 50%;
  --success-foreground: 240 18% 4%;
  --danger: 356 100% 69%;
  --danger-foreground: 240 33% 98%;
  --destructive: 356 100% 69%;
  --destructive-foreground: 240 33% 98%;
  --border: 230 16% 20%;
  --input: 230 16% 20%;
  --ring: 257 89% 64%;
  --radius: 1rem;

  --sidebar-background: 232 19% 9%;
  --sidebar-foreground: 240 33% 98%;
  --sidebar-primary: 257 89% 64%;
  --sidebar-primary-foreground: 240 33% 98%;
  --sidebar-accent: 257 89% 64% / 0.14;
  --sidebar-accent-foreground: 258 100% 74%;
  --sidebar-border: 230 16% 18%;
  --sidebar-ring: 257 89% 64%;
}

/* Base Typography & Canvas */
html,
body {
  background-color: var(--dd-bg-deep) !important;
  color: var(--dd-text-primary) !important;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
  overscroll-behavior-y: none !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
.font-display {
  font-family: 'Plus Jakarta Sans', 'Manrope', 'Inter', sans-serif !important;
  letter-spacing: -0.02em;
}

.tabular-nums {
  font-family: 'Manrope', 'Inter', sans-serif !important;
  font-variant-numeric: tabular-nums;
}

::selection {
  background-color: rgba(128, 80, 245, 0.32) !important;
  color: #F7F7FB !important;
}

/* Subtle Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--dd-bg-deep);
}

::-webkit-scrollbar-thumb {
  background: rgba(128, 80, 245, 0.35);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(164, 123, 255, 0.65);
}

/* ============================================================================
   SURFACE & CARD HIERARCHY (NO HEAVY BORDERS OR EXCESS NEON)
   ============================================================================ */
.bg-card,
[class*="rounded-xl"][class*="border"],
[class*="rounded-2xl"][class*="border"] {
  background-color: var(--dd-surface) !important;
  border-color: rgba(247, 247, 251, 0.06) !important;
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, 0.45);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.22s ease,
    box-shadow 0.22s ease;
}

.bg-card:hover {
  border-color: rgba(164, 123, 255, 0.16) !important;
}

/* Semantic Income & Expense Colors */
.text-emerald-400.tabular-nums,
.text-emerald-500.tabular-nums,
.text-green-400,
.text-green-500,
.text-success,
.dd-income-value {
  color: var(--dd-green) !important;
}

.text-red-400,
.text-red-500,
.text-rose-400,
.text-rose-500,
.text-danger,
.dd-expense-value {
  color: var(--dd-red) !important;
}

/* Primary Buttons (scoped strictly to buttons/links, never containers) */
button.bg-primary,
a.bg-primary {
  background: linear-gradient(135deg, #8050F5 0%, #6838E8 100%) !important;
  color: #F7F7FB !important;
  border: 1px solid rgba(164, 123, 255, 0.28) !important;
  box-shadow: 0 8px 24px -6px rgba(128, 80, 245, 0.45);
}

button.bg-primary:hover,
a.bg-primary:hover {
  background: linear-gradient(135deg, #8F63FF 0%, #7846F4 100%) !important;
  box-shadow: 0 10px 28px -4px rgba(128, 80, 245, 0.58);
  transform: translateY(-1px);
}

/* Native AI Assistant Panel — clean dark fintech surface & readable pills */
[data-dd-ai-panel="1"] {
  background: linear-gradient(180deg, #161822 0%, #0F1016 100%) !important;
  border: 1px solid rgba(164, 123, 255, 0.24) !important;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.72) !important;
  color: #F7F7FB !important;
}

[data-dd-ai-panel="1"] .text-muted-foreground {
  color: #A5A8B5 !important;
}

[data-dd-ai-panel="1"] button[class*="rounded-full"][class*="bg-primary/10"],
[data-dd-ai-panel="1"] button.px-3.py-1\.5 {
  background: rgba(128, 80, 245, 0.16) !important;
  border: 1px solid rgba(164, 123, 255, 0.3) !important;
  color: #E4D9FF !important;
}

[data-dd-ai-panel="1"] button[class*="rounded-full"][class*="bg-primary/10"]:hover,
[data-dd-ai-panel="1"] button.px-3.py-1\.5:hover {
  background: rgba(128, 80, 245, 0.28) !important;
  color: #FFFFFF !important;
}

/* ============================================================================
   DASHBOARD — PREMIUM BALANCE, INCOME & EXPENSE CARDS
   ============================================================================ */
.dd-balance-hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(120% 100% at 100% 0%, rgba(164, 123, 255, 0.22) 0%, rgba(128, 80, 245, 0.08) 42%, transparent 72%),
    linear-gradient(145deg, #1E1933 0%, #151622 55%, #12131A 100%) !important;
  border: 1px solid rgba(164, 123, 255, 0.22) !important;
  box-shadow: 0 20px 48px -16px rgba(128, 80, 245, 0.28) !important;
}

.dd-balance-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 20%, rgba(128, 80, 245, 0.14), transparent 50%);
  pointer-events: none;
}

.dd-income-card {
  background: linear-gradient(155deg, rgba(37, 217, 135, 0.08) 0%, #191B24 65%) !important;
  border: 1px solid rgba(37, 217, 135, 0.16) !important;
}

.dd-expense-card {
  background: linear-gradient(155deg, rgba(255, 98, 108, 0.08) 0%, #191B24 65%) !important;
  border: 1px solid rgba(255, 98, 108, 0.16) !important;
}

.dd-privacy-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(247, 247, 251, 0.06);
  border: 1px solid rgba(247, 247, 251, 0.1);
  color: var(--dd-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dd-privacy-toggle:hover {
  background: rgba(128, 80, 245, 0.18);
  color: var(--dd-text-primary);
  border-color: rgba(164, 123, 255, 0.35);
}

.dd-masked-value {
  filter: blur(8px);
  user-select: none !important;
  transition: filter 0.25s ease;
}

/* Recharts Tooltips & Polish */
.recharts-default-tooltip {
  background-color: rgba(25, 27, 36, 0.96) !important;
  border: 1px solid rgba(164, 123, 255, 0.24) !important;
  border-radius: 12px !important;
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5) !important;
  color: var(--dd-text-primary) !important;
}

.recharts-cartesian-grid-horizontal line,
.recharts-cartesian-grid-vertical line {
  stroke: rgba(247, 247, 251, 0.06) !important;
}

/* ============================================================================
   DESKTOP SIDEBAR (COLLAPSIBLE & REFINED)
   ============================================================================ */
@media (min-width: 768px) {

  aside,
  [data-sidebar="sidebar"] {
    background-color: var(--dd-bg-graphite) !important;
    border-right: 1px solid rgba(247, 247, 251, 0.06) !important;
    transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1) !important;
  }

  body.dd-sidebar-collapsed aside {
    width: 76px !important;
    min-width: 76px !important;
  }

  body.dd-sidebar-collapsed aside nav a span,
  body.dd-sidebar-collapsed aside button span,
  body.dd-sidebar-collapsed .dd-sidebar-label {
    display: none !important;
  }

  body.dd-sidebar-collapsed main,
  body.dd-sidebar-collapsed .md\:pl-64 {
    padding-left: 76px !important;
    transition: padding-left 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

.dd-sidebar-collapse-btn {
  position: fixed;
  top: 18px;
  left: 236px;
  z-index: 60;
  width: 28px;
  height: 28px;
  border-radius: 9999px;
  background: var(--dd-surface-elevated);
  border: 1px solid rgba(164, 123, 255, 0.28);
  color: var(--dd-text-primary);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: left 0.28s cubic-bezier(0.22, 1, 0.36, 1), transform 0.2s ease, background 0.2s ease;
}

@media (min-width: 768px) {
  .dd-sidebar-collapse-btn.is-visible {
    display: flex;
  }

  body.dd-sidebar-collapsed .dd-sidebar-collapse-btn {
    left: 62px;
    transform: rotate(180deg);
  }
}

/* ============================================================================
   MOBILE BOTTOM NAVIGATION + "MAIS" SHEET
   ============================================================================ */
@media (max-width: 767px) {

  html,
  body {
    max-width: 100vw;
    min-height: 100%;
    min-height: 100lvh;
    overflow-x: clip !important;
  }

  #root {
    max-width: 100vw;
    overflow-x: clip !important;
  }

  /* Only hide the NATIVE React bottom nav when our upgraded nav is active */
  body.dd-mobile-nav-ready nav.fixed.bottom-0:not(#dd-mobile-bottom-nav) {
    display: none !important;
  }

  /* Extra bottom padding so last card is not hidden behind bottom nav
     — only on the scrollable main content area, not globally */
  #root>div>main,
  #root>main {
    padding-top: 0 !important;
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 20px)) !important;
  }

  /* Only force single column on CARD grids (not tab grids, calendar grids, etc.) */
  .dd-income-card~* .grid.grid-cols-2,
  section .grid.grid-cols-2:not([data-tabs]):not([role="grid"]):not([data-calendar]) {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* Tablists on mobile: scroll horizontally cleanly instead of breaking layout */
  [role="tablist"] {
    max-width: 100% !important;
    overflow-x: auto !important;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  [role="tablist"]::-webkit-scrollbar {
    display: none;
  }

  /* Keep primary CTA buttons comfortable to tap without breaking calendar/tab/icon buttons */
  .dd-btn-primary,
  .dd-btn-secondary,
  #dd-mobile-bottom-nav button {
    min-height: 44px;
  }
}

#dd-mobile-bottom-nav {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  margin: 0 !important;
  z-index: 999 !important;
  background: rgba(18, 19, 26, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(247, 247, 251, 0.08);
  /* Use padding-bottom to absorb safe-area — no fixed height so it shrink-wraps */
  padding: 6px 8px 0 !important;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 14px)) !important;
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
  /* Prevent index.html PATCH from forcing a conflicting height */
  height: auto !important;
  min-height: 60px;
  /* Override PATCH 7 background, transform and other conflicts */
  background: rgba(18, 19, 26, 0.97) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  transform: none !important;
}

/* Fill any iOS PWA bottom safe-area gap below fixed bottom:0 */
#dd-mobile-bottom-nav::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 48px;
  background: rgba(18, 19, 26, 0.97);
  pointer-events: none;
}

@media (min-width: 768px) {
  #dd-mobile-bottom-nav {
    display: none !important;
  }
}

.dd-bottom-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 58px;
  min-height: 46px;
  padding: 4px 8px;
  border-radius: 12px;
  color: var(--dd-text-secondary);
  font-size: 11px;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.dd-bottom-item.is-active {
  color: var(--dd-purple-light);
  background: rgba(128, 80, 245, 0.14);
  font-weight: 600;
}

.dd-bottom-item:active {
  transform: scale(0.94);
}

/* Mobile "Mais" Drawer Sheet */
#dd-more-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(9, 9, 13, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

#dd-more-sheet-backdrop.is-open {
  display: flex;
}

#dd-more-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--dd-bg-graphite);
  border-top: 1px solid rgba(164, 123, 255, 0.2);
  border-radius: 24px 24px 0 0;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.65);
  animation: ddSheetUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ddSheetUp {
  from {
    transform: translateY(100%);
    opacity: 0.4;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.dd-more-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.dd-more-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-radius: 14px;
  background: var(--dd-surface);
  border: 1px solid rgba(247, 247, 251, 0.06);
  color: var(--dd-text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.dd-more-link:hover {
  background: var(--dd-surface-elevated);
  border-color: rgba(164, 123, 255, 0.28);
}

/* ============================================================================
   RADIX DIALOG — only TRUE modal dialogs (not popovers, calendars, dropdowns)
   ============================================================================ */

/* Real dialog modals */
[data-radix-dialog-content] {
  background-color: var(--dd-bg-graphite) !important;
  border: 1px solid rgba(164, 123, 255, 0.18) !important;
  max-height: 92dvh !important;
  max-width: calc(100vw - 16px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.72) !important;
}

/* Popovers (Calendar, Dropdowns, Selects) */
[data-radix-popper-content-wrapper],
[data-radix-select-content],
[data-radix-dropdown-menu-content],
[data-radix-popover-content] {
  z-index: 9999 !important;
  overflow: visible !important;
  max-height: none !important;
}

[data-radix-popover-content],
[data-radix-select-content],
[data-radix-dropdown-menu-content] {
  background-color: var(--dd-bg-graphite) !important;
  border: 1px solid rgba(164, 123, 255, 0.22) !important;
  border-radius: 14px !important;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75) !important;
}

/* Calendar inside popover — remove stray background */
[data-radix-popover-content] .rdp,
[data-radix-popover-content] table,
[data-radix-popover-content] [role="grid"] {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  max-height: none !important;
  overflow: visible !important;
}

/* ============================================================================
   MOBILE CALENDAR FIX — keep Radix Popper functional and fit viewport cleanly
   ============================================================================ */
@media (max-width: 767px) {
  [data-radix-popper-content-wrapper] {
    max-width: calc(100vw - 16px) !important;
    z-index: 10000 !important;
  }

  [data-radix-popover-content] {
    max-width: calc(100vw - 24px) !important;
    width: auto !important;
    max-height: 68dvh !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    box-sizing: border-box !important;
  }

  [data-radix-popover-content] .rdp {
    margin: 0 auto !important;
    padding: 6px !important;
  }

  [data-radix-popover-content] .rdp-months {
    flex-direction: column !important;
    gap: 12px !important;
  }

  [data-radix-popover-content] .rdp-cell,
  [data-radix-popover-content] .rdp-head_cell {
    width: 36px !important;
    height: 36px !important;
    padding: 1px !important;
  }

  [data-radix-popover-content] .rdp-day {
    width: 34px !important;
    height: 34px !important;
    font-size: 13px !important;
  }
}

/* ============================================================================
   MOBILE FAB FIX — push floating action buttons above bottom nav
   ============================================================================ */
@media (max-width: 767px) {
  /* Push ALL fixed FAB-style buttons above our bottom nav (72px + safe-area) */
  button.fixed[class*="bottom-"],
  div.fixed[class*="bottom-"],
  a.fixed[class*="bottom-"] {
    bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Specifically target the + add button and sparkle AI button */
  button.fixed[class*="bottom-32"],
  button.fixed[class*="bottom-20"],
  button.fixed[class*="bottom-16"],
  div.fixed[class*="bottom-32"],
  div.fixed[class*="bottom-20"],
  div.fixed[class*="bottom-16"] {
    bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Do NOT move the bottom nav itself */
  #dd-mobile-bottom-nav {
    bottom: 0 !important;
  }
}

/* ============================================================================
   ANIMATED PROGRESS BARS (GOALS & PROJECTS)
   ============================================================================ */
[role="progressbar"]>div {
  background: linear-gradient(90deg, #8050F5 0%, #25D987 100%) !important;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

/* ============================================================================
   ACCESSIBILITY & REDUCED MOTION
   ============================================================================ */
:focus-visible {
  outline: 2px solid var(--dd-purple-light) !important;
  outline-offset: 2px !important;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}