/* ════════════════════════════════════════════════════
   BUDGETFLOW — styles.css
   Color Palette: #1f6f5f | #2fa084 | #6fcf97 | #eeeeee
   Font: Inter (all weights)
   ════════════════════════════════════════════════════ */

/* ─── CSS Variables ─── */
:root {
  --clr-primary:     #1f6f5f;
  --clr-secondary:   #2fa084;
  --clr-accent:      #6fcf97;
  --clr-bg:          #eeeeee;
  --clr-surface:     #ffffff;
  --clr-surface-2:   #f7f9f8;
  --clr-border:      rgba(31, 111, 95, 0.12);
  --clr-border-soft: #e2e8e5;
  --clr-text:        #0f2921;
  --clr-text-muted:  #5a7268;
  --clr-text-light:  #9ab5ad;
  --clr-inflow:      #1f6f5f;
  --clr-outflow:     #c0392b;
  --clr-outflow-bg:  #fdf0ef;
  --clr-inflow-bg:   #edf8f4;
  --clr-negative:    #c0392b;
  --clr-warning:     #e67e22;
  --shadow-sm:       0 1px 4px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
  --shadow-md:       0 4px 16px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg:       0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
  --radius-sm:       8px;
  --radius-md:       14px;
  --radius-lg:       20px;
  --radius-xl:       28px;
  --nav-height:      72px;
  --header-height:   auto;
  --font-heading:    'Inter', system-ui, -apple-system, sans-serif;
  --font-body:       'Inter', system-ui, -apple-system, sans-serif;
  --transition:      0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Lock to viewport — scroll lives inside .main-content only */
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--clr-bg);
  color: var(--clr-text);
  /* Flex column: header / content / nav are plain flex items.
     Nothing scrolls at the page level — only .main-content scrolls. */
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  /* Disable long-press text selection everywhere */
  user-select: none;
  -webkit-user-select: none;
  /* Remove the blue tap-highlight rectangle on Android */
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  /* No blue square on tap, no focus ring */
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
input, select, textarea {
  font-family: inherit;
  /* Re-enable selection inside form fields */
  user-select: text;
  -webkit-user-select: text;
}
svg { display: block; }

/* ─── Lucide Icon Base ─── */
[data-lucide] {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.lc-block {
  display: flex;
  align-items: center;
  justify-content: center;
}

.pill-icon [data-lucide] {
  display: inline-block;
  vertical-align: middle;
  opacity: 0.85;
}

/* ─── App Header / Balance ─── */
.app-header {
  background: linear-gradient(160deg, var(--clr-primary) 0%, var(--clr-secondary) 100%);
  color: white;
  padding: 16px 20px 20px;
  /* Flex item — no position:sticky needed; body is flex-column so this
     never moves regardless of what main-content scrolls. */
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(31, 111, 95, 0.30);
  overflow: hidden;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--clr-accent);
  box-shadow: 0 0 0 3px rgba(111, 207, 151, 0.30);
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(111, 207, 151, 0.30); }
  50%       { box-shadow: 0 0 0 6px rgba(111, 207, 151, 0.15); }
}

.brand-name {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: white;
}

.header-date {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.65);
  font-weight: 500;
}

/* ─── Period Mode Tabs ─── */
.period-mode-tabs {
  display: flex;
  background: rgba(0,0,0,0.18);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 16px;
}

.period-mode-btn {
  flex: 1;
  padding: 6px 0;
  border-radius: 9px;
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255,255,255,0.60);
  background: transparent;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}

.period-mode-btn.active {
  background: rgba(255,255,255,0.20);
  color: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.20);
}

/* Balance Card */
.balance-card {
  text-align: center;
  padding: 0;
}

.balance-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.70);
  margin-bottom: 6px;
}

/* ─── Balance Nav Row ─── */
.balance-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 4px;
}

.balance-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.balance-nav-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.22);
}

.balance-nav-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.balance-nav-btn:disabled {
  cursor: default;
}

