/* ==========================================================================
   MyBudget — warm, calm spending tracker
   ========================================================================== */

:root {
  --bg: #FBF4EA;
  --bg-deep: #F3E6D5;
  --card: #FFFFFF;
  /* Warm terracotta, deepened so white text and small labels clear WCAG AA. */
  --terracotta: #B85134;
  --terracotta-dark: #A2432A;
  --amber: #E8A33D;
  --ink: #4A3B32;
  --ink-soft: #6F5D50;
  --line: #EDE0D0;
  --good: #4F7A55;
  --warn: #D9902B;
  --over: #C2452F;
  --on-accent: #FFF7F0;

  --grad-start: #B85134;
  --grad-end: #9C3F24;
  --accent-shadow: rgba(156, 63, 36, 0.26);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 6px 20px rgba(74, 59, 50, 0.08);
  --shadow-soft: 0 2px 8px rgba(74, 59, 50, 0.06);

  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #211A16;
    --bg-deep: #2E2520;
    --card: #2C2320;
    --terracotta: #E58F6E;
    --terracotta-dark: #EFA98A;
    --amber: #E0A85A;
    --ink: #F3E7DC;
    --ink-soft: #B09C8E;
    --line: #3D322C;
    --good: #8FB894;
    --warn: #E0A85A;
    --over: #EC8570;
    --on-accent: #2A1B15;

    --grad-start: #B85E3F;
    --grad-end: #94462C;
    --accent-shadow: rgba(0, 0, 0, 0.4);

    --shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.25);
  }

  /* the hero card keeps light text on its own dark gradient */
  .summary-card { color: #FDEFE6 !important; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ============ Layout shell ============ */

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 20px 12px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 22px; }

.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  font-size: 17px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}

.icon-btn:active { transform: scale(0.92); }

.content { padding: 4px 20px 24px; }

.tab-panel[hidden] { display: none; }

.block { margin-top: 24px; }
.block:first-child { margin-top: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.section-title {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.section-note {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--terracotta-dark);
  font-size: 13px;
  font-weight: 700;
  padding: 0 0 10px;
}

.hint {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 10px 2px 0;
}

/* ============ Segmented control ============ */

.segmented {
  display: flex;
  background: var(--bg-deep);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 16px;
}

.segment {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 0;
  border-radius: calc(var(--radius-md) - 4px);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background 0.18s ease, color 0.18s ease;
}

.segment.active {
  background: var(--card);
  color: var(--terracotta-dark);
  box-shadow: var(--shadow-soft);
}

/* ============ Summary hero ============ */

.summary-card {
  background: linear-gradient(160deg, var(--grad-start) 0%, var(--grad-end) 100%);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  color: #FFF7F0;
  box-shadow: 0 10px 24px var(--accent-shadow);
}

.range-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.range-arrow {
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.range-arrow:active { background: rgba(255, 255, 255, 0.32); }
.range-arrow:disabled { opacity: 0.3; }

.summary-label {
  font-size: 12.5px;
  font-weight: 600;
  /* Kept fully opaque: fading this small text drops it below AA on the gradient. */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  flex: 1;
}

.summary-total {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-top: 6px;
  line-height: 1.1;
}

.summary-sub {
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 4px;
  min-height: 16px;
}

.budget-progress { margin-top: 16px; }

.progress-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: #FFF7F0;
  border-radius: 999px;
  transition: width 0.4s ease, background 0.4s ease;
}

.progress-fill.state-good { background: #FFF7F0; }
.progress-fill.state-warn { background: #FFE1A8; }
.progress-fill.state-over { background: #FFB3A0; }

.progress-caption {
  margin-top: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.summary-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.pill-link {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
}

.pill-link:active { background: rgba(255, 255, 255, 0.3); }

/* ============ Quick stats ============ */

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.quick-stats:empty { display: none; }

.qstat {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 11px 10px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.qstat-value {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.qstat-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-top: 3px;
}

/* ============ Category breakdown ============ */

.category-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}

.category-emoji { font-size: 17px; }

.category-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-bar-track {
  width: 62px;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.category-bar-fill {
  display: block;
  height: 100%;
  background: var(--amber);
  border-radius: 999px;
}

.category-amount {
  font-size: 14px;
  font-weight: 700;
  min-width: 62px;
  text-align: right;
  flex-shrink: 0;
}

/* ============ Expense list ============ */

.expense-list, .history-list, .recurring-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expense-list:empty, .history-list:empty, .recurring-list:empty { display: none; }

.day-heading {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  padding: 10px 2px 0;
}

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-soft);
  border: none;
  width: 100%;
  text-align: left;
  transition: transform 0.12s ease;
}

.expense-row:active { transform: scale(0.985); }

.expense-emoji {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

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

.expense-category {
  font-size: 14.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.expense-meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--terracotta-dark);
  flex-shrink: 0;
}

.auto-tag {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: var(--bg-deep);
  border-radius: 5px;
  padding: 2px 5px;
}

.empty-state {
  text-align: center;
  padding: 34px 20px;
  color: var(--ink-soft);
}

.empty-emoji { font-size: 32px; margin-bottom: 8px; }

.empty-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 4px;
}

.empty-sub { font-size: 13px; margin: 0; line-height: 1.5; }

/* ============ History ============ */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 132px;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 12px 10px;
  box-shadow: var(--shadow-soft);
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.chart-bar {
  width: 100%;
  max-width: 26px;
  background: var(--terracotta);
  border-radius: 6px 6px 3px 3px;
  min-height: 3px;
  transition: height 0.35s ease;
}

.chart-bar.is-current { background: var(--amber); }
.chart-bar.is-over { background: var(--over); }
.chart-bar.is-empty { background: var(--bg-deep); }

.chart-label {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
  border: none;
  width: 100%;
  text-align: left;
  transition: transform 0.12s ease;
}

.history-row:active { transform: scale(0.99); }

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

.history-range { font-size: 14px; font-weight: 700; }

.history-meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--terracotta-dark);
  flex-shrink: 0;
}

.history-amount.state-over { color: var(--over); }

/* ============ Plan ============ */

.goal-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.goal-card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.goal-card-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.goal-card-value {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 4px;
}

.goal-card-sub {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 2px;
}

.goal-card-sub.state-over { color: var(--over); }
.goal-card-sub.state-good { color: var(--good); }

.mini-track {
  height: 6px;
  background: var(--bg-deep);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 9px;
}

.mini-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--good);
}

