:root {
  --paper: #f2ecdf;
  --paper-light: #faf7ef;
  --ink: #171713;
  --muted: #6b665b;
  --gold: #9b7428;
  --gold-pale: #ded0ac;
  --rule: #b9b09d;
  --danger: #8b2f25;
  --serif: 'Iowan Old Style', 'Baskerville', 'Times New Roman', serif;
  --sans: 'Avenir Next', 'Gill Sans', sans-serif;
  --mono: 'SFMono-Regular', 'Cascadia Mono', monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: var(--sans); }
body { margin: 0; min-height: 100vh; background-color: var(--paper); background-image: radial-gradient(rgba(23,23,19,.055) .6px, transparent .6px); background-size: 5px 5px; }
button, input, select { font: inherit; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #4f390e; outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; top: -100px; left: 1rem; z-index: 20; background: var(--ink); color: white; padding: .75rem 1rem; }
.skip-link:focus { top: 1rem; }
.site-header { min-height: 64px; padding: .55rem clamp(1rem,3vw,2.5rem); display: grid; grid-template-columns: minmax(220px,1fr) auto minmax(220px,1fr); align-items: center; border-bottom: 1px solid var(--ink); background: rgba(242,236,223,.96); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: .65rem; text-decoration: none; font-family: var(--serif); font-size: .95rem; line-height: 1.05; }
.brand img { width: 40px; height: 40px; object-fit: contain; }
.brand small { display: block; font: 500 .54rem/1.5 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
nav { display: flex; align-items: center; gap: 1.25rem; font: 500 .66rem var(--mono); letter-spacing: .04em; text-transform: uppercase; }
nav a, .link-button { background: none; border: 0; padding: .65rem 0; text-decoration: none; color: var(--muted); cursor: pointer; position: relative; }
nav a::after { content: ''; position: absolute; left: 0; right: 100%; bottom: .35rem; height: 1px; background: var(--gold); transition: right .2s ease; }
nav a:hover::after, nav a[aria-current='page']::after { right: 0; }
nav a[aria-current='page'], .link-button:hover { color: var(--ink); }
.identity { justify-self: end; font: .68rem var(--mono); color: var(--muted); margin: 0; text-align: right; }
.nav-toggle { display: none; }

main { width: min(1200px, 100%); margin: auto; padding: 1.5rem clamp(1rem,3vw,2.5rem) 3rem; }
.eyebrow { margin: 0 0 .6rem; font: 500 .66rem/1.4 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--gold); }
h1, h2 { font-family: var(--serif); font-weight: 400; margin: 0; }
h1 { font-size: clamp(3.4rem,8vw,7.8rem); line-height: .86; letter-spacing: -.045em; }
h2 { font-size: clamp(2rem,4vw,3.8rem); line-height: .95; letter-spacing: -.035em; }
.lede { color: var(--muted); font-size: 1.05rem; line-height: 1.55; max-width: 38rem; }
.page-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: clamp(3rem,7vw,6.5rem); }
.refresh-status, .heading-note { margin: 0; text-align: right; color: var(--muted); }
.refresh-status span { display: block; font: .62rem var(--mono); text-transform: uppercase; letter-spacing: .12em; }
.refresh-status strong { font: 400 .85rem/2 var(--mono); color: var(--ink); }
.heading-note { font: .8rem/1.5 var(--mono); }

.dashboard-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.dashboard-bar h1 { font-family: var(--sans); font-size: 1.55rem; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; }
.dashboard-bar p { margin: .2rem 0 0; color: var(--muted); font-size: .78rem; }
.dashboard-actions { display: flex; align-items: center; gap: .5rem; }
.dashboard-actions .refresh-status { margin-right: .35rem; font: .66rem var(--mono); white-space: nowrap; }
.dashboard-actions .refresh-status strong { display: inline; font: inherit; color: var(--ink); }

