/* ==========================================================================
   FCC Expenses Blueprint Redesign
   Scope: Expenses page only
   Visual source: expenses-redesign-blueprint.png

   Rules:
   - Scope everything under body.fcc-app-shell-v1 #expenses.
   - Do not style unrelated pages.
   - Do not depend on fake data.
   - This file loads after fcc-app-modules-v1.css and wins over legacy CSS.

   Note: the period tabs, summary band, spending trend, spending-by-category
   and budget-status widgets are injected into #fcc-expense-dashboard-root by
   expense-charts-ui.js as .fcc-ec-* elements (styled blue/dark-navy by
   expense-charts.css). We do NOT touch that JS; we re-skin those elements to
   the lavender/pink blueprint palette here with higher-specificity scoped
   overrides so the page reads as one cohesive design.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens + containment
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses {
  --fcc-expense-violet: #7c3aed;
  --fcc-expense-violet-2: #8b5cf6;
  --fcc-expense-pink: #ec4899;
  --fcc-expense-rose: #fce7f3;
  --fcc-expense-lavender: #f4ebff;
  --fcc-expense-ink: #17132f;
  --fcc-expense-muted: #6f6a8a;
  --fcc-expense-border: rgba(124, 58, 237, 0.14);
  --fcc-expense-border-strong: rgba(168, 85, 247, 0.24);
  --fcc-expense-card: rgba(255, 255, 255, 0.92);
  --fcc-expense-shadow: 0 20px 60px rgba(83, 45, 128, 0.10), 0 3px 12px rgba(17, 12, 46, 0.05);

  min-width: 0;
  overflow-x: hidden;
  color: var(--fcc-expense-ink);
}

body.fcc-app-shell-v1 #expenses,
body.fcc-app-shell-v1 #expenses * {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Hero header — plain header on the page background (no card), matching the
   blueprint: dark bold title + muted subtitle on the left, gradient pill
   "+ Add Expense" action on the right. Overrides the shared .fcc-page-hero
   gradient card + gradient title-fill.
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .fcc-expenses-hero {
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 2px 2px 0;
  margin: 0 0 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

body.fcc-app-shell-v1 #expenses .fcc-expenses-hero .fcc-page-hero-title {
  margin: 0;
  background: none;
  -webkit-text-fill-color: currentColor;
  color: var(--fcc-expense-ink);
  font-size: clamp(30px, 3vw, 42px);
  line-height: 1.05;
  letter-spacing: -0.04em;
  font-weight: 850;
}

body.fcc-app-shell-v1 #expenses .fcc-expenses-hero .fcc-page-hero-subtitle {
  margin: 8px 0 0;
  color: var(--fcc-expense-muted);
  font-size: 15px;
  line-height: 1.55;
}

body.fcc-app-shell-v1 #expenses .fcc-expenses-hero .fcc-page-hero-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Hero + form primary actions → violet→pink pill */
body.fcc-app-shell-v1 #expenses .fcc-hero-primary-btn,
body.fcc-app-shell-v1 #expenses .expense-form-actions .btn-primary,
body.fcc-app-shell-v1 #expenses .fcc-ios-button-primary {
  border: 0;
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--fcc-expense-violet), var(--fcc-expense-pink));
  box-shadow: 0 14px 30px rgba(168, 85, 247, 0.28);
}

/* --------------------------------------------------------------------------
   Top three-card grid: Add Expense / Category Manager / Budget Snapshot
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .expenses-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) minmax(320px, 0.92fr);
  gap: 22px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  margin: 0 0 22px;
}

/* Critical regression guard: the empty category-merge host must not consume a
   grid slot (would push Add Expense into column 2 and leave a blank cell). */
body.fcc-app-shell-v1 #expenses .expenses-layout > [data-fcc-category-merge-panel-host]:empty {
  display: none !important;
}
/* When the merge host is populated it spans its own full-width row. */
body.fcc-app-shell-v1 #expenses .expenses-layout > [data-fcc-category-merge-panel-host] {
  grid-column: 1 / -1;
}

