/* Kingsgate Estate — design tokens & shared components. Warm & vibey, light theme, soft shapes. */
:root {
  /* --sun is the primary action colour: #C2431F gives white text 5.1:1 (WCAG AA); the old #E4572E only reached 3.7:1. */
  --sun: #C2431F; --sun-deep: #A33716; --sun-soft: #FDE7DE;
  --gold: #F2B134; --gold-soft: #FFF1CC;
  --jac: #5E3F94; --jac-light: #8E6FC2; --jac-soft: #EFE8FA;
  --leaf: #2E8B6A; --leaf-soft: #DDF3EA;
  --sky: #2D7DD2; --sky-soft: #DFEBFA;
  --rose: #D23F5C; --rose-soft: #FBE1E7;
  /* --ink-3 is the muted text colour: #66596D reaches 5.6:1 on --sand and 6.2:1 on --cream (WCAG AA); the old #7B6F82 only reached 4.06:1 on --sand. */
  --ink: #2A1F2D; --ink-2: #4E4354; --ink-3: #66596D; --line: #EADFD6;
  --cream: #FFF8F1; --paper: #FFFFFF; --sand: #F7ECE1;
  --r-sm: 12px; --r: 20px; --r-lg: 28px; --r-pill: 999px;
  --shadow: 0 10px 30px rgba(42, 31, 45, 0.08); --shadow-lg: 0 24px 60px rgba(42, 31, 45, 0.14);
  --font: 'Nunito', 'Avenir Next', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 72px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--cream); line-height: 1.55; font-size: 16px; overflow-x: hidden; }
img, svg { max-width: 100%; display: block; }
a { color: var(--jac); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; }
h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); }
h2 { font-size: clamp(1.6rem, 3.2vw, 2.2rem); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 var(--space-4); }
.muted { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; font-weight: 800; color: var(--sun); margin-bottom: var(--space-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.container { width: min(1180px, 100% - 2 * var(--space-4)); margin-inline: auto; }
@media (min-width: 720px) { .container { width: min(1180px, 100% - 2 * var(--space-6)); } }
.section { padding-block: var(--space-7); }
.section-head { margin-bottom: var(--space-5); }

/* Money & numbers */
.money { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 800; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Inline SVG icons (the only pictographs in the UI — never emoji) */
.ico { display: inline-grid; place-items: center; line-height: 0; flex: none; }
.ico svg { width: 1.25em; height: 1.25em; }
.btn .ico svg { width: 18px; height: 18px; }
.btn-icon .ico svg { width: 20px; height: 20px; }
.fac-icon { width: 44px; height: 44px; border-radius: 14px; background: var(--jac-soft); color: var(--jac); margin-bottom: var(--space-2); }
.fac-icon svg { width: 26px; height: 26px; }

/* Buttons — touch targets ≥ 44px */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 44px; padding: 10px 20px; border-radius: var(--r-pill); border: 2px solid transparent; font-weight: 800; cursor: pointer; text-decoration: none; transition: transform .12s ease, box-shadow .12s ease, background .12s ease; white-space: nowrap; }
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--sun); color: #fff; }
.btn-primary:hover { background: var(--sun-deep); }
.btn-jac { background: var(--jac); color: #fff; }
.btn-jac:hover { background: #4A2F7A; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--paper); }
.btn-soft { background: var(--jac-soft); color: var(--jac); }
.btn-danger { background: #B8324C; color: #fff; }
.btn-sm { min-height: 40px; padding: 6px 14px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: 50%; }

/* Cards */
.card { background: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); padding: var(--space-5); border: 1px solid rgba(234, 223, 214, .6); }
.card-soft { background: var(--sand); box-shadow: none; }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.grid > .card { display: flex; flex-direction: column; }
.card .card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.card .card-title-row .money { flex: none; }
.card-cta { margin-top: auto; padding-top: var(--space-4); }

/* Stat tiles */
.stat { background: var(--paper); border-radius: var(--r); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow); border-left: 6px solid var(--sun); }
.stat .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); font-weight: 800; }
.stat .value { font-size: clamp(1.7rem, 3vw, 2.4rem); font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.1; }
.stat .hint { font-size: .85rem; color: var(--ink-3); }
.stat.jac { border-color: var(--jac); } .stat.leaf { border-color: var(--leaf); } .stat.gold { border-color: var(--gold); } .stat.rose { border-color: var(--rose); } .stat.sky { border-color: var(--sky); }