.metrics { display: grid; grid-template-columns: repeat(4,1fr); border: 1px solid var(--rule); background: rgba(250,247,239,.45); }
.metric { min-height: 82px; padding: .8rem 1rem; border-left: 1px solid var(--rule); display: flex; flex-direction: column; justify-content: space-between; }
.metric:first-child { border-left: 0; }
.metric span { font: 500 .62rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.metric strong { font: 600 1.65rem/1 var(--sans); }
.metric-total strong { color: var(--gold); }

.ledger { padding-top: 1.25rem; }
.ledger-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.ledger-title h2 { font-family: var(--sans); font-size: 1rem; font-weight: 600; letter-spacing: 0; }
.result-count { margin: 0; color: var(--muted); font: .68rem var(--mono); }
.result-count strong { color: var(--ink); }
.actions, .dialog-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.button { min-height: 34px; padding: .5rem .72rem; border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink); text-decoration: none; font: 500 .62rem var(--mono); letter-spacing: .03em; text-transform: uppercase; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .18s, color .18s; }
.button:hover { background: var(--gold-pale); }
.button-dark, .button-primary { background: var(--ink); color: var(--paper-light); }
.button-dark:hover, .button-primary:hover { background: var(--gold); color: white; }
.button-danger { border-color: var(--danger); color: var(--danger); }
.button-danger:hover { background: var(--danger); color: white; }
.button:disabled { opacity: .5; cursor: wait; }
.full { width: 100%; }

