/* Mobile-first styles for the student budget app. */

:root {
  --pink: #d4537e;
  --pink-soft: #fbeaf0;
  --violet: #7f77dd;
  --violet-soft: #eeedfe;
  --text: #2c2c2a;
  --muted: #6b6a65;
  --bg: #faf8f5;
  --card: #ffffff;
  --line: #ebe8e1;
  --danger: #c0392b;
  --danger-soft: #fcebeb;
  --warn: #8a5a00;
  --warn-soft: #faeeda;
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* hidden must win over display: flex */

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--pink-soft); display: grid; place-items: center; font-size: 24px;
}

.month-switch { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; font-weight: 600; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 50%;
  width: 34px; height: 34px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
}

.hero {
  background: var(--violet-soft); border-radius: 20px; padding: 16px;
  display: flex; align-items: center; gap: 18px; color: #3c3489;
}
.ring {
  --pct: 0;
  --ring-color: var(--violet);
  width: 92px; height: 92px; border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--ring-color) calc(var(--pct) * 1%), #fff 0);
  display: grid; place-items: center;
}
.ring span {
  width: 70px; height: 70px; border-radius: 50%; background: var(--violet-soft);
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.hero-label { margin: 0; font-size: 13px; }
.hero-amount { margin: 2px 0; font-size: 30px; font-weight: 700; }

.alert {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45;
  background: var(--warn-soft); color: var(--warn);
}
.alert.over { background: var(--danger-soft); color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.cat { display: flex; align-items: center; gap: 12px; }
.bubble {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 20px;
}
.cat-body { flex: 1; min-width: 0; }
.cat-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.cat-top .over { color: var(--danger); font-weight: 600; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }

.expense-list { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.expense-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.expense-list li:first-child { border-top: none; }
.expense-list .bubble { width: 34px; height: 34px; font-size: 17px; }
.expense-list .what { flex: 1; min-width: 0; font-size: 14px; }
.expense-list .what small { display: block; color: var(--muted); font-size: 12px; }
.expense-list .amt { font-weight: 600; }
.tag { font-size: 10px; background: var(--line); color: var(--muted); border-radius: 6px; padding: 1px 5px; margin-left: 4px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px; }

label { display: block; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
input:focus { outline: 2px solid var(--pink); outline-offset: 1px; }
.amount-field span { font-size: 13px; color: var(--muted); }
.amount-field div { display: flex; align-items: center; gap: 8px; }
.amount-field input { font-size: 30px; font-weight: 700; border: none; padding: 4px 0; }
.amount-field input:focus { outline: none; }
input::placeholder { color: #c9c6bd; }
.amount-field b { font-size: 26px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; color: var(--text);
}
.chip.selected { border-color: transparent; font-weight: 600; }

.primary {
  border: none; border-radius: 14px; padding: 14px; font: inherit; font-size: 16px; font-weight: 600;
  background: var(--pink); color: #fff; cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; margin: 0; }

.budget-row { display: flex; align-items: center; gap: 12px; }
.budget-row .name { flex: 1; font-size: 14px; }
.budget-row input { width: 110px; text-align: right; }
.total-line { text-align: right; font-size: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 8px;
  background: rgba(255, 255, 255, 0.95); border-top: 1px solid var(--line);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; max-width: 140px; border: none; background: none; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px; border-radius: 12px;
}
.tabbar button span { font-size: 22px; }
.tabbar button.active { color: var(--pink); font-weight: 600; background: var(--pink-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}

/* Coach chat */
.coach-head { display: flex; align-items: center; gap: 12px; }
.coach-head h2 { margin: 0; }
.coach-logo { background: #e1f5ee; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 12px; }
.msg { max-width: 85%; padding: 10px 13px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--pink); color: #fff; border-radius: 18px 18px 4px 18px; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 18px 18px 18px 4px; }
.msg.bot.error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.msg.thinking { color: var(--muted); font-style: italic; }
.tools { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 6px; }
.tools span { font-size: 12px; background: #e1f5ee; color: #085041; border-radius: 999px; padding: 3px 10px; }
.chat-form {
  position: sticky; bottom: calc(78px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; margin-top: 12px; padding: 8px 0; background: var(--bg);
}
.chat-form input { flex: 1; border-radius: 999px; }
.send { width: 44px; border: none; border-radius: 50%; background: var(--pink); color: #fff; font-size: 18px; cursor: pointer; }
.send:disabled { opacity: 0.5; cursor: wait; }
.msg.bot.fact { background: #eeedfe; color: #3c3489; border-color: transparent; font-size: 13px; }

/* Receipt scan */
.scan-btn {
  display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 12px;
  padding: 14px; border-radius: 14px; border: 2px dashed var(--pink); background: var(--pink-soft);
  color: var(--pink); font-weight: 600; cursor: pointer;
}
.scan-status { margin-bottom: 12px; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; display: flex; gap: 10px; align-items: flex-start; }
.scan-status img { width: 56px; height: 72px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.scan-status.reading { background: var(--violet-soft); color: #3c3489; }
.scan-status.done { background: #e1f5ee; color: #085041; }
.scan-status.error { background: var(--danger-soft); color: var(--danger); }
.scan-status ul { margin: 4px 0 0; padding-left: 18px; }

/* Charts (plain SVG, no library: works offline) */
.chart svg { display: block; width: 100%; height: auto; }
.chart-caption { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.chart-caption b { color: var(--text); }
.donut-card { display: flex; align-items: center; gap: 16px; }
.donut { width: 128px; flex-shrink: 0; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .pct { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 18px; }
.tabbar button { max-width: 110px; }
.bar-hit { cursor: pointer; }

/* Proactive tips */
.tip { margin-top: 10px; padding: 12px; border-radius: 14px; background: var(--warn-soft); color: var(--warn); font-size: 13px; line-height: 1.45; }
.tip.over { background: var(--danger-soft); color: var(--danger); }
.tip p { margin: 6px 0 0; }
.tip-head { display: flex; align-items: center; gap: 8px; }
.tip-head .bubble { width: 30px; height: 30px; font-size: 16px; }
.tip-action { color: var(--text); font-weight: 600; }
.tip-ask { margin-top: 8px; border: 1px solid currentColor; background: #fff; color: inherit; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.tip-insight { font-style: italic; }

/* Private app screen and demo banner */
body.locked .top, body.locked .view, body.locked .tabbar, body.locked .demo-banner { display: none !important; }
.locked-page { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.locked-page .logo { width: 72px; height: 72px; font-size: 36px; }
.locked-page h1 { font-size: 24px; }
.locked-page .muted { max-width: 300px; font-size: 15px; }
.demo-btn { display: inline-block; margin-top: 12px; text-decoration: none; padding: 14px 22px; }
.demo-banner { margin: -4px 0 12px; padding: 8px 12px; border-radius: 12px; background: #e1f5ee; color: #085041; font-size: 13px; text-align: center; }
