/* REALM Pay: REALM look (dark forest green, orange, white). System fonts only (strict CSP, fast). */
:root {
  --green: #0b2e1a; --green-2: #12452a; --green-3: #1d5c3a; --orange: #f58214; --orange-ink: #8a4300;
  --ink: #10261a; --muted: #536459; --line: #dfe7e1; --bg: #f4f7f4; --card: #fff;
  --good: #11743f; --good-bg: #e5f4ea; --warn: #a33a12; --warn-bg: #fdece4; --info-bg: #eef3fb; --info: #23466e;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 46, 26, .06), 0 4px 16px rgba(11, 46, 26, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--green-3); text-underline-offset: 2px; }
a:hover { color: var(--green); }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); letter-spacing: -.01em; }
p, li { text-wrap: pretty; }
.num, .table td.r, .tile-value, .totals span:last-child { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.muted, .sub, .hint { color: var(--muted); }
.sub { display: block; font-size: .85rem; }
.hint { font-size: .85rem; }
.center { text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.wrap-narrow { max-width: 860px; margin: 0 auto; padding: 20px 16px 8px; }

/* Wordmark */
.wordmark { font-weight: 800; letter-spacing: .12em; color: #fff; text-decoration: none; font-size: 1.05rem; margin: 0; white-space: nowrap; }
.wordmark span { color: var(--orange); letter-spacing: .04em; }
.wordmark:hover { color: #fff; }
.wordmark-dark { color: var(--green); }

/* Top bar */
.topbar { background: var(--green); color: #fff; position: sticky; top: 0; z-index: 5; }
.topbar-in { display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: #d6e5da; text-decoration: none; padding: 10px 12px; border-radius: 999px; font-weight: 600; font-size: .95rem; white-space: nowrap; transition: background-color 150ms ease-out, color 150ms ease-out; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a[aria-current="page"] { background: rgba(245, 130, 20, .18); color: #fff; box-shadow: inset 0 0 0 1px rgba(245, 130, 20, .5); }
.who { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: #cfe0d4; }
.who form { margin: 0; }
.who-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-banner { background: #fff4e6; color: var(--orange-ink); border-bottom: 1px solid #f6d3ae; padding: 10px 16px; text-align: center; font-size: .95rem; }

.main { padding-top: 24px; padding-bottom: 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 4px; font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--orange-ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card-title { font-size: 1.05rem; margin-bottom: 12px; }
.sub-title { font-size: .95rem; margin: 16px 0 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.grid-2 > .card, .grid-detail > .card { margin: 0; }
.nowrap { white-space: nowrap; }
.grid-detail { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.stack > .card:last-child { margin-bottom: 0; }
.empty { text-align: center; padding: 40px 20px; }
.empty h2 { margin-bottom: 8px; }

/* Tiles */
.tile-group { margin-bottom: 18px; }
.tile-cur { font-size: .8rem; letter-spacing: .1em; color: var(--muted); margin-bottom: 8px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
  transition-property: transform, box-shadow, border-color; transition-duration: 150ms; transition-timing-function: ease-out; }
.tile:hover { transform: translateY(-1px); border-color: #c5d6ca; color: var(--ink); box-shadow: 0 2px 4px rgba(11, 46, 26, .06), 0 10px 24px rgba(11, 46, 26, .08); }
.tile-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.tile-value { font-size: clamp(1.3rem, 1rem + 1vw, 1.75rem); font-weight: 800; letter-spacing: -.01em; }
.tile-sub { font-size: .8rem; color: var(--muted); }
.tile-warn { border-left: 4px solid var(--warn); }
.tile-good { border-left: 4px solid var(--good); }
.tile:first-child { border-left: 4px solid var(--orange); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid #c9d6cd; background: #fff; color: var(--green);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition-property: transform, background-color, box-shadow, border-color; transition-duration: 150ms; transition-timing-function: ease-out; }
.btn:hover { background: #f1f6f2; border-color: #b4c7ba; color: var(--green); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-2); color: #fff; border-color: var(--green-2); }
.btn-pay { background: var(--orange); border-color: var(--orange); color: #1d1200; font-size: 1.1rem; min-height: 54px; padding: 12px 26px; box-shadow: 0 1px 0 rgba(0, 0, 0, .08), 0 6px 16px rgba(245, 130, 20, .28); }
.btn-pay:hover { background: #ff9533; border-color: #ff9533; color: #1d1200; }
.btn-quiet { background: transparent; border-color: transparent; }
.topbar .btn-quiet { color: #fff; border-color: rgba(255, 255, 255, .25); }
.topbar .btn-quiet:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.btn-danger-quiet { color: var(--warn); border-color: #efc7b6; }
.btn-danger-quiet:hover { background: var(--warn-bg); color: var(--warn); border-color: #e7ad95; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; font-size: 1.4rem; line-height: 1; color: var(--muted); cursor: pointer; transition: background-color 150ms ease-out, color 150ms ease-out; }
.icon-btn:hover { background: var(--warn-bg); color: var(--warn); }

/* Chips */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .02em; vertical-align: middle; white-space: nowrap; border: 1px solid transparent; }
.chip-draft { background: #eef1ef; color: #48574d; border-color: #dbe2dd; }
.chip-sent { background: var(--info-bg); color: var(--info); border-color: #d6e1f2; }
.chip-viewed { background: #f1ecfb; color: #4c3a86; border-color: #e2d9f6; }
.chip-paid { background: var(--good-bg); color: var(--good); border-color: #c8e6d2; }
.chip-part_paid { background: #fff4e6; color: var(--orange-ink); border-color: #f6d3ae; }
.chip-void { background: #f2f2f2; color: #666; border-color: #e0e0e0; text-decoration: line-through; }
.chip-refunded { background: #f7eef1; color: #7c2d46; border-color: #efd7df; }
.chip-overdue { background: var(--warn-bg); color: var(--warn); border-color: #f3cbb9; }
.chip-demo { background: #fff4e6; color: var(--orange-ink); border-color: #f6d3ae; }
.warn { color: var(--warn); font-weight: 650; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 10px; border-bottom: 1px solid #edf1ee; vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table-click tbody tr { transition: background-color 120ms ease-out; }
.table-click tbody tr:hover { background: #f7faf8; }
.strong { font-weight: 700; text-decoration: none; }

/* Forms */
.form label, .filters label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
.form label em, .filters label em { font-style: normal; font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #c9d6cd; border-radius: var(--radius-sm); padding: 10px 12px; min-height: 44px; width: 100%; transition: border-color 150ms ease-out, box-shadow 150ms ease-out; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-3); box-shadow: 0 0 0 3px rgba(29, 92, 58, .18); }
input[readonly] { background: #f6f8f6; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.span-2 { grid-column: span 2; }
.narrow { max-width: 640px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px; }
.filters label { margin: 0; flex: 1 1 160px; }
.filters .grow { flex: 1 1 300px; }
.lines td { padding: 6px 6px; vertical-align: middle; }
.lines td:first-child { min-width: 220px; }
.in-num { text-align: right; max-width: 120px; }
.line-total { white-space: nowrap; font-weight: 650; }
.totals-preview, .totals { margin: 16px 0 16px auto; max-width: 340px; display: grid; gap: 6px; }
.totals-preview > div, .totals > div { display: flex; justify-content: space-between; gap: 16px; }
.totals .grand, .totals-preview .grand { font-size: 1.15rem; font-weight: 800; border-top: 1px solid var(--line); padding-top: 8px; }
.totals .due { background: #fff4e6; border-radius: 10px; padding: 10px 12px; font-weight: 800; font-size: 1.1rem; }
.hint { margin: 4px 0 0; font-weight: 400; }
a.hint { font-weight: 600; }

/* Flash */
.flash { border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-info { background: var(--good-bg); border-color: #c8e6d2; color: #0d4d2b; }
.flash-error { background: var(--warn-bg); border-color: #f3cbb9; color: #7a2a0b; }

/* Detail */
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; }
.facts dt { font-size: .8rem; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.facts .big { font-size: 1.25rem; font-weight: 800; }
.share { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.share label { font-size: .85rem; font-weight: 600; display: block; margin-bottom: 6px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.timeline, .feed, .plain-list { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #b4c7ba; }
.timeline li.tl-payment::before { border-color: var(--good); background: var(--good-bg); }
.timeline li.tl-checkout::before { border-color: var(--orange); }
.tl-what { display: block; font-weight: 600; font-size: .92rem; }
.tl-when { display: block; font-size: .8rem; color: var(--muted); }
.feed li, .plain-list li { padding: 8px 0; border-bottom: 1px solid #edf1ee; font-size: .92rem; }
.feed li:last-child, .plain-list li:last-child { border-bottom: 0; }

.site-foot { text-align: center; font-size: .8rem; color: var(--muted); padding: 24px 16px 32px; }

/* Public invoice */
.public { background: linear-gradient(var(--green), var(--green)) top / 100% 180px no-repeat, var(--bg); min-height: 100vh; }
.demo-ribbon { background: #fff4e6; color: var(--orange-ink); border: 1px solid #f6d3ae; border-radius: var(--radius-sm); padding: 10px 14px; margin: 0 0 14px; font-size: .92rem; text-align: center; }
.demo-ribbon-big { font-size: 1rem; }
.invoice { padding: clamp(18px, 4vw, 40px); }
.inv-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 3px solid var(--orange); }
.inv-brand { margin: 4px 0 0; font-weight: 650; color: var(--muted); }
.inv-meta { text-align: right; }
.inv-meta h1 { font-size: 1.6rem; }
.inv-number { margin: 4px 0 0; font-weight: 700; font-size: 1.05rem; }
.stamp { display: inline-block; margin: 8px 0 0; padding: 4px 12px; border: 2px solid currentColor; border-radius: 8px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; transform: rotate(-3deg); }
.stamp-paid { color: var(--good); } .stamp-refunded { color: #7c2d46; } .stamp-void { color: #777; } .stamp-part_paid { color: var(--orange-ink); }
.inv-parties { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; padding: 20px 0; }
.inv-parties h2 { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 6px; }
.inv-parties p { margin: 0; font-size: .93rem; }
.inv-dl { margin: 0; font-size: .93rem; display: grid; gap: 2px; }
.inv-dl div { display: flex; justify-content: space-between; gap: 10px; }
.inv-dl dt { color: var(--muted); } .inv-dl dd { margin: 0; font-weight: 600; }
.inv-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
.inv-bottom .totals { margin: 0 0 0 auto; flex: 1 1 280px; }
.qr { width: 132px; }
.qr svg { width: 120px; height: 120px; display: block; }
.qr .hint { font-size: .75rem; margin-top: 2px; }
.inv-notes { background: #f6f8f6; border-radius: var(--radius-sm); padding: 12px 14px; white-space: pre-line; }
.inv-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.inv-actions form { margin: 0; }
.receipt { margin-top: 22px; border: 1px solid #c8e6d2; background: var(--good-bg); border-radius: var(--radius-sm); padding: 14px 16px; }
.receipt h2 { font-size: 1rem; color: var(--good); margin-bottom: 6px; }
.receipt ul { list-style: none; margin: 0; padding: 0; }
.receipt li { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .93rem; }
.safety { margin: 20px 0 0; font-size: .82rem; color: var(--muted); text-align: center; }

/* Pop-ups after checkout */
.popup { display: flex; gap: 14px; align-items: flex-start; border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow); border: 1px solid; background: #fff; animation: pop-in 260ms ease-out both; }
.popup p { margin: 0; }
.popup-title { font-weight: 800; font-size: 1.05rem; margin-bottom: 2px !important; }
.popup-icon { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; }
.popup-good { border-color: #c8e6d2; } .popup-good .popup-icon { background: var(--good); }
.popup-info { border-color: #d6e1f2; } .popup-info .popup-icon { background: var(--info); }
.popup-bad { border-color: #f3cbb9; } .popup-bad .popup-icon { background: var(--warn); }
.popup-quiet { border-color: #e0e0e0; } .popup-quiet .popup-icon { background: #7a817c; }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .popup { animation: none; } .btn:active { transform: none; } .tile:hover { transform: none; } }

/* Demo checkout */
.checkout { text-align: center; padding: clamp(20px, 5vw, 44px); }
.checkout h1 { font-size: 1.4rem; }
.checkout-amount { font-size: clamp(2rem, 1.5rem + 2vw, 2.8rem); font-weight: 800; margin: 10px 0; letter-spacing: -.02em; }
.fake-card { margin: 18px auto; max-width: 340px; display: flex; justify-content: space-between; padding: 18px; border-radius: 14px; background: linear-gradient(135deg, var(--green-3), var(--green)); color: #e6efe9; font-family: ui-monospace, Menlo, monospace; box-shadow: var(--shadow); }
.checkout-actions { display: grid; gap: 10px; max-width: 360px; margin: 20px auto 0; }
.checkout-actions .btn { width: 100%; }
.checkout-actions form { margin: 0; }
.landing { text-align: center; padding: 36px 24px; margin-top: 40px; }
.landing h1 { margin: 12px 0; }
.notice { max-width: 560px; margin: 60px auto 0; text-align: center; }
.notice .wordmark { color: var(--green); margin-bottom: 10px; }
body.plain { background: var(--bg); padding: 0 16px; }

/* Phone */
@media (max-width: 860px) {
  .grid-detail { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inv-parties { grid-template-columns: 1fr; gap: 14px; }
  .span-2 { grid-column: auto; }
}
@media (max-width: 640px) {
  .topbar-in { gap: 6px 12px; padding-top: 8px; padding-bottom: 6px; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -6px; }
  .who { margin-left: auto; }
  .who-name { display: none; }
  .card { padding: 16px; }
  .page-head { align-items: flex-start; }
  .actions { width: 100%; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
  .table td:not([data-label])::before { content: none; }
  .table td .sub { display: block; }
  .tiles { grid-template-columns: 1fr; gap: 6px; }
  .tile { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 10px 14px; border-radius: 12px; }
  .tile-label { grid-column: 1; }
  .tile-sub { grid-column: 1; font-size: .75rem; }
  .tile-value { grid-column: 2; grid-row: 1 / span 2; font-size: 1.15rem; }
  .tile-group { margin-bottom: 12px; }
  .lines td { display: flex; align-items: center; }
  .lines td::before { min-width: 90px; }
  .lines td:first-child { min-width: 0; }
  .in-num { max-width: none; }
  .lines tr { position: relative; padding-right: 0; }
  .lines td:last-child { justify-content: flex-end; }
  .inv-meta { text-align: left; }
  .inv-bottom { flex-direction: column-reverse; align-items: stretch; }
  .inv-bottom .totals { flex: none; margin: 0; }
  .qr { margin: 0 auto; text-align: center; }
  .qr svg { margin: 0 auto; }
  .inv-actions .btn, .inv-actions form { width: 100%; }
  .totals, .totals-preview { max-width: none; }
}

/* Print = the PDF */
@media print {
  @page { margin: 14mm; }
  body, .public { background: #fff !important; }
  .no-print, .demo-ribbon, .popup, .site-foot { display: none !important; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .wrap-narrow { max-width: none; padding: 0; }
  .table thead { display: table-header-group; }
  a { color: inherit; text-decoration: none; }
}