.filters { margin: .65rem 0 0; display: grid; grid-template-columns: 2fr 1fr 1fr; border: 1px solid var(--rule); background: rgba(250,247,239,.45); }
label { display: block; font: 500 .65rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.filters label { padding: .45rem .75rem .35rem; border-left: 1px solid var(--rule); }
.filters label:first-child { border-left: 0; }
input, select { width: 100%; min-height: 34px; border: 0; border-bottom: 1px solid var(--ink); border-radius: 0; color: var(--ink); background: transparent; padding: .3rem 0; outline: 0; font-size: .86rem; text-transform: none; }
input:focus, select:focus { border-bottom-width: 2px; border-bottom-color: var(--gold); }
.state { min-height: 72px; border-bottom: 1px solid var(--rule); display: grid; place-items: center; text-align: center; color: var(--muted); font: .72rem var(--mono); }
.state.error { color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: .6rem .65rem; text-align: left; border-bottom: 1px solid var(--ink); color: var(--muted); font: 500 .6rem var(--mono); letter-spacing: .08em; text-transform: uppercase; }
td { padding: .62rem .65rem; border-bottom: 1px solid var(--rule); font-size: .86rem; }
td:nth-child(2), td:nth-child(3) { font-family: var(--mono); font-size: .78rem; }
tbody tr { animation: reveal .3s ease both; }
tbody tr:hover { background: rgba(222,208,172,.3); }

.login-layout { min-height: calc(100vh - 10rem); display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: clamp(3rem,9vw,10rem); max-width: 1120px; margin: auto; }
.login-mark { border-right: 1px solid var(--ink); min-height: 520px; display: flex; padding-right: 5rem; flex-direction: column; align-items: center; justify-content: center; }
.login-mark img { width: min(320px,100%); height: auto; filter: sepia(.1); }
.login-mark p { width: 100%; display: flex; align-items: center; gap: 1rem; font: .66rem var(--mono); color: var(--gold); letter-spacing: .15em; }
.login-mark i { height: 1px; background: var(--gold); flex: 1; }
.login-panel { max-width: 430px; }
.login-panel h1 { font-size: clamp(4.5rem,8vw,7rem); }
.login-panel form, .ruled-form, .add-user form { margin-top: 2.5rem; }
.login-panel form > label, .password-field, .ruled-form > .password-field, .add-user form > label { margin-top: 1.2rem; }
.password-field { position: relative; }
.password-field input { padding-right: 4rem; }
.reveal { position: absolute; right: 0; bottom: 0; height: 44px; border: 0; background: none; font: .62rem var(--mono); text-transform: uppercase; cursor: pointer; color: var(--muted); }
.form-message { min-height: 1.5rem; margin: .8rem 0; color: var(--danger); font-size: .86rem; }
.hint { color: var(--muted); font-size: .84rem; line-height: 1.5; }

.narrow-page { max-width: 680px; margin: 5vh auto 0; }
.narrow-page h1 { font-size: clamp(3.8rem,8vw,6.8rem); }
.ruled-form { border-top: 1px solid var(--ink); padding-top: .5rem; }
.ruled-form .button { margin-top: 1rem; }
.user-grid { display: grid; grid-template-columns: minmax(260px,1fr) 3fr; gap: clamp(2rem,6vw,7rem); align-items: start; }
.add-user { position: sticky; top: 2rem; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 1.5rem 0 2rem; }
.add-user h2 { font-size: 3rem; }
.user-list { margin-top: 2rem; border-top: 1px solid var(--ink); }
.user-row { padding: 1.2rem .2rem; border-bottom: 1px solid var(--rule); display: grid; grid-template-columns: minmax(180px,1.7fr) repeat(4,minmax(80px,.7fr)) auto; gap: 1rem; align-items: center; }
.user-email { overflow-wrap: anywhere; }
.user-email strong { display: block; font-weight: 600; }
.user-email small, .user-meta { font: .68rem/1.5 var(--mono); color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: .4rem; font: 500 .63rem var(--mono); text-transform: uppercase; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.badge.disabled::before { background: var(--danger); }
.user-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: .4rem; }
.user-actions .button { padding: .55rem .65rem; }
.login-history { grid-column: 1 / -1; border-top: 1px dotted var(--rule); padding-top: .6rem; color: var(--muted); font: .68rem/1.5 var(--mono); }
.login-history summary { width: fit-content; color: var(--ink); cursor: pointer; }
.login-history ol { max-height: 180px; overflow: auto; margin: .6rem 0 0; padding-left: 1.8rem; columns: 2; column-gap: 2rem; }
.login-history li { padding: .15rem 0; break-inside: avoid; }

dialog { width: min(520px,calc(100% - 2rem)); border: 1px solid var(--ink); padding: 0; color: var(--ink); background: var(--paper-light); }
dialog::backdrop { background: rgba(23,23,19,.72); }
.dialog-inner { padding: clamp(1.5rem,5vw,3rem); }
.dialog-inner h2 { margin-bottom: 1rem; }
.dialog-inner code { display: block; margin: 1.5rem 0; padding: 1.2rem; border: 1px dashed var(--gold); background: var(--paper); font: 500 1.15rem var(--mono); overflow-wrap: anywhere; user-select: all; }
.toast { position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 30; max-width: 360px; padding: .9rem 1.1rem; background: var(--ink); color: white; font-size: .85rem; transform: translateY(150%); transition: transform .25s ease; }
.toast.visible { transform: none; }

@keyframes reveal { from { opacity: 0; transform: translateY(6px); } }
@media (max-width: 900px) {
  .site-header { grid-template-columns: 1fr auto; }
  .identity { grid-column: 1 / -1; justify-self: start; margin-left: 3.2rem; margin-top: -.65rem; }
  .nav-toggle { display: block; min-width: 44px; min-height: 44px; background: transparent; border: 1px solid var(--ink); font: .65rem var(--mono); text-transform: uppercase; }
  nav { display: none; grid-column: 1 / -1; padding-top: 1rem; border-top: 1px solid var(--rule); margin-top: 1rem; }
  nav.open { display: flex; flex-wrap: wrap; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(3) { border-left: 0; border-top: 1px solid var(--rule); }
  .metric:nth-child(4) { border-top: 1px solid var(--rule); }
  .user-grid { grid-template-columns: 1fr; }
  .add-user { position: static; }
  .user-row { grid-template-columns: 1fr 1fr; }
  .user-email { grid-column: 1 / -1; }
  .user-actions { grid-column: 1 / -1; justify-content: start; }
}

@media (max-width: 640px) {
  main { padding-top: 1rem; }
  .brand span { font-size: .92rem; }
  .dashboard-bar { align-items: flex-start; flex-direction: column; }
  .dashboard-actions { width: 100%; flex-wrap: wrap; }
  .dashboard-actions .refresh-status { width: 100%; }
  .page-heading { align-items: start; gap: 2rem; }
  .page-heading h1 { font-size: 4.2rem; }
  .refresh-status, .heading-note { padding-top: .2rem; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 66px; border-left: 0; border-top: 1px solid var(--rule); }
  .metric:first-child { border-top: 0; }
  .ledger-title { align-items: start; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .filters label, .filters label:first-child { border-left: 0; border-top: 1px solid var(--rule); }
  .filters label:first-child { border-top: 0; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }
  td { display: grid; grid-template-columns: 95px 1fr; gap: .5rem; border: 0; padding: .25rem .4rem; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); font: 500 .62rem var(--mono); color: var(--muted); text-transform: uppercase; }
  .login-layout { display: block; min-height: 0; }
  .login-mark { min-height: 0; border-right: 0; border-bottom: 1px solid var(--ink); padding: 0 0 2rem; margin-bottom: 2.5rem; }
  .login-mark img { width: 150px; }
  .login-panel h1 { font-size: 4.7rem; }
}

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