.balance-amount {
  font-family: var(--font-heading);
  font-size: 2.4rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.04em;
  line-height: 1;
  transition: color var(--transition);
  min-width: 0;
}

.balance-amount.negative {
  color: #ff8a7a;
}

/* ─── Period Label Below Balance ─── */
.balance-period-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.65);
  margin-bottom: 14px;
  letter-spacing: 0.02em;
  min-height: 1em;
}

.balance-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.balance-pill {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  max-width: 110px;
}

.pill-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.65);
}

.pill-value {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
}

/* ─── Main Content ─── */
.main-content {
  /* The ONLY scrolling element — flex:1 fills space between header and nav */
  flex: 1 1 0%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar across all browsers while keeping scroll functional */
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE / Edge */
  padding: 20px 16px 24px;
  max-width: 540px;
  margin: 0 auto;
  /* Width must be 100% when max-width centres it in a flex container */
  width: 100%;
}

/* Hide scrollbar on WebKit — Chrome, Safari, Android WebView */
.main-content::-webkit-scrollbar { display: none; }

/* ─── Tab System ─── */
.tab-pane {
  display: none;
  animation: fadeUp 0.25s ease forwards;
}

.tab-pane.active { display: block; }

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

/* ─── Sub Tabs ─── */
.sub-tabs {
  display: flex;
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.sub-tab {
  flex: 1;
  padding: 9px 16px;
  border-radius: 10px;
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  transition: all var(--transition);
  text-align: center;
}

.sub-tab.active {
  background: var(--clr-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(31,111,95,0.25);
}

.sub-pane { display: none; }
.sub-pane.active { display: block; }

/* ─── Section Headers ─── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-text);
  letter-spacing: -0.02em;
}

.section-period {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--clr-secondary);
  background: rgba(47,160,132,0.10);
  padding: 3px 8px;
  border-radius: 20px;
}

.link-btn {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--clr-secondary);
  padding: 4px 8px;
}

.mt-20 { margin-top: 24px; }
.mb-12 { margin-bottom: 12px; }

/* ─── Cards ─── */
.card {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
}

/* ─── Snapshot Grid (Dashboard Budget Summary) ─── */
.snapshot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.snapshot-card {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
}

.snapshot-cat {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.snapshot-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-secondary);
}

.snapshot-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.snapshot-amounts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.snapshot-spent {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-text);
}

.snapshot-limit {
  font-size: 0.68rem;
  color: var(--clr-text-muted);
}

.progress-bar {
  height: 6px;
  background: var(--clr-bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--clr-secondary);
  transition: width 0.5s ease;
}

.progress-fill.danger  { background: var(--clr-negative); }
.progress-fill.warning { background: var(--clr-warning); }

/* Goals Snapshot */
.goals-snapshot {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.goal-snap-card {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  gap: 14px;
}

.goal-snap-ring {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.goal-snap-ring svg {
  transform: rotate(-90deg);
  width: 44px;
  height: 44px;
}

.goal-snap-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--clr-primary);
}

.goal-snap-info { flex: 1; min-width: 0; }

.goal-snap-name {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--clr-text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goal-snap-sub {
  font-size: 0.72rem;
  color: var(--clr-text-muted);
}

/* ─── Budget List ─── */
.budget-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.budget-item {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
}

.budget-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.budget-cat {
  display: flex;
  align-items: center;
  gap: 8px;
}

.budget-icon {
  font-size: 1.3rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--clr-surface-2);
  border-radius: 10px;
  color: var(--clr-secondary);
}

.budget-cat-name {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--clr-text);
}

.budget-period-tag {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  background: var(--clr-bg);
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-item-actions {
  display: flex;
  gap: 6px;
}

.action-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: background var(--transition);
}

.action-btn.edit { color: var(--clr-secondary); }
.action-btn.edit:hover { background: rgba(47,160,132,0.10); }
.action-btn.delete { color: var(--clr-negative); }
.action-btn.delete:hover { background: rgba(192,57,43,0.10); }