/* --------------------------------------------------------------------------
   Cards — top-grid cards + the bottom section cards (history / expense list)
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .expenses-layout > .section-card,
body.fcc-app-shell-v1 #expenses > .section-card,
body.fcc-app-shell-v1 #expenses .expense-form-card,
body.fcc-app-shell-v1 #expenses .expense-category-card,
body.fcc-app-shell-v1 #expenses .expense-summary-card {
  min-width: 0;
  background: var(--fcc-expense-card);
  border: 1px solid var(--fcc-expense-border);
  border-radius: 26px;
  box-shadow: var(--fcc-expense-shadow);
  backdrop-filter: blur(16px);
}

body.fcc-app-shell-v1 #expenses .expenses-layout > .section-card,
body.fcc-app-shell-v1 #expenses .expense-form-card,
body.fcc-app-shell-v1 #expenses .expense-category-card,
body.fcc-app-shell-v1 #expenses .expense-summary-card {
  padding: clamp(20px, 2vw, 28px);
  align-self: stretch;
}

body.fcc-app-shell-v1 #expenses > .section-card {
  padding: clamp(20px, 2vw, 26px);
}

body.fcc-app-shell-v1 #expenses .expense-card-header {
  margin-bottom: 16px;
}

body.fcc-app-shell-v1 #expenses .section-title {
  margin-top: 0;
  color: var(--fcc-expense-ink);
  font-weight: 850;
  letter-spacing: -0.02em;
}

body.fcc-app-shell-v1 #expenses .expense-card-copy,
body.fcc-app-shell-v1 #expenses .muted {
  color: var(--fcc-expense-muted);
}

/* Budget Snapshot — keep the summary list tidy and the action full-width. */
body.fcc-app-shell-v1 #expenses .expense-summary-actions .btn-secondary {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Form fields
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses label {
  color: rgba(23, 19, 47, 0.74);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.01em;
}

body.fcc-app-shell-v1 #expenses input,
body.fcc-app-shell-v1 #expenses select,
body.fcc-app-shell-v1 #expenses textarea {
  border: 1px solid rgba(124, 58, 237, 0.22);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--fcc-expense-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

body.fcc-app-shell-v1 #expenses input:focus,
body.fcc-app-shell-v1 #expenses select:focus,
body.fcc-app-shell-v1 #expenses textarea:focus {
  outline: none;
  border-color: rgba(168, 85, 247, 0.52);
  box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.12);
}

/* --------------------------------------------------------------------------
   Period tabs (JS: .fcc-ec-filter-bar / .fcc-ec-pill) — re-skin blue → violet
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .fcc-ec-filter-bar {
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.12);
  border-radius: 14px;
  margin: 0 0 18px;
}

body.fcc-app-shell-v1 #expenses .fcc-ec-pill {
  color: rgba(23, 19, 47, 0.55);
  font-weight: 800;
}

body.fcc-app-shell-v1 #expenses .fcc-ec-pill:hover:not(.fcc-ec-pill--on) {
  color: rgba(23, 19, 47, 0.78);
  background: rgba(255, 255, 255, 0.6);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-pill--on {
  color: #fff;
  background: linear-gradient(135deg, var(--fcc-expense-violet), var(--fcc-expense-pink));
  box-shadow: 0 8px 20px rgba(168, 85, 247, 0.22);
}

/* --------------------------------------------------------------------------
   Summary band (JS: .fcc-ec-hero) — re-skin dark navy → light lavender/pink
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .fcc-ec-hero {
  border-radius: 26px;
  border: 1px solid rgba(236, 72, 153, 0.16);
  background: linear-gradient(135deg, rgba(250, 245, 255, 0.98), rgba(252, 231, 243, 0.94));
  box-shadow: var(--fcc-expense-shadow);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-hero-glow {
  background: radial-gradient(ellipse at 85% 12%, rgba(236, 72, 153, 0.16) 0%, transparent 60%);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-hero-label {
  color: var(--fcc-expense-muted);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-hero-amount {
  color: var(--fcc-expense-ink);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-hero-meta,
body.fcc-app-shell-v1 #expenses .fcc-ec-budget-of {
  color: var(--fcc-expense-muted);
}

/* Delta chips tuned for a light background (originals were tuned for navy). */
body.fcc-app-shell-v1 #expenses .fcc-ec-delta--up {
  background: rgba(255, 59, 48, 0.12);
  color: #d0291a;
}
body.fcc-app-shell-v1 #expenses .fcc-ec-delta--down {
  background: rgba(52, 199, 89, 0.14);
  color: #1f9d57;
}
body.fcc-app-shell-v1 #expenses .fcc-ec-delta--neutral {
  background: rgba(124, 58, 237, 0.10);
  color: var(--fcc-expense-muted);
}

