/* Society Loan calculator — visual system.
   Chrome palette (navy / primary blue / bg), type and card geometry are kept
   in step with the RKY Finance home page (site-wide style.css) so the move
   from the home page into this calculator reads as one product. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Poppins:wght@500;600;700;800&display=swap');

:root {
  --bg: #f5f8fc;
  --card: #ffffff;
  --line: #e3e8ef;
  --line-soft: #edf1f6;

  --navy: #0b2551;
  --navy-deep: #08203f;
  --navy-50: #eef3fb;

  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #6e7c91;

  --principal: #1a63cf;
  --principal-soft: #eaf1fb;
  --principal-line: #cfe0f5;
  --interest: #a2590f;
  --interest-soft: #fdf4e7;
  --interest-line: #f0dcbd;
  --lumpsum: #7c3aed;
  --lumpsum-soft: #f3ecfe;
  --lumpsum-line: #ded0fa;
  --ok: #067647;
  --ok-soft: #e9f6ef;
  --alert: #b42318;
  --alert-soft: #fdeceb;
  --note-soft: #fff8ec;

  --r: 20px;
  --r-sm: 14px;
  --r-xs: 10px;
  --pad: 16px;
  --shadow: 0 1px 3px rgba(16, 40, 80, .04), 0 10px 26px rgba(16, 40, 80, .05);

  --sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --head: 'Poppins', 'Inter', "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  overflow-wrap: break-word;
}

.wrap {
  width: 100%; max-width: 1060px; margin: 0 auto;
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
}

/* ---------- top bar — light, to match the RKY Finance home page header ---------- */
.masthead {
  background: #fff; color: var(--ink);
  border-bottom: 1px solid var(--line);
  padding: calc(14px + env(safe-area-inset-top)) 0 14px;
  margin-bottom: 4px;
}
.masthead .wrap { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; }
.topbar-id { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1 1 auto; }
/* the title grows and pushes the save chip + the two tool buttons together
   to the right edge, so the chip lines up with "Standard values" / "Clear" */
.masthead .wrap > .save-pill { order: 1; }
.masthead-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  flex: 0 0 auto; order: 2; justify-content: flex-end; min-width: 0;
}
.topbar-text { display: flex; flex-direction: column; min-width: 0; }

/* RKY Finance wordmark — the button back to the home page. The arrow + pill
   hover make it read as a "back to the site" control, not just a label. */
.brand {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--head);
  font-size: 18px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2;
  color: var(--navy); text-decoration: none;
  margin-left: -10px; padding: 4px 10px; border-radius: 999px;
  transition: background .15s, color .15s;
}
.brand-chev { font-size: 15px; opacity: .65; }
.brand:hover { color: var(--principal); background: var(--navy-50); }
.brand:hover .brand-chev { opacity: 1; }
.brand:focus-visible { outline: 2px solid var(--principal); outline-offset: 2px; }

/* the calculator's own name, now a subtitle under the wordmark */
.masthead h1 {
  margin: 2px 0 0; font-family: var(--sans);
  font-size: 12.5px; font-weight: 500; letter-spacing: .01em; line-height: 1.3;
  color: var(--ink-3);
}
.masthead h1 em { font-style: normal; font-weight: inherit; color: inherit; }
.masthead .tools { display: flex; gap: 8px; flex: 0 0 auto; }