.budget-amounts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.budget-spent-label {
  font-size: 0.72rem;
  color: var(--clr-text-muted);
  font-weight: 500;
}

.budget-spent-val {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--clr-text);
}

.budget-limit-val {
  font-size: 0.78rem;
  color: var(--clr-text-muted);
  font-weight: 500;
}

.budget-remaining {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  margin-top: 6px;
  font-weight: 500;
}

.budget-remaining.over { color: var(--clr-negative); }
.budget-remaining.ok   { color: var(--clr-secondary); }

/* ─── Bills List ─── */
.bills-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bill-item {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.bill-icon {
  width: 40px;
  height: 40px;
  background: var(--clr-surface-2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--clr-secondary);
}

.bill-info { flex: 1; min-width: 0; }

.bill-name {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--clr-text);
  margin-bottom: 3px;
}

.bill-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.bill-freq-tag {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--clr-bg);
  color: var(--clr-text-muted);
  padding: 2px 6px;
  border-radius: 6px;
}

.bill-due {
  font-size: 0.68rem;
  color: var(--clr-text-muted);
}

.bill-due.today {
  color: var(--clr-negative);
  font-weight: 600;
}

.bill-auto-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.62rem;
  color: var(--clr-secondary);
  font-weight: 600;
}

.bill-amount {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--clr-negative);
  flex-shrink: 0;
}

.bill-actions {
  display: flex;
  gap: 4px;
}

/* ─── Goals List ─── */
.goals-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.goal-card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  position: relative;
  overflow: hidden;
}

.goal-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--clr-secondary), var(--clr-accent));
}

.goal-card.debt::before {
  background: linear-gradient(90deg, #e74c3c, #e67e22);
}

.goal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.goal-title-wrap { flex: 1; }

.goal-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 4px;
}

.goal-type-badge.savings {
  background: rgba(47,160,132,0.12);
  color: var(--clr-primary);
}

.goal-type-badge.debt {
  background: rgba(192,57,43,0.10);
  color: var(--clr-negative);
}

.goal-name {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--clr-text);
  letter-spacing: -0.03em;
}

.goal-actions {
  display: flex;
  gap: 4px;
}

/* Goal Progress Arc */
.goal-progress-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.goal-arc {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

.goal-arc svg {
  transform: rotate(-90deg);
  width: 80px;
  height: 80px;
}

.goal-arc-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0;
}

.goal-arc-num {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 800;
  color: var(--clr-primary);
  line-height: 1;
}

.goal-arc-label {
  font-size: 0.5rem;
  color: var(--clr-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.goal-amounts { flex: 1; }

.goal-amount-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.goal-amount-label {
  font-size: 0.72rem;
  color: var(--clr-text-muted);
  font-weight: 500;
}

.goal-amount-val {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--clr-text);
}

.goal-amount-val.highlight { color: var(--clr-secondary); }

.goal-deadline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--clr-text-muted);
  margin-bottom: 12px;
}

.goal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-reached {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--clr-secondary);
}

/* ─── Transaction List ─── */
.transactions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.transactions-list.full {
  max-height: none;
}

.tx-item {
  background: var(--clr-surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  cursor: pointer;
  transition: box-shadow var(--transition);
}

.tx-item:hover {
  box-shadow: var(--shadow-md);
}

.tx-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tx-icon.inflow  { background: var(--clr-inflow-bg);  color: var(--clr-inflow); }
.tx-icon.outflow { background: var(--clr-outflow-bg); color: var(--clr-outflow); }

.tx-info { flex: 1; min-width: 0; }

.tx-name {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--clr-text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tx-category {
  font-size: 0.68rem;
  color: var(--clr-text-muted);
  font-weight: 500;
}

.tx-date {
  font-size: 0.65rem;
  color: var(--clr-text-light);
}

.tx-auto-tag {
  font-size: 0.62rem;
  color: var(--clr-secondary);
  font-weight: 600;
  background: rgba(47,160,132,0.10);
  padding: 1px 5px;
  border-radius: 4px;
}

.tx-amount {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}

.tx-amount.inflow  { color: var(--clr-inflow); }
.tx-amount.outflow { color: var(--clr-negative); }

/* ─── Charts ─── */
.chart-card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  margin-bottom: 12px;
}

.chart-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-text-muted);
  margin-bottom: 16px;
}

