/**
 * Balance Flow Chart — Styles & Animations
 * Marquee financial visualization: Income → Balance → Spending
 */

/* ─── Card Container ─── */

.balance-flow-card {
  background: var(--brokerly-card-background, #ffffff);
  border-radius: var(--radius-lg, 16px);
  padding: 20px;
  margin-bottom: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.2s ease;
  overflow: hidden;
}

.balance-flow-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ─── Chart Wrapper ─── */

.bf-chart-wrapper {
  position: relative;
  width: 100%;
  margin-bottom: 16px;
}

.bf-svg {
  width: 100%;
  height: auto;
  display: block;
  cursor: default;
}

/* ─── Flow Ribbons ─── */

.bf-flow-ribbon {
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.6s ease, filter 0.25s ease;
}

.bf-svg.bf-animated .bf-flow-ribbon {
  opacity: 0.82;
}

.bf-flow-ribbon.bf-highlighted {
  opacity: 1 !important;
  filter: brightness(1.12) saturate(1.1);
}

.bf-flow-ribbon.bf-dimmed {
  opacity: 0.12 !important;
  filter: grayscale(0.6) blur(1.2px);
  transition: opacity 0.25s ease, filter 0.25s ease;
}

/* ─── Labels ─── */

.bf-label {
  opacity: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  transition: opacity 0.5s ease;
  cursor: pointer;
}

.bf-svg.bf-animated .bf-label {
  opacity: 1;
}

.bf-label-name {
  font-size: 12.5px;
  font-weight: 600;
}

.bf-label-amount {
  font-size: 11.5px;
  font-weight: 500;
}

.bf-label-dim {
  opacity: 0.25 !important;
  filter: blur(0.8px);
  transition: opacity 0.25s ease, filter 0.25s ease;
}

.bf-side-label {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.5s ease 0.5s;
}

.bf-svg.bf-animated .bf-side-label {
  opacity: 0.5;
}

/* ─── Center Node ─── */

.bf-center-group {
  transform-origin: 480px 270px;
  transform: scale(0);
  transition: transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s;
}

.bf-svg.bf-animated .bf-center-group {
  transform: scale(1);
}

.bf-account-node {
  transition: opacity 0.25s ease, filter 0.25s ease;
}

.bf-account-node.bf-dimmed-acct {
  opacity: 0.15 !important;
  filter: grayscale(0.5) blur(1.5px);
}

.bf-account-seg {
  transition: filter 0.2s ease;
}

.bf-account-node:hover .bf-account-seg {
  filter: brightness(1.15);
}

/* Glow ring removed */

.bf-balance-amount {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.bf-balance-label {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

/* ─── Particles ─── */

.bf-particle {
  opacity: 0;
  transition: opacity 0.3s ease 1s;
}

.bf-svg.bf-animated .bf-particle {
  opacity: 0.75;
}

.bf-svg.bf-highlight-active .bf-particle {
  transition: opacity 0.2s ease !important;
}

/* ─── Tooltip ─── */

.bf-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  transform: translateY(-50%);
  animation: bf-tooltip-in 0.15s ease;
}

.bf-tooltip[hidden] {
  display: none;
}

.bf-tooltip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bf-tooltip-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bf-tooltip-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
}

.bf-tooltip-amount {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
}

.bf-tooltip-pct {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
}

/* ─── Summary Row ─── */

.bf-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 4px;
  gap: 12px;
}

.bf-summary-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

.bf-summary-icon {
  font-size: 11px;
  opacity: 0.6;
}

