/* ---------- Design tokens ---------- */
:root {
  --bg: #F7F5EF;
  --card: #FFFFFF;
  --ink: #23312E;
  --muted: #71797A;
  --faint: #9AA3A0;
  --brand: #1B6B5A;
  --brand-deep: #14523F;
  --brand-soft: #E4F0EA;
  --brand-softer: #F0F6F2;
  --gold: #A87A2E;
  --gold-soft: #F6EEDD;
  --danger: #B4483C;
  --danger-soft: #F9ECEA;
  --line: #E8E4D9;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 3px rgba(35, 49, 46, 0.06), 0 6px 20px rgba(35, 49, 46, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--ink); }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 20px 6px;
  min-height: 30px;
}
.header:empty { padding: 0; min-height: 0; }
.header .h-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.header .h-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.header .h-actions { display: flex; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.chip svg { width: 14px; height: 14px; stroke: var(--muted); fill: none; stroke-width: 2; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 19px; height: 19px; stroke: var(--ink); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Main view ---------- */
.view {
  flex: 1;
  padding: 10px 20px 110px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.nav-btn {
  flex: 1;
  background: none; border: none;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 4px;
  color: var(--faint);
  font-size: 11px; font-weight: 600;
  border-radius: 12px;
}
.nav-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.active { color: var(--brand-deep); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.soft { background: var(--brand-softer); border-color: #DCEAE1; box-shadow: none; }

.hero-card {
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 24px 22px;
  box-shadow: 0 10px 28px rgba(20, 82, 63, 0.28);
}
.hero-card .hc-label { font-size: 13px; font-weight: 600; opacity: 0.85; letter-spacing: 0.04em; text-transform: uppercase; }
.hero-card .hc-amount { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.hero-card .hc-note { font-size: 13.5px; opacity: 0.85; }
.hero-card.below {
  background: linear-gradient(150deg, #56746B, #43605A);
  box-shadow: 0 10px 28px rgba(67, 96, 90, 0.25);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 14px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  padding: 15px 22px;
  min-height: 52px;
  transition: transform 0.06s ease, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-deep); }
.btn.ghost { background: transparent; color: var(--brand-deep); border: 1.5px solid #C9DBD2; }
.btn.subtle { background: var(--brand-soft); color: var(--brand-deep); }
.btn.danger-ghost { background: transparent; color: var(--danger); border: 1.5px solid #E5C7C3; }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 9px 16px; font-size: 14px; border-radius: 11px; }

.link-btn {
  background: none; border: none;
  color: var(--brand-deep);
  font-size: 14px; font-weight: 700;
  padding: 8px 4px;
  text-decoration: underline;
  text-decoration-color: #B9D2C7;
  text-underline-offset: 3px;
}

/* ---------- Guided (chat) flow ---------- */
.guided-top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0 10px;
  margin: -10px 0 0;
}
.guided-top .gt-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.guided-top .gt-step { font-size: 13px; color: var(--muted); font-weight: 600; }
.progress-track { height: 5px; background: #E5E1D5; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); border-radius: 99px; transition: width 0.4s ease; }

.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.bubble {
  max-width: 88%;
  padding: 13px 16px;
  font-size: 15.5px;
  line-height: 1.55;
  animation: rise 0.28s ease both;
}
.bubble.bot {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  box-shadow: var(--shadow);
}
.bubble.bot .b-hint { display: block; margin-top: 6px; font-size: 13.5px; color: var(--muted); }
.bubble.user {
  align-self: flex-end;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: 600;
  border-radius: 18px 4px 18px 18px;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.input-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 6px;
  animation: rise 0.3s ease both;
  display: flex; flex-direction: column; gap: 14px;
}
.input-card .ic-actions { display: flex; gap: 10px; }
.input-card .ic-actions .btn { flex: 1; }
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  text-align: left;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15.5px;
  transition: border-color 0.15s, background 0.15s;
}
.choice-btn .cb-title { font-weight: 700; display: block; }
.choice-btn .cb-sub { font-size: 13.5px; color: var(--muted); display: block; margin-top: 2px; }
.choice-btn.selected { border-color: var(--brand); background: var(--brand-softer); }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 600; color: var(--ink);
}
.field-label .fl-sub { font-weight: 400; color: var(--muted); }
.info-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: none;
  background: #EDEAE0;
  color: var(--muted);
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.money-wrap { position: relative; }
.money-wrap .rupee {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 17px; font-weight: 600;
  pointer-events: none;
}
input.money, input.grams, input.text-input, select.select, textarea.textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: #FCFBF8;
  padding: 14px 15px;
  font-size: 17px;
  font-weight: 600;
  min-height: 52px;
  outline: none;
  transition: border-color 0.15s;
}
input.money { padding-left: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); background: #fff; }
input::placeholder, textarea::placeholder { color: #B9BFBB; font-weight: 500; }
textarea.textarea { min-height: 76px; font-weight: 500; resize: vertical; }

/* Purity grid — grams entry per karat, grouped in one compact block */
.purity-grid {
  display: flex; flex-direction: column;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: #FCFBF8;
  overflow: hidden;
}
.purity-row { display: flex; align-items: center; gap: 12px; padding: 4px 12px; border-bottom: 1px solid var(--line); }
.purity-row:last-child { border-bottom: none; }
.purity-row .pr-k { width: 30px; flex: none; font-size: 14px; font-weight: 700; color: var(--muted); }
.purity-row input.grams {
  flex: 1; min-height: 42px; padding: 8px 4px;
  border: none; background: transparent;
  font-size: 15.5px; font-weight: 600;
}
.purity-row input.grams:focus { background: #fff; }

/* Toggle */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
}
.toggle-row .tr-text { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.toggle-row .tr-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 2; }
.switch .knob {
  position: absolute; inset: 0;
  background: #D8D4C8;
  border-radius: 99px;
  transition: background 0.2s;
}
.switch .knob::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.switch input:checked + .knob { background: var(--brand); }
.switch input:checked + .knob::after { transform: translateX(20px); }

/* ---------- Form sections (Assets view) ---------- */
.section-card { padding: 4px 18px; }
.section-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 0;
  width: 100%;
  background: none; border: none;
  text-align: left;
}
.section-head .sh-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--brand-softer);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  flex: none;
}
.section-head .sh-text { flex: 1; min-width: 0; }
.section-head .sh-title { font-size: 15.5px; font-weight: 700; }
.section-head .sh-amount { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.section-head .sh-chev { width: 18px; height: 18px; stroke: var(--faint); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s; flex: none; }
.section-card.open .sh-chev { transform: rotate(180deg); }
.section-body { display: none; flex-direction: column; gap: 14px; padding: 4px 0 18px; }
.section-card.open .section-body { display: flex; }
.subhead { font-size: 12.5px; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }

.sticky-summary {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 8px 0 10px;
  margin-top: -10px;
}
.summary-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--ink);
  color: #fff;
  border-radius: 16px;
  padding: 13px 18px;
}
.summary-bar .sb-label { font-size: 12.5px; opacity: 0.75; }
.summary-bar .sb-amount { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.summary-bar .sb-side { text-align: right; }

/* ---------- Breakdown ---------- */
.break-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0;
  font-size: 14.5px;
  border-bottom: 1px dashed var(--line);
}
.break-row:last-child { border-bottom: none; }
.break-row .br-label { color: var(--muted); }
.break-row .br-val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.break-row.total { font-weight: 700; }
.break-row.total .br-label { color: var(--ink); }
.break-row.deduct .br-val { color: var(--danger); }

/* ---------- Payments ---------- */
.pay-progress { margin-top: 12px; }
.pay-progress .pp-track { height: 9px; background: #EAE6DA; border-radius: 99px; overflow: hidden; }
.pay-progress .pp-fill { height: 100%; background: var(--gold); border-radius: 99px; transition: width 0.4s; }
.pay-progress .pp-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 7px; }
.pay-item {
  display: flex; align-items: flex-start; gap: 13px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.pay-item:last-child { border-bottom: none; }
.pay-item .pi-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--gold-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex: none;
}
.pay-item .pi-main { flex: 1; min-width: 0; }
.pay-item .pi-title { font-weight: 700; font-size: 15px; }
.pay-item .pi-sub { font-size: 13px; color: var(--muted); margin-top: 1px; overflow-wrap: anywhere; }
.pay-item .pi-amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pay-item .pi-del {
  background: none; border: none; color: var(--faint);
  padding: 4px; margin-left: 2px;
}
.pay-item .pi-del svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- Years ---------- */
.year-card { display: flex; align-items: center; gap: 14px; }
.year-card .yc-left { width: 62px; flex: none; }
.year-card .yc-year { font-size: 19px; font-weight: 800; }
.year-card .yc-current { font-size: 11px; font-weight: 700; color: var(--brand-deep); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }
.year-card .yc-main { flex: 1; }
.year-card .yc-line { font-size: 13.5px; color: var(--muted); }
.year-card .yc-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
.badge {
  font-size: 11.5px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge.paid { background: var(--brand-soft); color: var(--brand-deep); }
.badge.partial { background: var(--gold-soft); color: var(--gold); }
.badge.due { background: var(--danger-soft); color: var(--danger); }
.badge.na { background: #EDEAE0; color: var(--muted); }

/* ---------- Sheet (bottom modal) ---------- */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(30, 40, 37, 0.45);
  z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 14px 22px calc(26px + env(safe-area-inset-bottom));
  max-height: 86dvh;
  overflow-y: auto;
  animation: slideUp 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0.5; } }
.sheet .grabber { width: 40px; height: 4px; background: #DDD9CD; border-radius: 99px; margin: 0 auto 16px; }
.sheet h3 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 8px; }
.sheet .sheet-body { font-size: 15px; color: #47524E; display: flex; flex-direction: column; gap: 12px; }
.sheet .sheet-body p b { color: var(--ink); }
.sheet .sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ---------- Misc ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .st-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .st-val { font-size: 20px; font-weight: 800; margin-top: 3px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
  font-size: 14.5px;
}
.empty .e-icon { font-size: 34px; margin-bottom: 8px; }

.note {
  font-size: 13.5px;
  color: var(--muted);
  background: var(--gold-soft);
  border: 1px solid #EDE0C4;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: #6E5B33;
}

.toast {
  position: fixed;
  bottom: 96px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 14px; font-weight: 600;
  padding: 11px 20px;
  border-radius: 99px;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  animation: rise 0.25s ease;
  max-width: 88%;
  text-align: center;
}

h2.view-title { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
.divider { height: 1px; background: var(--line); border: none; margin: 4px 0; }

/* Welcome */
.welcome {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  gap: 34px;
  padding: 20px 6px 40px;
  text-align: center;
}
.welcome .w-hero { display: flex; flex-direction: column; align-items: center; }

.welcome .w-markwrap { position: relative; width: 80px; height: 80px; margin: 0 auto; }
.welcome .w-halo {
  position: absolute; inset: -22px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(27, 107, 90, 0.16), transparent 72%);
}
.welcome .w-mark {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--brand) 0%, var(--brand-deep) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 30px -10px rgba(20, 82, 63, 0.45);
}
.welcome .w-mark svg { width: 38px; height: 38px; overflow: visible; }
.welcome .w-mark .w-moon { fill: #fff; }
.welcome .w-mark .w-spark { fill: var(--gold); }

.welcome .w-brand {
  font-size: 13px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--brand-deep);
  margin-top: 16px;
}
.welcome h1 {
  font-size: 27px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.22;
  margin-top: 8px;
  max-width: 300px;
}
.welcome .w-sub {
  color: var(--muted); font-size: 15px; font-weight: 500; line-height: 1.55;
  max-width: 290px; margin: 10px auto 0;
}

.welcome .w-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 18px;
  text-align: left;
  max-width: 300px;
  margin: 0 auto;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}
.welcome .w-list li { display: flex; gap: 13px; align-items: flex-start; font-size: 14px; color: #47524E; line-height: 1.5; }
.welcome .w-list .w-ico { flex: none; margin-top: 1px; }
.welcome .w-list .w-ico svg { width: 19px; height: 19px; fill: none; stroke: var(--brand-deep); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.welcome .w-actions { display: flex; flex-direction: column; gap: 12px; }

@media (min-width: 500px) {
  body { background: #EFECE3; }
  #app { background: var(--bg); box-shadow: 0 0 40px rgba(0,0,0,0.06); }
}