.mini-fill.state-warn { background: var(--warn); }
.mini-fill.state-over { background: var(--over); }

.cap-list { display: flex; flex-direction: column; gap: 8px; }
.cap-list:empty { display: none; }

.cap-row {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-soft);
}

.cap-head {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
}

.cap-head .cap-name { flex: 1; }

.cap-figures {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
}

.cap-figures.state-over { color: var(--over); }

.recurring-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-soft);
  border: none;
  width: 100%;
  text-align: left;
}

.recurring-row:active { transform: scale(0.99); }

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

.recurring-name { font-size: 14.5px; font-weight: 700; }

.recurring-meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recurring-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--terracotta-dark);
  flex-shrink: 0;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.data-actions .btn { flex: 1 1 30%; }

.danger-link {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--over);
  font-size: 13.5px;
  font-weight: 700;
  padding: 16px 0 4px;
  text-align: center;
}

/* ============ FAB + tab bar ============ */

.fab {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  /* Hug the right edge of the centred 480px column, never the viewport edge. */
  right: max(20px, calc(50% - 240px + 20px));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--terracotta);
  color: #FFF7F0;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 10px 22px var(--accent-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.fab:active { transform: scale(0.92); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
  z-index: 40;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-soft);
  padding: 0;
  transition: color 0.15s ease;
}

.tab-icon { font-size: 17px; line-height: 1; }

.tab-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tab.active { color: var(--terracotta-dark); }

/* ============ Sheets ============ */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 28, 22, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  animation: fade-in 0.18s ease;
}

.sheet-overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  padding: 10px 22px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slide-up 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .sheet-overlay, .sheet { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  margin: 6px auto 14px;
}

.sheet-title {
  font-size: 19px;
  font-weight: 800;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.confirm-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 18px;
}

.field { display: block; margin-bottom: 16px; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="file"],
textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px; /* 16px keeps iOS Safari from zooming on focus */
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
  font-size: 14px;
}

.field input:focus, textarea:focus {
  outline: none;
  border-color: var(--terracotta);
}

.field input[type="date"] { min-height: 48px; }

.amount-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 0 14px;
}

.amount-input-wrap:focus-within { border-color: var(--terracotta); }

.currency-sign {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-right: 4px;
}

.amount-input-wrap input {
  border: none;
  background: transparent;
  padding: 13px 0;
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.chip.selected {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #FFF7F0;
}

.quick-dates { display: flex; gap: 8px; margin-top: 8px; }

.mini-chip {
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.mini-chip.selected {
  background: var(--bg-deep);
  border-color: var(--bg-deep);
  color: var(--ink);
}

.cap-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.cap-field-label {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.cap-field .amount-input-wrap {
  width: 128px;
  flex-shrink: 0;
  padding: 0 12px;
}

.cap-field .amount-input-wrap input { padding: 10px 0; font-size: 15px; }

.form-error {
  color: var(--over);
  font-size: 13px;
  font-weight: 600;
  margin: -4px 0 12px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  font-size: 15.5px;
  font-weight: 700;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn-ghost { background: var(--bg-deep); color: var(--ink-soft); }
.btn-primary { background: var(--terracotta); color: #FFF7F0; }
.btn-danger { background: var(--over); color: #FFF7F0; }

.btn-soft {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  font-size: 13.5px;
  padding: 13px 8px;
}

.btn:active { transform: scale(0.98); }

/* ============ Toast ============ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
  z-index: 80;
  max-width: 88vw;
  text-align: center;
  animation: toast-in 0.22s ease;
}

.toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ Focus visibility ============ */

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2.5px solid var(--terracotta);
  outline-offset: 2px;
}

/* ============ Wider screens ============ */

@media (min-width: 620px) {
  .app { padding-bottom: calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
  .summary-total { font-size: 44px; }
}