/* Pills & badges */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--r-pill); font-size: .78rem; font-weight: 800; letter-spacing: .02em; white-space: nowrap; background: var(--sand); color: var(--ink-2); }
.pill-sun { background: var(--sun-soft); color: var(--sun-deep); } .pill-jac { background: var(--jac-soft); color: var(--jac); }
.pill-leaf { background: var(--leaf-soft); color: #1F6B50; } .pill-gold { background: var(--gold-soft); color: #8A5A00; }
.pill-rose { background: var(--rose-soft); color: #A62742; } .pill-sky { background: var(--sky-soft); color: #1B5AA0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-weight: 800; font-size: .9rem; }
.field .help { font-size: .82rem; color: var(--ink-3); }
.input, input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="time"], input[type="number"], input[type="search"], select, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-sm); border: 2px solid var(--line); background: var(--paper); transition: border-color .12s; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--jac-light); outline: none; }
.form-row { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.check { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; }
.seg { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.seg button { min-height: 44px; padding: 8px 16px; border-radius: var(--r-pill); border: 2px solid var(--line); background: var(--paper); font-weight: 800; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--jac); border-color: var(--jac); color: #fff; }

/* Tables → cards on phones */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r); }
table.tbl { width: 100%; border-collapse: collapse; background: var(--paper); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.tbl th, .tbl td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); background: var(--sand); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #FFFCF8; }
.tbl .row-link { cursor: pointer; }

/* Lists */
.list { display: flex; flex-direction: column; gap: var(--space-3); }
.item { background: var(--paper); border-radius: var(--r); padding: var(--space-4); box-shadow: var(--shadow); display: grid; gap: var(--space-2); }
.item .item-head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: flex-start; flex-wrap: wrap; }
.item .item-title { font-weight: 800; }
.item .item-meta { color: var(--ink-3); font-size: .875rem; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.item .item-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.item.clickable { cursor: pointer; }
.item.clickable:hover { box-shadow: var(--shadow-lg); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--space-5); border-left: 3px solid var(--jac-soft); display: grid; gap: var(--space-4); }
.timeline li { position: relative; }
.timeline li::before { content: ''; position: absolute; left: calc(-1 * var(--space-5) - 8px); top: 6px; width: 13px; height: 13px; border-radius: 50%; background: var(--jac); border: 3px solid var(--cream); }
.timeline .when { font-size: .8rem; color: var(--ink-3); }

/* Feedback */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--r-sm); font-weight: 700; border: 2px solid transparent; }
.alert-ok { background: var(--leaf-soft); color: #1F6B50; border-color: #BFE6D4; }
.alert-err { background: var(--rose-soft); color: #A62742; border-color: #F3C2CD; }
.alert-info { background: var(--sky-soft); color: #1B5AA0; }
.alert-warn { background: var(--gold-soft); color: #8A5A00; }
.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--ink-3); background: var(--sand); border-radius: var(--r); }
.empty strong { color: var(--ink); display: block; margin-bottom: var(--space-2); font-size: 1.05rem; }
.skeleton { background: linear-gradient(90deg, var(--sand) 25%, #FBF4EC 50%, var(--sand) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--r-sm); min-height: 80px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--r-pill); font-weight: 800; box-shadow: var(--shadow-lg); z-index: 200; max-width: min(92vw, 520px); text-align: center; }
.toast.err { background: var(--rose); }
.modal-back { position: fixed; inset: 0; background: rgba(42, 31, 45, .45); display: grid; place-items: end center; z-index: 150; padding: 0; }
@media (min-width: 720px) { .modal-back { place-items: center; padding: var(--space-5); } }
.modal { background: var(--paper); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--space-5); box-shadow: var(--shadow-lg); }
@media (min-width: 720px) { .modal { border-radius: var(--r-lg); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }

/* Native <dialog> for confirmations and prompts (replaces window.confirm / prompt) */
dialog.confirm-dialog { border: 0; border-radius: var(--r-lg); padding: var(--space-5); width: min(92vw, 440px); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.confirm-dialog::backdrop { background: rgba(42, 31, 45, .45); }
dialog.confirm-dialog h3 { margin-bottom: var(--space-2); }
dialog.confirm-dialog .dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
dialog.confirm-dialog .dialog-actions .btn { flex: 1 1 auto; }

.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: var(--space-3); }
.divider { height: 1px; background: var(--line); margin-block: var(--space-4); }
.code-big { font-size: clamp(2.4rem, 8vw, 3.6rem); letter-spacing: .18em; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--jac); text-align: center; }
.tabs { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 4px; }
.tabs button { min-height: 44px; padding: 8px 16px; border-radius: var(--r-pill); border: 2px solid var(--line); background: var(--paper); font-weight: 800; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--sun); border-color: var(--sun); color: #fff; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