/* ---------- where the figures are being kept ---------- */
.save-pill {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  background: var(--navy-50); border: 1px solid var(--principal-line);
  color: var(--ink-2); border-radius: 999px; padding: 5px 10px;
  min-height: 28px; font-size: 10.5px; font-weight: 650; white-space: nowrap;
}
/* grey = this device only. green = a cloud copy exists. */
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: #9fb0c4; flex: none; }
.save-pill[data-save="saving"] { color: #8a6116; }
.save-pill[data-save="saving"] .save-dot { background: #d9a441; }
.save-pill[data-save="cloud"] { color: var(--ok); }
.save-pill[data-save="cloud"] .save-dot { background: #45c286; }
.save-pill[data-save="off"] { color: var(--alert); }
.save-pill[data-save="off"] .save-dot { background: #e0776c; }
.save-pill[data-save="failed"], .save-pill[data-save="conflict"], .save-pill[data-save="signin"] { color: var(--alert); }
.save-pill[data-save="failed"] .save-dot,
.save-pill[data-save="conflict"] .save-dot,
.save-pill[data-save="signin"] .save-dot { background: #e0776c; }

.save-note {
  margin: 12px 0 0; padding: 12px 13px; border-radius: var(--r-sm);
  background: var(--navy-50); border: 1px solid var(--principal-line);
  font-size: 12.5px; line-height: 1.5; color: var(--ink-2);
}
.save-note[hidden] { display: none; }

/* ---------- section rules ---------- */
.section-rule {
  display: flex; align-items: center; gap: 12px;
  margin: 26px 2px 2px; color: var(--ink-3);
  font-size: 10.5px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
}
.section-rule::before, .section-rule::after { content: ""; height: 1px; background: var(--line); flex: 1 1 auto; }
.section-rule::before { flex: 0 0 14px; }

/* ---------- generic chrome ---------- */
.eyebrow {
  font-size: 10px; font-weight: 700; letter-spacing: .16em;
  text-transform: uppercase; color: var(--principal);
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); margin-top: 12px; overflow: hidden;
}
.card > summary, .card-head {
  list-style: none; padding: 15px var(--pad); display: flex; align-items: center;
  gap: 11px; cursor: pointer; background: var(--card);
  border-bottom: 1px solid transparent;
}
.card[open] > summary { border-bottom-color: var(--line); }
.card > summary::-webkit-details-marker { display: none; }
.card h2 {
  margin: 0; font-family: var(--head); font-size: 15.5px; font-weight: 700;
  letter-spacing: -.015em; flex: 1 1 auto; min-width: 0;
}
.card .hint { font-size: 12px; color: var(--ink-3); font-weight: 500; flex: 0 0 auto; }
.chev {
  width: 9px; height: 9px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(45deg); transition: transform .18s ease; flex: none; margin-right: 3px;
}
.card[open] > summary .chev { transform: rotate(-135deg); }
.card-body { padding: var(--pad); }

.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--principal-soft); color: var(--principal);
  font-size: 11.5px; font-weight: 700; flex: none;
}

/* ---------- form controls ---------- */
.grid { display: grid; gap: 14px 16px; grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.field .note { font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }
.field-warning {
  margin-top: 4px; font-size: 11.5px; line-height: 1.5;
  background: var(--note-soft); border: 1px solid #f0d9a8; border-left: 3px solid #d9a441;
  color: #74501a; border-radius: var(--r-sm); padding: 9px 11px;
}
.field-warning strong { font-weight: 700; }

input, select {
  font: inherit; font-size: 16px;
  color: var(--ink); background: #fff;
  border: 1px solid #d8e0ea; border-radius: var(--r-sm);
  padding: 11px 12px; width: 100%; min-width: 0; min-height: 46px;
  -webkit-appearance: none; appearance: none;
}
input[type=date] { -webkit-appearance: none; }
input::placeholder { color: #9aa6b8; }
input:focus, select:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--principal); outline-offset: 1px; border-color: var(--principal);
}
.num { font-variant-numeric: tabular-nums; }

button {
  font: inherit; font-size: 13.5px; font-weight: 650;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  padding: 9px 14px; min-height: 42px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
button:active { transform: translateY(1px); }
.btn-primary { background: var(--principal); border-color: var(--principal); color: #fff; }
.btn-ghost-dark {
  background: #fff; border-color: var(--line); color: var(--ink-2);
  min-height: 28px; padding: 5px 10px; font-size: 11px;
}
.btn-ghost-dark:hover { border-color: var(--principal-line); color: var(--navy); }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 12.5px; }
.btn-danger { color: var(--alert); border-color: #f0cfcc; background: var(--alert-soft); }

/* ---------- the hero result panel — the headline answer, kept light but
   tinted blue so it still reads as the primary card above the stat tiles ---------- */
.hero {
  margin-top: 12px;
  background: linear-gradient(180deg, #dbe8f8, #c1d6f0);
  color: var(--ink);
  border: 1px solid #acc8e6;
  border-radius: var(--r); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.hero-main { display: flex; flex-direction: column; gap: 13px; }
.hero-label { font-size: 11.5px; color: var(--ink-3); font-weight: 500; }
.hero-total { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hero-big {
  font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1.15;
  color: var(--navy); font-variant-numeric: tabular-nums;
}
.hero-sub { font-size: 12px; color: var(--ink-3); }
.hero-split {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px;
  padding-top: 13px; border-top: 1px solid var(--principal-line);
}
.hero-item { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hero-value {
  font-size: 17px; font-weight: 650; letter-spacing: -.015em;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}

/* ---------- stat tiles ---------- */
.stat-grid { display: grid; gap: 10px; margin-top: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 13px; display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
}
.stat-label { font-size: 11px; color: var(--ink-3); font-weight: 650; }
.stat-value {
  font-size: 16px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.stat-note { font-size: 11px; color: var(--ink-3); }
.stat.is-principal { border-color: var(--principal-line); background: linear-gradient(#fff, var(--principal-soft)); }
.stat.is-principal .stat-value { color: var(--principal); }
.stat.is-interest { border-color: var(--interest-line); background: linear-gradient(#fff, var(--interest-soft)); }
.stat.is-interest .stat-value { color: var(--interest); }
.stat.is-lumpsum { border-color: var(--lumpsum-line); background: linear-gradient(#fff, var(--lumpsum-soft)); }
.stat.is-lumpsum .stat-value { color: var(--lumpsum); }

/* ---------- definition rows ---------- */
.dl { display: flex; flex-direction: column; }
.dl > div {
  display: flex; justify-content: space-between; gap: 10px 18px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap;
}
.dl > div:last-child { border-bottom: 0; }
.dl dt { font-size: 13px; color: var(--ink-2); margin: 0; flex: 1 1 auto; min-width: 0; }
.dl dd {
  margin: 0; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums;
  text-align: right; flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere;
}

/* ---------- messages ---------- */
.msg { border-radius: var(--r-sm); padding: 12px 14px; font-size: 13px; margin-top: 12px; }
.msg ul { margin: 6px 0 0; padding-left: 18px; }
.msg li + li { margin-top: 4px; }
.msg-error { background: var(--alert-soft); color: #7d1f1f; border: 1px solid #f4d3d0; border-left: 3px solid var(--alert); }
.msg-note { background: var(--note-soft); color: #74501a; border: 1px solid #f0d9a8; border-left: 3px solid #d9a441; }

/* ---------- tables ---------- */
.table-scroll {
  overflow: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
  max-height: 70vh; overscroll-behavior: contain;
}
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line-soft); }
th {
  position: sticky; top: 0; z-index: 3;
  background: #f7f9fc; font-size: 9.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--ink-2); text-align: right;
  border-bottom: 1px solid var(--line);
}
th:first-child, td:first-child {
  position: sticky; left: 0; z-index: 2; text-align: left;
  background: #fff; border-right: 1px solid var(--line);
}
th:first-child { z-index: 4; background: #f7f9fc; }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover td, tbody tr:hover td:first-child { background: #f7f9fd; }
tr.is-final td { font-weight: 700; background: var(--ok-soft); }
tr.is-final td:first-child { background: var(--ok-soft); }
td.zero { color: #9aa6b8; }
td.has-event { color: var(--lumpsum); font-weight: 650; }
.tbl-note { font-size: 12px; color: var(--ink-3); margin: 10px 0 0; }
.tbl-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 11px; }
.tbl-tools .count { font-size: 11.5px; color: var(--ink-3); }

/* ---------- step: pill tabs + list editor ---------- */
.step-sub { margin: 0; padding: 0 var(--pad) 2px; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.step-note { margin: 0 0 14px; font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.ptabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px var(--pad) 2px; }
.ptab {
  flex: 0 1 auto; font-size: 12.5px; font-weight: 650; color: var(--ink-2);
  background: #eef1f6; border: 1px solid transparent; border-radius: 999px;
  padding: 8px 13px; min-height: 38px; white-space: nowrap;
}
.ptab-on { background: var(--navy); border-color: var(--navy); color: #fff; }
.ptab .pip { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700; opacity: .75; }

.list-editor { padding: 14px var(--pad) var(--pad); }
.list-editor .note { display: block; margin: 0 0 12px; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.empty {
  margin: 0; padding: 16px; text-align: center; font-size: 13px; color: var(--ink-3);
  background: #f8fafc; border: 1px dashed var(--line); border-radius: var(--r-sm);
}

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line-soft);
}
.entry:first-child { border-top: 0; padding-top: 2px; }
.entry-no { font-size: 11.5px; color: var(--ink-3); font-weight: 700; }
.entry-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.entry-date { font-size: 12.5px; color: var(--ink-3); }
.entry-val {
  font-size: 15px; font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.entry-acts { display: flex; gap: 6px; flex: none; }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; min-height: 38px; padding: 0;
  background: #eef1f6; border: 0; border-radius: var(--r-xs); color: var(--ink-2);
}
.icon-btn:hover { background: #e2e8f1; }
.icon-del:hover { background: var(--alert-soft); color: var(--alert); }

.entry-form { margin-top: 14px; padding: 13px; border-radius: 14px; background: #f8fafc; border: 1px solid var(--line); }
.entry-form-title {
  margin: 0 0 11px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}
.entry-form-grid { display: grid; gap: 12px; }
.entry-error { margin: 10px 0 0; font-size: 12.5px; color: var(--alert); font-weight: 650; }
.entry-form-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.list-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 13px; flex-wrap: wrap;
}
.list-total { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- floating confirm dialog ---------- */
.eyebrow.is-alert { color: var(--alert); }
.warn-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; margin-right: 6px;
  background: var(--alert); color: #fff; font-size: 13px; font-weight: 700; line-height: 1;
}
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-back { position: absolute; inset: 0; background: rgba(16, 24, 40, .55); }
.sheet-panel {
  position: relative; z-index: 1; background: var(--card);
  width: min(420px, calc(100vw - 20px)); max-height: min(88vh, 900px);
  border-radius: var(--r); box-shadow: 0 24px 60px -20px rgba(16, 24, 40, .6);
  display: flex; flex-direction: column; overflow: hidden;
}
.sheet-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px var(--pad); border-bottom: 1px solid var(--line); background: var(--card);
}
.sheet-head h2 { margin: 3px 0 0; font-family: var(--head); font-size: 16px; font-weight: 700; letter-spacing: -.015em; display: flex; align-items: center; }
.sheet-head > div { flex: 1 1 auto; min-width: 0; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px var(--pad) var(--pad); }
.g-p { margin: 0 0 10px; font-size: 13px; line-height: 1.55; color: var(--ink-2); }

/* =====================================================================
   BREAKPOINTS
   ===================================================================== */
@media (min-width: 420px) {
  .entry-form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .entry-main { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 14px; }
  .entry-date { flex: 0 0 auto; }
  .entry-val { text-align: right; }
}

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { padding: 18px 20px; }
  .hero-big { font-size: 36px; }
  .hero-split { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
}

@media (min-width: 760px) {
  :root { --pad: 22px; }
  .wrap { padding-left: calc(20px + env(safe-area-inset-left)); padding-right: calc(20px + env(safe-area-inset-right)); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .brand { font-size: 19px; }
  .masthead h1 { font-size: 13px; }
  table { font-size: 13px; }
  .hero-main { flex-direction: row; align-items: flex-end; gap: 26px; }
  .hero-total { flex: 0 0 auto; }
  .hero-split {
    flex: 1 1 auto; padding-top: 0; border-top: 0;
    border-left: 1px solid var(--principal-line); padding-left: 26px;
  }
}

/* Below ~560px the title takes its own row, and the pill + buttons share
   the next one — this is what keeps the header compact on a phone. */
@media (max-width: 560px) {
  .masthead { padding: calc(9px + env(safe-area-inset-top)) 0 9px; }
  .masthead .wrap { gap: 8px 10px; align-items: flex-start; }
  /* wordmark + subtitle share row 1 with the save chip; the two tool
     buttons take a compact full-width row below — no separate chip row */
  .topbar-id { flex: 1 1 0; min-width: 0; }
  .save-pill { flex: 0 0 auto; align-self: flex-start; }
  .masthead h1 { font-size: 11.5px; }
  .masthead-actions { flex: 1 1 100%; }
  .masthead .tools { width: 100%; gap: 6px; }
  .masthead .tools button { flex: 1 1 0; white-space: nowrap; min-height: 32px; padding: 6px 6px; font-size: 12px; }
}

@media (max-width: 400px) {
  th, td { padding: 8px 8px; font-size: 12px; }
  .hero-big { font-size: 29px; }
  .masthead-actions { gap: 5px; }
  .masthead .tools { flex: 1 1 auto; }
  .masthead .tools button { flex: 1 1 0; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media print {
  body { background: #fff; padding: 0; font-size: 11px; }
  .masthead .tools { display: none !important; }
  .masthead { background: #fff; color: var(--ink); border-bottom: 2px solid var(--ink); padding: 0 0 10px; }
  .masthead .brand { color: var(--ink); }
  .masthead h1, .masthead h1 em { color: var(--ink-3); }
  .hero { background: #fff; color: var(--ink); box-shadow: none; border: 1px solid #ccc; }
  .hero-label, .hero-sub { color: var(--ink-3); }
  .hero-split { border-color: #ddd; }
  .card { box-shadow: none; break-inside: avoid; border-color: #ccc; }
  .stat { box-shadow: none; break-inside: avoid; }
  details:not([open]) > summary ~ * { display: none; }
  .table-scroll { max-height: none; overflow: visible; border: 0; }
  th, th:first-child, td:first-child { position: static; }
}
