/* ----------------------------------------------------------------------
   Spend Happens - cute, clean, modern styling
   Soft colors, rounded cards, friendly vibe. Mobile-first.
---------------------------------------------------------------------- */
:root {
  /* Glam princess palette: blush #FFEBEC, pink #F6D3D1, rose #D8A7AA,
     black #000000, mauve-beige #E9CDCC */
  --bg-1: #fff6f7;
  --bg-2: #ffe7e8;
  --ink: #17100f;
  --ink-soft: #8d7174;
  --card: #ffffff;
  --line: #f3dedd;
  --primary: #1a1316;        /* near-black = primary action */
  --primary-dark: #000000;
  --primary-soft: #ffebec;   /* blush soft fill */
  --pink: #d8a7aa;           /* dusty rose accent */
  --pink-soft: #f6d3d1;
  --rose: #e9cdcc;
  --mint: #d3e0c1;           /* soft sage green */
  --amber: #f59e0b;
  --red: #ef4444;
  --safe-bg: #e4efe8;   --safe-ink: #46785f;
  --spicy-bg: #fef3c7;  --spicy-ink: #b45309;
  --nope-bg: #fee2e2;   --nope-ink: #b91c1c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px -12px rgba(120, 70, 75, 0.28);
  --shadow-sm: 0 4px 14px -8px rgba(120, 70, 75, 0.32);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .4rem; font-weight: 800; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 .6rem; }
small { color: var(--ink-soft); }

/* ---------- Layout ---------- */
.appbar {
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.appbar-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: .4rem 1.25rem;
}
.brand {
  flex-shrink: 0;
  display: flex; align-items: center; gap: .55rem;
  font-weight: 900; font-size: 1.2rem; color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  color: #fff; font-size: 1.1rem; box-shadow: var(--shadow-sm);
}
.brand-logo { height: 52px; width: auto; display: block; }
.brand-logo.auth { height: 92px; }

.container { max-width: 1080px; margin: 0 auto; padding: 1.25rem; }

.tabs {
  flex: 1 1 auto; min-width: 0;
  display: flex; gap: .4rem; overflow-x: auto; padding: 0; margin: 0;
  justify-content: safe center; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  white-space: nowrap; padding: .5rem .9rem; border-radius: 999px;
  color: var(--ink-soft); font-weight: 700; font-size: .92rem;
  border: 1px solid transparent;
}
.tab:hover { text-decoration: none; background: #fff; color: var(--ink); }
.tab.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }

/* ---------- Account menu ---------- */
.account { position: relative; flex-shrink: 0; }
.account > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem;
  padding: .35rem .6rem; border-radius: 999px; border: 1px solid var(--line); background: #fff;
  font-weight: 700; font-size: .9rem;
}
.account > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: .85rem;
}
.account .menu {
  position: absolute; right: 0; top: 110%; min-width: 180px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: .4rem; z-index: 60;
}
.account .menu a, .account .menu button {
  display: block; width: 100%; text-align: left; padding: .5rem .6rem; border-radius: 8px;
  color: var(--ink); font: inherit; background: none; border: none; cursor: pointer;
}
.account .menu a:hover, .account .menu button:hover { background: var(--primary-soft); text-decoration: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 1.1rem 1.2rem;
}
.card h2 { font-size: 1.05rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 540px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

/* Stat cards */
.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat .label { color: var(--ink-soft); font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.55rem; font-weight: 900; }
.stat .sub { font-size: .82rem; color: var(--ink-soft); }
.stat.accent { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; border: none; }
.stat.accent .label, .stat.accent .sub { color: rgba(255,255,255,.85); }
.stat.pink { background: linear-gradient(135deg, var(--pink-soft), var(--pink)); color: var(--ink); border: none; }
.stat.pink .label, .stat.pink .sub { color: rgba(255,255,255,.9); }
.stat.mint { background: linear-gradient(135deg, #e6eedb, var(--mint)); color: #2f4632; border: none; }
.stat.mint .label, .stat.mint .sub { color: rgba(35,67,58,.72); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .subtitle { color: var(--ink-soft); }

/* Month switcher */
.month-nav { display: inline-flex; align-items: center; gap: .35rem; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: .25rem; }
.month-nav a, .month-nav .current {
  padding: .35rem .7rem; border-radius: 999px; font-weight: 800; font-size: .9rem; color: var(--ink);
}
.month-nav a:hover { background: var(--primary-soft); text-decoration: none; }
.month-nav .current { color: var(--primary-dark); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  padding: .55rem .95rem; border-radius: 999px; font-weight: 800; font-size: .92rem;
  border: 1px solid var(--line); background: #fff; color: var(--ink); transition: transform .05s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.pink { background: var(--pink); color: var(--ink); border-color: var(--pink); }
.btn.pink:hover { background: #cf999c; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #f6c5c5; background: #fff5f5; }
.btn.danger:hover { background: var(--nope-bg); }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field.full { grid-column: 1 / -1; }
label { font-weight: 700; font-size: .85rem; color: var(--ink-soft); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; color: var(--ink); background: #fffdfd;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
.check { display: inline-flex; align-items: center; gap: .45rem; font-weight: 700; color: var(--ink); }
.check input { width: auto; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .55rem; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #fff6f6; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Pills / chips ---------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border-radius: 999px; font-weight: 800; font-size: .78rem; }
.pill.safe { background: var(--safe-bg); color: var(--safe-ink); }
.pill.spicy { background: var(--spicy-bg); color: var(--spicy-ink); }
.pill.nope { background: var(--nope-bg); color: var(--nope-ink); }
.pill.muted { background: #f4eae9; color: var(--ink-soft); }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .5rem; border-radius: 999px; font-weight: 700; font-size: .78rem; background: var(--primary-soft); color: var(--primary-dark); }
.tag-row { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.tag-row:empty { display: none; }
.block-link { display: block; color: inherit; text-decoration: none; border-radius: 10px; padding: .15rem; transition: background .12s ease; }
.block-link:hover { background: var(--primary-soft); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Progress ---------- */
.bar { height: 9px; background: #f4e4e3; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.bar > span.spicy { background: var(--amber); }
.bar > span.nope { background: var(--red); }
.bar > span.safe { background: var(--mint); }

/* ---------- Flash messages ---------- */
.flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .7rem .9rem; border-radius: var(--radius-sm); font-weight: 700; border: 1px solid; }
.flash.success { background: var(--safe-bg); color: var(--safe-ink); border-color: #bbf7d0; }
.flash.error { background: var(--nope-bg); color: var(--nope-ink); border-color: #fecaca; }
.flash.info { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--pink); }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand { justify-content: center; margin-bottom: .5rem; font-size: 1.5rem; }
.auth-tagline { text-align: center; color: var(--ink-soft); margin-bottom: 1.2rem; }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--ink-soft); padding: 1.5rem; }
.list-reset { list-style: none; margin: 0; padding: 0; }
.between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.muted { color: var(--ink-soft); }
.pos { color: var(--safe-ink); font-weight: 800; }
.neg { color: var(--nope-ink); font-weight: 800; }
.stack > * + * { margin-top: 1rem; }
.inline-form { display: inline; }
.hide-mobile { display: inline; }
@media (max-width: 600px) { .hide-mobile { display: none; } }
.cat-icon { width: 26px; height: 26px; border-radius: 8px; display: inline-grid; place-items: center; font-size: .9rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; gap: .5rem; }
footer.site { text-align: center; color: var(--ink-soft); font-size: .82rem; padding: 1.5rem 1rem 2.5rem; }
details.editor > summary { cursor: pointer; font-weight: 800; color: var(--primary-dark); list-style: none; }
details.editor > summary::-webkit-details-marker { display: none; }

/* ---------- Chat assistant ---------- */
.chat-widget { position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 60; }
.chat-fab {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; font-family: inherit; padding: 0;
  background: var(--pink-soft);
  width: 62px; height: 62px; border-radius: 50%; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.chat-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 16px 34px -14px rgba(120,70,75,.5); }
.chat-fab-img { width: 54px; height: 54px; object-fit: contain; display: block; pointer-events: none; }
.chat-widget.open .chat-fab { display: none; }

.chat-panel {
  position: fixed; right: 1.1rem; bottom: 1.1rem;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 2rem));
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; animation: chat-pop .16s ease;
}
.chat-panel[hidden] { display: none; }
@keyframes chat-pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .8rem .9rem; background: var(--primary); color: #fff;
}
.chat-title { display: flex; align-items: center; gap: .6rem; }
.chat-title-emoji { font-size: 1.5rem; line-height: 1; }
.chat-title-logo {
  width: 40px; height: 40px; border-radius: 50%; object-fit: contain;
  background: var(--pink-soft); padding: 2px; box-shadow: var(--shadow-sm);
}
.chat-title strong { display: block; font-size: 1rem; }
.chat-title small { color: rgba(255,255,255,.72); font-size: .74rem; }
.chat-close {
  border: none; background: rgba(255,255,255,.14); color: #fff; cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; font-size: .9rem; font-weight: 800;
  display: grid; place-items: center; transition: background .12s ease;
}
.chat-close:hover { background: rgba(255,255,255,.28); }

.chat-log { flex: 1; overflow-y: auto; padding: .9rem; display: flex; flex-direction: column; gap: .65rem; }
.chat-msg { display: flex; }
.chat-msg.me { justify-content: flex-end; }
.chat-bubble {
  max-width: 84%; padding: .55rem .8rem; border-radius: 16px;
  font-size: .9rem; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word;
}
.chat-msg.bot .chat-bubble { background: var(--primary-soft); color: var(--ink); border-bottom-left-radius: 5px; }
.chat-msg.me .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.chat-msg.bot .chat-bubble.err { background: var(--nope-bg); color: var(--nope-ink); }
.chat-bubble code { background: rgba(0,0,0,.06); padding: .05rem .3rem; border-radius: 6px; font-size: .85em; }
.chat-bubble pre { background: #1a1316; color: #ffe7e8; padding: .6rem .7rem; border-radius: 10px; overflow-x: auto; margin: .4rem 0 0; }
.chat-bubble pre code { background: none; padding: 0; color: inherit; }
.chat-bubble strong { font-weight: 800; }
.chat-bubble a { color: var(--primary-dark); text-decoration: underline; }

.chat-typing { display: inline-flex; gap: .25rem; align-items: center; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--pink); animation: chat-blink 1s infinite; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.chat-input { display: flex; align-items: flex-end; gap: .5rem; padding: .65rem; border-top: 1px solid var(--line); background: var(--card); }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px;
  padding: .55rem .7rem; font-family: inherit; font-size: .9rem; line-height: 1.4;
  max-height: 120px; background: var(--bg-1); color: var(--ink);
}
.chat-input textarea:focus { outline: none; border-color: var(--pink); background: #fff; }
.chat-send {
  border: none; cursor: pointer; background: var(--primary); color: #fff;
  width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%;
  font-size: 1.1rem; font-weight: 800; display: grid; place-items: center;
  transition: opacity .12s ease;
}
.chat-send:disabled { opacity: .4; cursor: default; }

@media (max-width: 480px) {
  .chat-panel { right: 0; bottom: 0; width: 100vw; height: 100vh; border-radius: 0; }
}

/* ---------- Accountabilibuddy guided walkthrough ---------- */
.wizard { max-width: 680px; margin: 1.5rem auto; }

.wizard-progress { display: flex; align-items: center; gap: .4rem; margin-bottom: 1.25rem; }
.wz-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--pink-soft); transition: background .2s, transform .2s; }
.wz-dot.active { background: var(--primary); transform: scale(1.25); }
.wz-dot.done { background: var(--pink); }
.wz-progress-label { margin-left: .5rem; font-size: .8rem; font-weight: 800; color: var(--ink-soft); }

.buddy { display: flex; gap: .7rem; align-items: flex-start; margin-bottom: 1rem; }
.buddy-avatar {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 999px;
  display: grid; place-items: center; font-size: 1.4rem;
  background: linear-gradient(135deg, var(--primary), var(--pink)); box-shadow: var(--shadow-sm);
}
.buddy-bubble {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; border-top-left-radius: 4px; padding: .85rem 1rem;
  box-shadow: var(--shadow-sm); line-height: 1.5;
}
.buddy-name { font-weight: 900; font-size: .82rem; color: var(--primary-dark); margin-bottom: .25rem; }

.wizard-actions { margin-top: 1rem; align-items: center; }

/* Bills step */
.sub-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip-add {
  border: 1px dashed var(--pink); background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; padding: .3rem .7rem; font-weight: 800; font-size: .82rem; cursor: pointer;
}
.chip-add:hover { background: var(--pink-soft); }
.chip-add.used { opacity: .45; }
.bill-rows { display: flex; flex-direction: column; gap: .5rem; }
.bill-row { display: grid; grid-template-columns: 1fr 120px 100px auto; gap: .5rem; align-items: center; }
.bill-row input { width: 100%; }

/* Budget step */
.budget-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: 1rem; }
.budget-rows { display: flex; flex-direction: column; }
.budget-line {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 0; border-bottom: 1px solid var(--line); gap: 1rem;
}
.budget-line:last-child { border-bottom: none; }
.budget-cat { font-weight: 700; }
.budget-input { display: flex; align-items: center; gap: .25rem; }
.budget-input .dollar { color: var(--ink-soft); font-weight: 800; }
.budget-input input { width: 110px; text-align: right; }

.import-choices { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

@media (max-width: 560px) {
  .bill-row { grid-template-columns: 1fr 1fr; }
  .budget-summary { grid-template-columns: repeat(2, 1fr); }
}

/* AI-personalized budget bits */
.ai-badge {
  font-size: .68rem; font-weight: 800; color: var(--primary-dark);
  background: var(--primary-soft); border-radius: 999px; padding: .1rem .45rem; margin-left: .35rem;
}
.buddy-thinking { color: var(--ink-soft); font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.budget-input input.ai-filled {
  border-color: var(--pink); background: var(--primary-soft);
  animation: ai-pop .35s ease;
}
@keyframes ai-pop { from { transform: scale(.96); } to { transform: scale(1); } }

/* ---------- Admin panel ---------- */
.admin-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.admin-actions .reset-form { display: flex; gap: .3rem; align-items: center; }
.admin-actions .reset-form input { width: 150px; padding: .3rem .5rem; font-size: .82rem; }
.admin-table td { vertical-align: middle; }
.pill.safe { text-transform: lowercase; }

/* ---------- Paycheck planner ---------- */
.month-nav { display: flex; align-items: center; gap: .6rem; }
.paycheck-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.paycheck-card { display: flex; flex-direction: column; gap: .6rem; }
.paycheck-card.over { border-color: var(--nope-ink); background: var(--nope-bg); }
.paycheck-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.paycheck-head h2 { margin: 0; font-size: 1.05rem; }
.paycheck-income { font-weight: 900; font-size: 1.2rem; }
.paycheck-bar { height: 8px; border-radius: 999px; background: var(--primary-soft); overflow: hidden; }
.paycheck-bar-fill { height: 100%; border-radius: 999px; background: var(--pink); }
.paycheck-bar-fill.safe { background: var(--safe-ink); }
.paycheck-bar-fill.spicy { background: var(--spicy-ink); }
.paycheck-bar-fill.over { background: var(--nope-ink); }
.paycheck-stats { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .85rem; color: var(--ink-soft); }
.planner-bills { display: flex; flex-direction: column; gap: .4rem; margin-top: .3rem; }
.planner-bill { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.planner-bill-name { font-weight: 700; }
.planner-bill-meta { display: block; font-size: .78rem; color: var(--ink-soft); }
.planner-bill-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.planner-bill-amt { font-weight: 800; }
.planner-move select { font-size: .78rem; padding: .2rem .4rem; max-width: 150px; }
