/* Zapp Gateway: "Ledger" — warm paper / near-black ink, one money-green accent. */

:root {
  --bg: #f4f2ea;
  --surface: #fffefa;
  --surface-2: #eeebe1;
  --text: #121612;
  --muted: #566058;
  --line: #dcd8ca;
  --accent: #0e6b3c;
  --accent-press: #0a5630;
  --accent-text: #0b5a32;
  --on-accent: #ffffff;
  --accent-soft: #dcefe2;
  --in: #0e6b3c;
  --in-soft: #dcefe2;
  --warn: #8f5200;
  --warn-soft: #f8e8c9;
  --bad: #b3261e;
  --bad-soft: #fbe3df;
  --scrim: rgba(10, 14, 10, 0.5);
  --shadow: 0 1px 2px rgba(18, 22, 18, 0.06), 0 16px 40px -16px rgba(18, 22, 18, 0.35);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0c100d;
  --surface: #141a16;
  --surface-2: #1b231e;
  --text: #edf2ee;
  --muted: #99a79e;
  --line: #27312b;
  --accent: #3ddc84;
  --accent-press: #66e6a0;
  --accent-text: #5fe39a;
  --on-accent: #05140b;
  --accent-soft: #14301f;
  --in: #4be08e;
  --in-soft: #14301f;
  --warn: #f0b84e;
  --warn-soft: #33290f;
  --bad: #ff8a7e;
  --bad-soft: #3b1a16;
  --scrim: rgba(0, 0, 0, 0.65);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 44px -16px rgba(0, 0, 0, 0.75);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-color: var(--line) transparent; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 0.9375rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
body.modal-open { overflow: hidden; }
::selection { background: var(--accent); color: var(--on-accent); }
h1, h2, h3, p, dl, dd, ul { margin: 0; }
h1, h2, h3 { text-wrap: balance; letter-spacing: -0.02em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea { caret-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8125rem; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -48px; z-index: 90; padding: 10px 14px; border-radius: var(--r-sm); background: var(--surface); color: var(--text); }
.skip:focus { top: 12px; }
.icon { width: 18px; height: 18px; display: block; flex: 0 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--r);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 650; white-space: nowrap; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.12s var(--ease), opacity 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-press); }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn-danger.solid { background: var(--bad); color: #fff; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 0.875rem; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); transition: background 0.15s, color 0.15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-btn { border: 0; background: transparent; padding: 0; color: var(--accent-text); font-weight: 650; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; margin-bottom: 6px; font-size: 0.8125rem; font-weight: 650; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.select { width: auto; font-weight: 600; padding-right: 8px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent); }
.hint { margin-top: 5px; font-size: 0.8125rem; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mono-area { font: 0.75rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.form-error { margin-bottom: 14px; padding: 10px 12px; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-size: 0.875rem; }
.form-error:not([hidden]) { animation: shake 0.3s var(--ease); }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 60% { transform: translateX(3px); } }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Pills, chips ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: 22px; padding: 0 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--in-soft); color: var(--in); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { min-height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); font-size: 0.8125rem; font-weight: 650; transition: background 0.15s, color 0.15s; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- Sign in ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(380px, 100%); animation: rise 0.3s var(--ease) both; }
.mark { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.mark .icon { width: 22px; height: 22px; }
.mark.sm { width: 32px; height: 32px; border-radius: 10px; }
.mark.sm .icon { width: 17px; height: 17px; }
.login h1 { margin: 18px 0 20px; font-size: 1.75rem; line-height: 1.1; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.login .panel { padding: 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Shell ---------- */
.shell {
  min-height: 100dvh; display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: auto 1fr;
  grid-template-areas: "brand bar" "nav main";
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); min-width: 0; }
.brand strong { letter-spacing: -0.02em; white-space: nowrap; }
.role { padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 0.6875rem; font-weight: 750; }
.bar { grid-area: bar; display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 10px 24px; border-bottom: 1px solid var(--line); min-height: 61px; }
.bar .who { margin-right: 6px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.875rem; }
.nav { grid-area: nav; padding: 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.nav-item { position: relative; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 12px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-weight: 600; text-align: left; transition: background 0.15s, color 0.15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.main { grid-area: main; min-width: 0; padding: 24px; max-width: 1120px; width: 100%; animation: rise 0.22s var(--ease) both; }
.main:focus { outline: none; }
.main.silent { animation: none; }

@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "brand" "nav" "main"; }
  .brand { border-right: 0; padding: 12px 16px; padding-right: 150px; }
  .bar { position: fixed; top: 0; right: 0; z-index: 30; padding: 10px 12px; border: 0; min-height: 0; background: transparent; }
  .bar .who { display: none; }
  .nav { flex-direction: row; overflow-x: auto; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--line); scrollbar-width: none; position: sticky; top: 0; z-index: 20; background: var(--bg); }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: 0 0 auto; }
  .nav-item .icon { display: none; }
  .main { padding: 18px 16px 48px; }
}