/* --------------------------------------------------------------------------
   Analytics grid (Spending Trend + Spending by Category) and chart cards
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses .fcc-ec-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 22px;
}

body.fcc-app-shell-v1 #expenses .fcc-ec-card {
  background: var(--fcc-expense-card);
  border: 1px solid var(--fcc-expense-border);
  border-radius: 24px;
  box-shadow: var(--fcc-expense-shadow);
}

body.fcc-app-shell-v1 #expenses .fcc-ec-card-title {
  color: var(--fcc-expense-ink);
  font-weight: 800;
}

body.fcc-app-shell-v1 #expenses .fcc-ec-insight {
  border-radius: 16px;
  border-color: var(--fcc-expense-border);
}

/* --------------------------------------------------------------------------
   Tables (Monthly Budget History + Expense List)
   -------------------------------------------------------------------------- */
body.fcc-app-shell-v1 #expenses table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

body.fcc-app-shell-v1 #expenses thead th {
  color: var(--fcc-expense-violet);
  background: rgba(124, 58, 237, 0.07);
  font-size: 12px;
  text-align: left;
  letter-spacing: 0.01em;
}

body.fcc-app-shell-v1 #expenses tbody td {
  border-top: 1px solid rgba(124, 58, 237, 0.10);
}

body.fcc-app-shell-v1 #expenses .table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1200px) {
  body.fcc-app-shell-v1 #expenses .expenses-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* Add Expense form spans the full first row; the two helper cards share row 2. */
  body.fcc-app-shell-v1 #expenses .expenses-layout > .expense-form-card {
    grid-column: 1 / -1;
  }

  body.fcc-app-shell-v1 #expenses .fcc-ec-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body.fcc-app-shell-v1 #expenses .fcc-expenses-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  body.fcc-app-shell-v1 #expenses .fcc-expenses-hero .fcc-page-hero-actions,
  body.fcc-app-shell-v1 #expenses .fcc-expenses-hero .fcc-page-hero-actions > * {
    width: 100%;
  }

  body.fcc-app-shell-v1 #expenses .expenses-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  body.fcc-app-shell-v1 #expenses .expenses-layout > .expense-form-card {
    grid-column: auto;
  }

  body.fcc-app-shell-v1 #expenses .fcc-ec-filter-bar {
    width: 100%;
    overflow-x: auto;
  }

  body.fcc-app-shell-v1 #expenses input,
  body.fcc-app-shell-v1 #expenses select,
  body.fcc-app-shell-v1 #expenses textarea {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  body.fcc-app-shell-v1 #expenses .expenses-layout > .section-card,
  body.fcc-app-shell-v1 #expenses > .section-card,
  body.fcc-app-shell-v1 #expenses .expense-form-card,
  body.fcc-app-shell-v1 #expenses .expense-category-card,
  body.fcc-app-shell-v1 #expenses .expense-summary-card {
    border-radius: 20px;
    padding: 18px;
  }
}
