:root {
  --ink: #161a1d;
  --muted: #606970;
  --line: #d8dddf;
  --line-strong: #aeb6ba;
  --surface: #ffffff;
  --soft: #f3f5f4;
  --accent: #174b3d;
  --accent-hover: #0f382d;
  --danger: #8b2f2f;
  --danger-soft: #fff3f1;
  --success: #1e6246;
  --success-soft: #eef8f2;
  color: var(--ink);
  background: var(--surface);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--surface); }
body, button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-underline-offset: 3px; }
::selection { color: white; background: var(--accent); }

.skip-link {
  position: fixed; inset: 10px auto auto 10px; z-index: 20; padding: 10px 14px;
  color: white; background: var(--ink); transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

:focus-visible { outline: 3px solid rgba(23, 75, 61, .32); outline-offset: 3px; }

.site-header {
  min-height: 70px; padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  border-bottom: 1px solid #e9ecea; background: rgba(255, 255, 255, .98);
}
.brand { display: flex; align-items: center; gap: 11px; min-height: 44px; text-decoration: none; font-weight: 760; letter-spacing: -.015em; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; color: white; background: var(--ink); font-size: 11px; letter-spacing: .04em; }
.user-menu { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 14px; }
.user-menu form { margin: 0; }
.link-button { min-height: 44px; padding: 0; border: 0; color: var(--ink); background: none; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

main { min-height: calc(100vh - 128px); }
footer { padding: 20px; border-top: 1px solid #eceeec; color: #737b80; font-size: 12px; text-align: center; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 18px; font-size: clamp(38px, 5vw, 66px); line-height: 1.03; letter-spacing: -.04em; text-wrap: balance; }
.lead { max-width: 66ch; color: var(--muted); font-size: 18px; line-height: 1.65; }

.primary, .secondary, .export-button {
  min-height: 48px; border: 1px solid var(--ink); padding: 12px 20px; font-weight: 720;
  cursor: pointer; text-decoration: none; transition: background-color .16s ease-out, color .16s ease-out, border-color .16s ease-out;
}
.primary, .secondary { color: white; background: var(--ink); }
.primary:hover, .secondary:hover { border-color: var(--accent); background: var(--accent); }
.export-button { display: inline-flex; align-items: center; justify-content: center; color: var(--ink); background: white; }
.export-button:hover { color: white; background: var(--ink); }

.alert { margin: 24px 0; padding: 15px 17px; border: 1px solid #e4bebb; color: #6f2222; background: var(--danger-soft); line-height: 1.5; }
.alert.success { border-color: #b8d8c7; color: #174a35; background: var(--success-soft); }

.login-shell { min-height: calc(100vh - 128px); display: grid; place-items: center; padding: 60px 24px; background: var(--soft); }
.login-card { width: min(100%, 480px); padding: clamp(30px, 6vw, 50px); border: 1px solid var(--line); background: white; box-shadow: 0 22px 60px rgba(16, 28, 23, .08); }
.login-card h1 { font-size: clamp(34px, 7vw, 48px); }
.login-card .lead { font-size: 15px; }
.login-form { display: grid; gap: 18px; margin-top: 30px; }
.login-form label, .filters label { display: grid; gap: 7px; color: #41484c; font-size: 13px; font-weight: 700; }
.login-form input, .filters input, .filters select {
  width: 100%; min-height: 48px; border: 1px solid var(--line-strong); padding: 11px 13px; color: var(--ink); background: white; outline: none;
}
.login-form input:focus, .filters input:focus, .filters select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 75, 61, .14); }
.back-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 22px; color: var(--muted); font-size: 13px; }
.top-back { margin: 0 0 34px; }

.chooser { max-width: 1040px; margin: 0 auto; padding: clamp(64px, 9vw, 110px) 24px 90px; }
.chooser-copy { max-width: 720px; }
.portal-options { display: grid; margin-top: 54px; border-top: 1px solid var(--line); }
.portal-options a {
  min-height: 122px; padding: 25px 8px; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  border-bottom: 1px solid var(--line); text-decoration: none; transition: color .18s ease-out;
}
.portal-options a:hover { color: var(--accent); }
.portal-options a > span:first-child { display: grid; gap: 7px; min-width: 0; }
.portal-options strong { font-size: clamp(25px, 4vw, 34px); letter-spacing: -.03em; }
.portal-options small { color: var(--muted); font-size: 14px; }
.portal-options a > span:last-child { font-size: 28px; transition: transform .18s ease-out; }
.portal-options a:hover > span:last-child { transform: translateX(8px); }
.session-note { margin: 28px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.form-page { max-width: 1180px; margin: 0 auto; padding: 60px 24px 100px; }
.form-heading { display: flex; justify-content: space-between; gap: 36px; align-items: flex-end; margin-bottom: 30px; }
.form-heading h1 { margin-bottom: 10px; }
.form-heading p { margin: 0; color: var(--muted); line-height: 1.5; }
.form-heading p span, .field > span > b { color: var(--danger); }
.record-meta { max-width: 240px; padding-inline-start: 20px; border-inline-start: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.6; text-align: end; }
.record-meta strong { color: var(--ink); }
.customer-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-inline-start: 1px solid var(--line); }
.field {
  position: relative; min-width: 0; min-height: 84px; padding: 13px 16px 12px;
  display: flex; flex-direction: column; gap: 8px; border-inline-end: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.field > span, .radio-field legend { color: #343a3e; font-size: 13px; font-weight: 620; }
.field input, .field textarea { min-width: 0; width: 100%; border: 0; padding: 4px 0; color: var(--ink); background: transparent; outline: 0; font-size: 16px; }
.field:focus-within { box-shadow: inset 0 0 0 2px var(--accent); z-index: 1; }
.field:has([aria-invalid="true"]) { background: var(--danger-soft); }
.radio-field { margin: 0; flex-direction: row; align-items: center; gap: 18px; }
.radio-field legend { float: inline-start; margin-inline-end: 2px; }
.radio-field label { min-height: 44px; display: flex; align-items: center; gap: 7px; }
.radio-field input { width: auto; accent-color: var(--accent); }
.textarea-field { min-height: 126px; }
.field textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.uppercase { text-transform: uppercase; }
.field-error { color: var(--danger); font-size: 12px; line-height: 1.35; }
.form-actions {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 24px;
  padding: 24px; border-inline-end: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.form-actions p { max-width: 58ch; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.admin-page, .detail-page { max-width: 1260px; margin: 0 auto; padding: 66px 24px 100px; }
.admin-title, .detail-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; }
.admin-title h1 { margin-bottom: 10px; }
.admin-title p, .detail-title p { color: var(--muted); }
.tabs { display: flex; gap: 30px; margin-top: 52px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { min-height: 48px; padding: 14px 0; color: var(--muted); text-decoration: none; white-space: nowrap; font-size: 14px; }
.tabs a.active { border-bottom: 2px solid var(--ink); color: var(--ink); font-weight: 720; }
.filters { margin: 24px 0; padding: 20px; display: grid; grid-template-columns: 1fr 1fr 1fr 1.45fr auto auto; gap: 12px; align-items: end; background: var(--soft); }
.reset { min-height: 48px; padding: 12px 4px; display: inline-flex; align-items: center; color: var(--muted); font-size: 13px; }
.results-meta { margin: 28px 0 12px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { padding: 16px 17px; border-bottom: 1px solid var(--line); text-align: start; font-size: 13px; }
th { color: var(--muted); background: #fafbfa; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8faf9; }
.portal-badge { display: inline-block; padding: 5px 8px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.portal-badge.lotto { color: #20543c; background: #e7f2eb; }
.portal-badge.club { color: #344b78; background: #ebeff8; }
.table-link { min-height: 44px; display: inline-flex; align-items: center; font-weight: 720; }
.empty { padding: 52px; color: var(--muted); text-align: center; }
.pagination { margin-top: 22px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; color: var(--muted); font-size: 13px; }
.pagination a { min-height: 44px; display: inline-flex; align-items: center; color: var(--ink); font-weight: 700; }
.pagination a:last-child { justify-self: end; }

.detail-page > .top-back { margin-bottom: 38px; }
.detail-title { padding-bottom: 32px; border-bottom: 1px solid var(--line); }
.detail-title h1 { margin: 14px 0 8px; font-size: clamp(36px, 5vw, 52px); overflow-wrap: anywhere; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(240px, .8fr); gap: 50px; margin-top: 36px; }
.detail-grid { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-inline-start: 1px solid var(--line); border-top: 1px solid var(--line); }
.detail-grid div { min-width: 0; min-height: 78px; padding: 16px 18px; border-inline-end: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-grid dt { margin-bottom: 9px; color: var(--muted); font-size: 12px; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }
.detail-layout aside { padding-inline-start: 28px; border-inline-start: 1px solid var(--line); }
.detail-layout aside h2 { font-size: 17px; }
.history { margin: 24px 0 0; padding: 0; list-style: none; }
.history li { display: flex; gap: 12px; padding-bottom: 24px; }
.history-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.history li div { display: grid; gap: 5px; }
.history small { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .customer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-layout aside { padding: 30px 0 0; border-inline-start: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 600px) {
  .site-header { min-height: 62px; padding: 0 16px; }
  .brand > span:last-child, .user-menu > span { display: none; }
  .chooser, .form-page, .admin-page, .detail-page { padding-inline: 16px; }
  .login-shell { padding: 36px 16px; }
  .login-card { padding: 30px 22px; }
  .form-heading, .admin-title, .detail-title { align-items: flex-start; flex-direction: column; }
  .record-meta { max-width: none; padding: 14px 0 0; border-inline-start: 0; border-top: 1px solid var(--line); text-align: start; }
  .customer-grid, .detail-grid, .filters { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .primary, .export-button { width: 100%; }
  .portal-options a { min-height: 108px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .primary, .secondary, .export-button, .portal-options a { transition: none; }
}