.chart-wrap {
  position: relative;
  width: 100%;
}

.doughnut-wrap {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.doughnut-wrap canvas {
  max-height: 200px !important;
  max-width: 200px !important;
}

.doughnut-center {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.doughnut-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--clr-text-muted);
}

.doughnut-amount {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 800;
  color: var(--clr-primary);
}

.bar-wrap, .line-wrap {
  height: 180px;
}

.bar-wrap canvas, .line-wrap canvas {
  max-height: 180px !important;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--clr-text-muted);
  font-weight: 500;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Filter Bar ─── */
.tx-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tx-filter-bar.hidden { display: none; }

.filter-select {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--clr-border-soft);
  border-radius: var(--radius-sm);
  background: var(--clr-surface);
  font-size: 0.78rem;
  color: var(--clr-text);
  appearance: none;
  -webkit-appearance: none;
}

/* ─── Goal Type Filter ─── */
.goal-type-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border-soft);
  transition: all var(--transition);
}

.filter-chip.active {
  background: var(--clr-primary);
  color: white;
  border-color: var(--clr-primary);
}

/* ─── Period Toggle ─── */
.period-toggle {
  display: flex;
  background: var(--clr-bg);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}

.toggle-pill {
  padding: 5px 12px;
  border-radius: 18px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  transition: all var(--transition);
}

.toggle-pill.active {
  background: var(--clr-primary);
  color: white;
  box-shadow: 0 2px 6px rgba(31,111,95,0.25);
}

/* ─── Bottom Navigation ─── */
.bottom-nav {
  /* Flex item — always pinned at bottom of the flex-column body.
     No position:fixed needed, so no WebView / keyboard-resize bugs. */
  flex-shrink: 0;
  width: 100%;
  height: var(--nav-height);
  background: var(--clr-surface);
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--clr-border-soft);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--clr-text-light);
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all var(--transition);
  min-width: 52px;
}