.bf-summary-label {
  color: var(--brokerly-text-secondary, #666);
  font-weight: 500;
}

.bf-summary-value {
  font-weight: 700;
  font-size: 14px;
  color: var(--brokerly-text-primary, #1f2937);
}

.bf-summary-value.income {
  color: #10b981;
}

.bf-summary-value.expense {
  color: #ef4444;
}

.bf-net-summary.positive .bf-summary-value {
  color: #10b981;
}

.bf-net-summary.negative .bf-summary-value {
  color: #ef4444;
}

.bf-net-summary {
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.08);
}

.bf-net-summary.negative {
  background: rgba(239, 68, 68, 0.08);
}

/* ─── Animations ─── */

/* Pulse glow animation removed */

@keyframes bf-tooltip-in {
  from { opacity: 0; transform: translateY(-50%) scale(0.95); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}

/* ─── Dark Mode ─── */

:root[data-theme="dark"] .balance-flow-card,
.dark-mode .balance-flow-card {
  background: var(--brokerly-card-background, #1c1c1e);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

:root[data-theme="dark"] .balance-flow-card:hover,
.dark-mode .balance-flow-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

:root[data-theme="dark"] .bf-tooltip,
.dark-mode .bf-tooltip {
  background: rgba(30, 30, 34, 0.95);
}

:root[data-theme="dark"] .bf-summary-value,
.dark-mode .bf-summary-value {
  color: var(--brokerly-text-primary, #e5e7eb);
}

:root[data-theme="dark"] .bf-summary-label,
.dark-mode .bf-summary-label {
  color: var(--brokerly-text-secondary, #9ca3af);
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .balance-flow-card {
    padding: 14px;
  }

  .bf-summary-row {
    flex-direction: column;
    gap: 8px;
    padding: 8px 4px 0;
  }

  .bf-summary-item {
    width: 100%;
    justify-content: center;
  }

  .bf-label-name {
    font-size: 11px;
  }

  .bf-label-amount {
    font-size: 9.5px;
  }
}

@media (max-width: 480px) {
  .balance-flow-card {
    padding: 10px;
  }

  .bf-label-name {
    font-size: 10px;
  }

  .bf-label-amount {
    font-size: 9px;
  }
}

/* ─── Values Hidden Mode for SVG Text ─── */

body.values-hidden tspan[data-financial-value],
body.values-hidden text[data-financial-value] {
  fill: transparent !important;
  text-shadow: 0 0 6px rgba(100, 116, 139, 0.8) !important;
  filter: none !important;
}

:root[data-theme="dark"] body.values-hidden tspan[data-financial-value],
:root[data-theme="dark"] body.values-hidden text[data-financial-value],
.dark-mode body.values-hidden tspan[data-financial-value],
.dark-mode body.values-hidden text[data-financial-value] {
  text-shadow: 0 0 6px rgba(156, 163, 175, 0.8) !important;
}

/* ─── Expand / Minimize Button ─── */

.balance-flow-container .section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.bf-expand-btn {
  background: transparent;
  border: none;
  color: var(--brokerly-text-secondary, #64748b);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.bf-expand-btn:hover {
  background: var(--brokerly-bg-secondary, rgba(0, 0, 0, 0.05));
  color: var(--brokerly-text-primary, #1e293b);
}

:root[data-theme="dark"] .bf-expand-btn:hover,
.dark-mode .bf-expand-btn:hover {
  background: var(--brokerly-bg-secondary, rgba(255, 255, 255, 0.08));
  color: var(--brokerly-text-primary, #f8fafc);
}

/* ─── Fullscreen Expanded Layout ─── */

/* Wrapper container overlay */
#balance-flow-section.bf-expanded {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 24px;
  overscroll-behavior: contain !important;
}

#balance-flow-section.bf-expanded .balance-flow-container {
  width: 100%;
  max-width: 1280px;
  height: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--brokerly-card-background, #ffffff);
  border-radius: 24px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  padding: 24px 32px 32px;
  box-sizing: border-box;
  animation: bf-modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

#balance-flow-section.bf-expanded .balance-flow-card {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
  background: transparent;
}

#balance-flow-section.bf-expanded .bf-chart-wrapper {
  flex-grow: 1;
  height: 0;
  min-height: 0;
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#balance-flow-section.bf-expanded .bf-svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

#balance-flow-section.bf-expanded .bf-summary-row {
  padding: 16px 8px 0;
  border-top: 1px solid var(--brokerly-border, rgba(0, 0, 0, 0.06));
}

:root[data-theme="dark"] #balance-flow-section.bf-expanded .bf-summary-row,
.dark-mode #balance-flow-section.bf-expanded .bf-summary-row {
  border-top-color: var(--brokerly-border, rgba(255, 255, 255, 0.08));
}

/* Modal entry animation */
@keyframes bf-modal-in {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── Spend Analysis Fullscreen Overlay ─── */

.spend-analysis-modal-content {
  display: contents;
}

.spend-analysis-wrapper-card.widget-expanded-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 10000 !important;
  background: rgba(15, 23, 42, 0.55) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  padding: 24px !important;
  margin: 0 !important;
  gap: 0 !important;
  overscroll-behavior: contain !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-modal-content {
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  max-width: 1080px !important;
  height: 100% !important;
  max-height: 90vh !important;
  background: var(--brokerly-card-background, #ffffff) !important;
  border-radius: 24px !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4) !important;
  padding: 24px 32px 32px !important;
  box-sizing: border-box !important;
  animation: bf-modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  overflow: hidden !important;
  gap: 16px !important;
  touch-action: auto !important;
}

/* Adjust the header inside modal */
.spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-header {
  border-bottom: 1px solid var(--brokerly-border, rgba(0, 0, 0, 0.06)) !important;
  padding-bottom: 16px !important;
  width: 100% !important;
  flex-shrink: 0 !important;
}

/* Adjust the cash flow card (inner container) inside modal */
.spend-analysis-wrapper-card.widget-expanded-overlay .cash-flow-card {
  flex-grow: 1 !important;
  height: 0 !important;
  min-height: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .cash-flow-chart-container {
  flex-grow: 1 !important;
  height: 100% !important;
  min-height: 0 !important;
  width: 100% !important;
}

/* Dark mode overrides for Spend Analysis Expanded Overlay */
:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-modal-content,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-modal-content {
  background: var(--brokerly-card-background, #1c1c1e) !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.55) !important;
}

:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-header,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-header {
  border-bottom-color: var(--brokerly-border, rgba(255, 255, 255, 0.08)) !important;
}

/* ─── Table Modal Specific Overrides ─── */

.spend-analysis-wrapper-card.widget-expanded-overlay .money-section.collapsible {
  flex-grow: 1 !important;
  height: 0 !important;
  min-height: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .collapsible-header {
  display: none !important; /* Hide collapse toggle header inside modal */
}

.spend-analysis-wrapper-card.widget-expanded-overlay .collapsible-content.expanded {
  max-height: none !important;
  display: flex !important;
  flex-direction: column !important;
  flex-grow: 1 !important;
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .table-header {
  flex-shrink: 0 !important;
  width: 100% !important;
  display: flex !important;
  padding: 12px 16px !important;
  background: transparent !important;
  border-bottom: none !important;
  box-sizing: border-box !important;
}

:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .table-header,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .table-header {
  background: transparent !important;
  border-bottom: none !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .table-rows-container {
  flex-grow: 1 !important;
  overflow-y: auto !important;
  height: 100% !important;
  min-height: 0 !important;
  padding: 8px 16px !important;
  box-sizing: border-box !important;
  overscroll-behavior: contain !important;
}

/* Row polish inside expanded modal */
.spend-analysis-wrapper-card.widget-expanded-overlay .expense-row,
.spend-analysis-wrapper-card.widget-expanded-overlay .transaction-row {
  padding: 14px 16px !important;
  border-bottom: none !important;
  border-radius: 12px !important;
  margin-bottom: 8px !important;
  background-color: var(--brokerly-bg-secondary, rgba(128, 128, 128, 0.05)) !important;
  transition: background-color 0.2s ease, transform 0.2s ease !important;
  box-sizing: border-box !important;
  cursor: pointer !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .expense-row:hover,
.spend-analysis-wrapper-card.widget-expanded-overlay .transaction-row:hover {
  background-color: var(--brokerly-bg-tertiary, rgba(128, 128, 128, 0.1)) !important;
  transform: translateX(3px) !important;
}

:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .expense-row:hover,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .expense-row:hover,
:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .transaction-row:hover,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .transaction-row:hover {
  background-color: rgba(255, 255, 255, 0.05) !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .sort-controls {
  padding: 8px 16px !important;
  border-bottom: none !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .sort-controls,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .sort-controls {
  border-bottom: none !important;
}

.spend-analysis-wrapper-card.widget-expanded-overlay .section-header {
  border-bottom: none !important;
  padding-bottom: 8px !important;
  width: 100% !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

:root[data-theme="dark"] .spend-analysis-wrapper-card.widget-expanded-overlay .section-header,
.dark-mode .spend-analysis-wrapper-card.widget-expanded-overlay .section-header {
  border-bottom: none !important;
}

/* Prevent background scrolling when modal is open */
html:has(body.modal-open),
html.modal-open,
body.modal-open {
  overflow: hidden !important;
  height: 100vh !important;
  max-height: 100vh !important;
}

body.modal-open .view,
body.modal-open .view-content {
  overflow-y: hidden !important;
  touch-action: none !important;
}
