:root {
  color-scheme: light dark;
  --paper: #f5f3ef;
  --panel: #fff;
  --card: #f7f6f3;
  --ink: #292927;
  --muted: #77766f;
  --line: #dedbd4;
  --accent: #bd8c4f;
  --accent-soft: #fff0dc;
  --danger: #c92312;
  --danger-hover: #a91d10;
  --radius: 15px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 360px; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.hidden { display: none !important; }
.page-shell { width: min(1480px, calc(100% - 40px)); margin: 28px auto; }
.site-header, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.site-header { min-height: 138px; display: flex; align-items: center; gap: 32px; padding: 22px 34px; }
.brand { display: block; flex: 0 0 216px; line-height: 0; }
.brand img { display: block; width: 100%; height: auto; }
.site-heading { flex: 1 1 auto; min-width: 0; }
.site-heading h1 { margin: 0; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -0.035em; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 36px); }
h2 { margin-bottom: var(--space-2); font-size: 25px; }
h3 { margin-bottom: var(--space-3); font-size: 17px; }
.signed-in-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.panel { padding: 24px; }
.auth-panel { width: min(620px, 100%); margin: 42px auto; padding: 32px; }
.muted { color: var(--muted); line-height: 1.55; }
.subtle { color: var(--muted); font-size: 13px; line-height: 1.5; }
.form-stack { display: flex; flex-direction: column; gap: 10px; margin-top: var(--space-4); }
label { font-size: 13px; font-weight: 700; }
input, select { width: 100%; min-width: 0; height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; color: var(--ink); background: var(--panel); }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.ui-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; border: 1px solid var(--line); color: var(--ink); background: var(--card); text-decoration: none; cursor: pointer; font-weight: 750; text-transform: uppercase; letter-spacing: .065em; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.ui-button:hover { background: #eeeae3; }
.ui-button:disabled { cursor: not-allowed; opacity: .55; }
.ui-button--header { min-height: 44px; padding: 0 17px; border-radius: 10px; font-size: 13px; }
.ui-button--card { min-height: 38px; padding: 0 13px; border-radius: 9px; font-size: 12px; }
.ui-button--neutral { background: var(--card); }
.ui-button--positive { background: var(--accent-soft); border-color: #f0dfc8; }
.ui-button--positive:hover { background: #ffe4bf; }
.ui-button--destructive { color: #fff; background: var(--danger); border-color: var(--danger); }
.ui-button--destructive:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.text-button { width: fit-content; padding: 6px 0; border: 0; color: var(--ink); background: transparent; cursor: pointer; font-size: 12px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--muted); }
.status { min-height: 1.5em; margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="success"] { color: #247346; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-panel:has(.spinner) { display: flex; align-items: center; gap: 14px; }
.auth-panel:has(.spinner) p { margin: 0; }
.setup-key-row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.setup-key-row code { flex: 1; overflow-wrap: anywhere; font-size: 15px; font-weight: 700; letter-spacing: .08em; }
.backup-codes { margin-top: var(--space-5); padding: 20px; border: 1px solid #a8d8b8; border-radius: 12px; background: #edf8f0; }
.backup-codes h3 { margin-bottom: 8px; }
.backup-codes p { color: #3e6950; font-size: 13px; line-height: 1.5; }
.backup-codes ul { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 8px 16px; margin: 16px 0; padding: 0; list-style: none; }
.backup-codes li { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }
.admin-toolbar, .section-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-toolbar { margin: 34px 0 18px; }
.admin-toolbar h2 { margin: 0; }
.admin-grid { display: grid; grid-template-columns: minmax(265px, 340px) minmax(0, 1fr); align-items: start; gap: 18px; }
.customer-browser { position: sticky; top: 18px; }
.gift-section h2 { font-size: 20px; }
.gift-section > .subtle { margin-bottom: 14px; }
.gift-section .form-stack { margin-top: 0; }
.gift-invitation-list { margin-top: 12px; }
.section-divider { height: 1px; margin: 22px 0; border: 0; background: var(--line); }
.search-row, .inline-form { display: flex; align-items: center; gap: 9px; }
.search-row { margin-top: 8px; }
.search-row input { flex: 1; }
.customer-list { display: grid; gap: 7px; margin-top: 12px; }
.customer-row { width: 100%; display: block; padding: 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--card); text-align: left; cursor: pointer; }
.customer-row:hover, .customer-row[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.customer-row strong, .customer-row span { display: block; overflow-wrap: anywhere; }
.customer-row span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 16px; }
.pagination .ui-button { padding: 0 9px; font-size: 10px; }
.customer-detail { min-width: 0; }
.customer-detail-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.customer-detail-heading h2 { margin-bottom: 4px; overflow-wrap: anywhere; }
.customer-detail-heading .muted { overflow-wrap: anywhere; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 10px; margin: 20px 0 24px; }
.metric-grid > div { min-height: 80px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.metric-grid span { color: var(--muted); font-size: 12px; }
.metric-grid strong { font-size: 24px; }
.detail-section { padding: 20px 0; border-top: 1px solid var(--line); }
.detail-section > h3 { margin-bottom: 14px; }
.detail-section .subtle { margin: 8px 0 0; }
.grant-form { display: grid; grid-template-columns: 1.2fr .65fr 1.5fr auto; align-items: end; gap: 8px; }
.grant-form label { grid-row: 1; }
.grant-form select, .grant-form input { grid-row: 2; }
.grant-form button { grid-column: 4; grid-row: 2; }
.inline-form { align-items: stretch; flex-wrap: wrap; }
.inline-form input:first-child { flex: 1.2 1 180px; }
.inline-form input:nth-child(2) { flex: 1 1 160px; }
.inline-form button { flex: 0 0 auto; }
.record-list { display: grid; gap: 9px; }
.record-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.record-main { min-width: 0; flex: 1; }
.record-main strong { display: block; overflow-wrap: anywhere; }
.record-meta { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.record-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.transaction-id { max-width: 390px; display: inline-block; overflow-wrap: anywhere; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.transaction-value { font-weight: 750; white-space: nowrap; }
.section-heading-row h3 { margin: 0; }
.section-heading-row form { margin: 0; }
.security-form { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.security-form h3 { margin: 0 0 4px; }
footer { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 12px; }

@media (prefers-color-scheme: dark) {
  :root { --paper: #171716; --panel: #222220; --card: #2b2a28; --ink: #f2f0ed; --muted: #aaa79f; --line: #44423e; --accent-soft: #493824; }
  .ui-button:hover { background: #383632; }
  .ui-button--positive:hover { background: #5d462a; }
  .backup-codes { border-color: #3d7650; background: #1d3325; }
  .backup-codes p { color: #afd7ba; }
  .customer-row:hover, .customer-row[aria-current="true"] { background: #493824; }
  .status[data-kind="success"] { color: #8bd4a5; }
}

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .customer-browser { position: static; }
  .customer-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  body { min-width: 320px; }
  .page-shell { width: min(100% - 20px, 1480px); margin: 10px auto; }
  .site-header { min-height: auto; display: grid; grid-template-columns: minmax(95px, 132px) 1fr; gap: 12px; padding: 15px; }
  .brand { width: 100%; }
  .site-heading h1 { font-size: 20px; }
  .signed-in-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .ui-button--header { min-height: 40px; padding: 0 11px; font-size: 11px; }
  .auth-panel, .panel { padding: 17px; }
  .auth-panel { margin: 18px auto; }
  .admin-toolbar { margin-top: 22px; }
  .customer-list { grid-template-columns: 1fr; }
  .customer-detail-heading { display: block; }
  .customer-detail-heading > .subtle { display: block; margin-top: 8px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grant-form { grid-template-columns: 1fr 90px; }
  .grant-form label:nth-of-type(1) { grid-column: 1; }
  .grant-form label:nth-of-type(2) { grid-column: 2; }
  .grant-form select { grid-column: 1; }
  .grant-form input { grid-column: 2; }
  .grant-form label:nth-of-type(3), .grant-form input:nth-of-type(2) { grid-column: 1 / -1; }
  .grant-form button { grid-column: 1 / -1; grid-row: auto; justify-self: start; }
  .inline-form { align-items: stretch; }
  .inline-form button { width: 100%; }
  .record-row { flex-direction: column; }
  .record-actions { justify-content: flex-start; }
  .section-heading-row { align-items: flex-start; flex-direction: column; }
  .section-heading-row form { width: 100%; }
  .section-heading-row form button { width: 100%; }
  .setup-key-row { align-items: stretch; flex-direction: column; }
}