.nav-item.active {
  color: var(--clr-primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.nav-item.active .nav-icon {
  stroke: var(--clr-primary);
}

/* FAB */
.nav-fab {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  color: white !important;
  box-shadow: 0 4px 16px rgba(31,111,95,0.40);
  margin-top: -20px;
  transition: all var(--transition);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(31,111,95,0.50);
}

.nav-fab:active {
  transform: scale(0.96);
}

.nav-fab svg {
  width: 24px;
  height: 24px;
}

/* ─── Buttons ─── */
.btn-primary {
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: all var(--transition);
  box-shadow: 0 3px 10px rgba(31,111,95,0.30);
}

.btn-primary:hover {
  box-shadow: 0 5px 16px rgba(31,111,95,0.40);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  color: var(--clr-text-muted);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
}

.btn-ghost:hover { background: var(--clr-bg); }

.btn-outline {
  border: 1.5px solid var(--clr-secondary);
  color: var(--clr-secondary);
  padding: 11px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  transition: all var(--transition);
}

.btn-outline:hover {
  background: rgba(47,160,132,0.08);
}

.btn-outline.full-width { width: 100%; text-align: center; display: block; }

.btn-sm {
  background: var(--clr-primary);
  color: white;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  transition: all var(--transition);
}

.btn-sm:hover { background: var(--clr-secondary); }

.btn-contrib {
  background: rgba(47,160,132,0.10);
  color: var(--clr-secondary);
  border: 1px solid rgba(47,160,132,0.20);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  flex: 1;
  transition: all var(--transition);
}

.btn-contrib:hover { background: rgba(47,160,132,0.18); }

.btn-danger-sm {
  background: rgba(192,57,43,0.08);
  color: var(--clr-negative);
  border: 1px solid rgba(192,57,43,0.15);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  transition: all var(--transition);
}

.btn-danger-sm:hover { background: rgba(192,57,43,0.15); }

/* ─── Modals ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.40);
  backdrop-filter: blur(4px);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-backdrop.visible { opacity: 1; }
.modal-backdrop.hidden  { display: none; }

.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--clr-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 400;
  max-height: 92dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  max-width: 540px;
  margin: 0 auto;
}

.modal.visible { transform: translateY(0); }
.modal.hidden  { display: none; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  position: sticky;
  top: 0;
  background: var(--clr-surface);
  z-index: 1;
  border-bottom: 1px solid var(--clr-border-soft);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--clr-text);
  letter-spacing: -0.03em;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--clr-bg);
  color: var(--clr-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  transition: background var(--transition);
}

.modal-close:hover { background: var(--clr-border-soft); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 12px 20px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--clr-border-soft);
  justify-content: flex-end;
}

/* ─── Forms ─── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--clr-text-muted);
}

.form-input {
  padding: 12px 14px;
  border: 1.5px solid var(--clr-border-soft);
  border-radius: var(--radius-md);
  background: var(--clr-surface-2);
  font-size: 0.9rem;
  color: var(--clr-text);
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}

.form-input:focus {
  border-color: var(--clr-secondary);
  background: white;
}

.amount-input {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding: 14px;
}

/* Type Toggle (modal) */
.type-toggle {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  border: 1.5px solid var(--clr-border-soft);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--clr-text-muted);
  background: var(--clr-surface-2);
  transition: all var(--transition);
}

.type-btn.active[data-type="inflow"] {
  background: var(--clr-inflow-bg);
  border-color: var(--clr-inflow);
  color: var(--clr-inflow);
}

.type-btn.active[data-type="outflow"] {
  background: var(--clr-outflow-bg);
  border-color: var(--clr-outflow);
  color: var(--clr-outflow);
}

.type-btn.active[data-bperiod],
.type-btn.active[data-gtype],
.type-btn.active[data-freq] {
  background: rgba(31,111,95,0.10);
  border-color: var(--clr-primary);
  color: var(--clr-primary);
}

.type-btn.active[data-gtype="debt"] {
  background: rgba(192,57,43,0.08);
  border-color: var(--clr-negative);
  color: var(--clr-negative);
}

/* Toggle Switch */
.toggle-switch-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--clr-border-soft);
  border-radius: 12px;
  transition: background var(--transition);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--clr-secondary);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--transition);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
}

/* ─── Empty State ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  text-align: center;
  gap: 8px;
}

.empty-icon {
  color: var(--clr-text-light);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 0.82rem;
  color: var(--clr-text-muted);
  line-height: 1.5;
}

.snapshot-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  font-size: 0.8rem;
  color: var(--clr-text-muted);
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--clr-text);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease;
}

.toast.hidden { display: none; }
.toast.success { background: var(--clr-primary); }
.toast.error   { background: var(--clr-negative); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Responsive ─── */
@media (min-width: 540px) {
  .main-content {
    /* Nav is a flex item in flow, so no extra bottom padding needed */
    padding: 24px 20px 32px;
  }
  
  .modal {
    border-radius: var(--radius-xl);
    bottom: 50%;
    transform: translateY(50%) scale(0.96);
    max-width: 440px;
    left: 50%;
    right: auto;
    margin-left: -220px;
    margin-bottom: -200px;
  }
  
  .modal.visible {
    transform: translateY(50%) scale(1);
  }
}

@media (max-width: 360px) {
  .balance-amount  { font-size: 2rem; }
  .balance-pills   { gap: 5px; }
  .balance-pill    { padding: 6px 8px; }
  .pill-value      { font-size: 0.75rem; }
  .period-mode-btn { font-size: 0.65rem; }
}