/* ---------- Page structure ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 1.375rem; }
.page-head .actions, .toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar { margin-bottom: 14px; justify-content: space-between; }
.stamp { color: var(--muted); font-size: 0.8125rem; }
.section-title { margin: 28px 0 10px; font-size: 1rem; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.metric { padding: 14px 16px; min-width: 0; border: 0; background: transparent; text-align: left; border-left: 1px solid var(--line); }
.metric:first-child { border-left: 0; }
button.metric:hover { background: var(--surface-2); }
.metric dt { color: var(--muted); font-size: 0.8125rem; }
.metric dd { margin-top: 2px; font-size: 1.375rem; font-weight: 700; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.metric small { display: block; margin-top: 1px; color: var(--muted); font-size: 0.8125rem; font-weight: 500; letter-spacing: 0; }
@media (max-width: 640px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { border-left: 0; border-top: 1px solid var(--line); }
  .metric:nth-child(odd) { border-right: 1px solid var(--line); }
  .metric:nth-child(-n+2) { border-top: 0; }
}

.cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }
.card { padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 1rem; margin-bottom: 12px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.card h2 + .kv { border-top: 0; }
.kv > span:first-child { color: var(--muted); }
.kv > :last-child { text-align: right; overflow-wrap: anywhere; font-weight: 600; }
.card-actions { margin-top: 14px; }
.card.narrow { max-width: 600px; }

.banner { margin-bottom: 16px; padding: 12px 14px; border-radius: var(--r); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Tables ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 16px; background: var(--surface-2); color: var(--muted); font-size: 0.75rem; font-weight: 700; text-align: left; white-space: nowrap; }
td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
th.num, td.num { text-align: right; }
td.num { font-weight: 650; white-space: nowrap; }
tr[data-act] { cursor: pointer; }
tr[data-act]:hover td { background: var(--surface-2); }
tr.total td { background: var(--surface-2); font-weight: 700; }
.cell-btn { display: block; max-width: 100%; border: 0; padding: 0; background: transparent; text-align: left; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: 0.8125rem; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 2px; color: var(--text); }
.empty .btn { margin-top: 12px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 0.875rem; }
.skeleton { display: grid; gap: 10px; }
.skeleton i { display: block; height: 52px; border-radius: var(--r); background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 220% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton i:first-child { height: 34px; width: 40%; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

@media (max-width: 720px) {
  .table-wrap { border: 0; background: transparent; border-radius: 0; overflow: visible; }
  table, tbody, tr, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  tbody tr { margin-bottom: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
  td, tbody tr:first-child td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 0.8125rem; font-weight: 500; flex: 0 0 auto; }
  td.first::before { display: none; }
  td.first { padding-bottom: 6px; }
  td.num { text-align: right; }
  tr.total { border-color: var(--text); }
  tr[data-act]:hover td { background: transparent; }
  .cell-btn { white-space: normal; }
}

/* ---------- Dialogs ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: 16px; background: var(--scrim); }
.modal.active { display: flex; animation: fade 0.15s ease-out; }
.modal.closing { animation: fadeOut 0.12s ease-in forwards; }
#dialog { z-index: 60; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
.sheet { width: min(500px, 100%); max-height: min(90dvh, 760px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); animation: pop 0.2s var(--ease); }
.sheet.narrow { width: min(400px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font-size: 1.0625rem; }
.sheet-body { padding: 8px 20px 20px; overflow: auto; overscroll-behavior: contain; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.facts { margin: 0; }
.fact { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.fact:first-child { border-top: 0; }
.fact dt { color: var(--muted); flex: 0 0 auto; }
.fact dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; max-width: 66%; }
.sheet h3 { margin: 18px 0 4px; font-size: 0.9375rem; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.qr-box { width: fit-content; margin: 4px auto 14px; padding: 10px; border-radius: var(--r-lg); background: #fff; animation: rise 0.3s var(--ease) both; }
.qr-box img { display: block; width: min(220px, 62vw); height: auto; }
.qr-box.small { margin: 0 0 12px; padding: 6px; }
.qr-box.small img { width: 120px; }
.countdown { height: 3px; margin: 0 0 14px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.countdown i { display: block; height: 100%; background: var(--accent); transform-origin: left; transition: transform 1s linear; }
.center { text-align: center; }
.secret { display: flex; gap: 8px; align-items: stretch; }
.secret code { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); overflow-wrap: anywhere; font: 0.8125rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); overflow-x: auto; font: 0.8125rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hist { padding: 12px 0; border-top: 1px solid var(--line); }
.hist code { display: block; margin: 6px 0 8px; color: var(--muted); word-break: break-all; font: 0.6875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.success-mark { width: 64px; height: 64px; margin: 4px auto 10px; display: block; }
.success-ring { fill: var(--in-soft); stroke: var(--in); stroke-width: 3; stroke-dasharray: 252; stroke-dashoffset: 252; animation: draw 0.5s var(--ease) forwards; }
.success-check { fill: none; stroke: var(--in); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 52; stroke-dashoffset: 52; animation: draw 0.35s var(--ease) 0.35s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: min(400px, calc(100% - 32px)); justify-items: center; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: var(--r); background: var(--text); color: var(--bg); font-size: 0.875rem; font-weight: 600; box-shadow: var(--shadow); animation: toastIn 0.25s var(--ease) both; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { animation: toastOut 0.18s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}

.mt-12 { margin-top: 12px; }
.first-title { margin-top: 0; }
.input.search { width: 220px; }
.settings > div > .card { max-width: 640px; }
.cols.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .cols.settings { grid-template-columns: 1fr; } .input.search { width: 100%; } }

@media (max-width: 640px) { .metric:last-child:nth-child(odd) { grid-column: 1 / -1; border-right: 0; } }
