:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #5c6b7a;
  --line: #d5dde6;
  --paper: #f4f7fb;
  --card: #fff;
  --blue: #0b4f8a;
  --blue-dark: #083864;
  --gold: #c47b12;
  --danger: #9d1c2f;
  --ok: #0f6b45;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); }
a { color: var(--blue); }
button, input, textarea, select { font: inherit; color: inherit; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 8px; top: 8px; background: #fff; padding: 8px; z-index: 5; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.top-nav { display: flex; gap: 14px; flex-wrap: wrap; }
.top-nav a { text-decoration: none; font-weight: 600; }
.top-nav a[aria-current="page"] { color: var(--blue-dark); border-bottom: 2px solid var(--gold); }

.wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
h1 { font-size: 1.7rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
.lede, .muted { color: var(--muted); }
.req { color: var(--danger); }
.hidden, [hidden] { display: none !important; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.field span { font-weight: 600; }
input[type="text"], input[type="date"], input[type="email"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}
textarea { min-height: 80px; resize: vertical; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } }

.btn, button.btn {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-quiet { background: #fff; color: var(--blue); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.alert { background: #fff4f4; color: var(--danger); border: 1px solid #f0c2c8; padding: 10px 12px; border-radius: 8px; }
.ok { background: #eef8f3; color: var(--ok); border: 1px solid #b7e0cc; padding: 10px 12px; border-radius: 8px; }

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  border: 1px dashed var(--blue);
  border-radius: 10px;
  background: #f7fbff;
  cursor: pointer;
}
.file-drop input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.page-stage { position: relative; margin: 12px 0 24px; background: #fff; border: 1px solid var(--line); }
.page-stage canvas { display: block; width: 100%; height: auto; }
.box-layer { position: absolute; inset: 0; }
.sign-box {
  position: absolute;
  border: 2px solid var(--gold);
  background: rgba(196, 123, 18, 0.12);
  cursor: move;
  min-width: 48px;
  min-height: 28px;
}
.sign-box.is-selected { outline: 2px solid var(--blue); }
.sign-label { display: block; font-size: 12px; font-weight: 700; padding: 2px 4px; }
.sign-date { display: block; font-size: 11px; padding: 0 4px 2px; }
.sign-date-toggle, .sign-box button { font-size: 11px; }
.sign-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: var(--blue);
  border-radius: 2px;
  cursor: nwse-resize;
}
.hint { font-size: 0.92rem; }

.invoice-list { list-style: none; padding: 0; margin: 0; }
.invoice-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e7eef6;
  font-size: 0.85rem;
}
.status-pill.submitted { background: #fff4d6; }
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.detail-grid dt { color: var(--muted); }
.hash { font-family: ui-monospace, monospace; font-size: 0.82rem; word-break: break-all; }
#admin-root { margin-top: 8px; }

dialog.modal {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  max-width: 960px;
  width: calc(100% - 24px);
  max-height: calc(100% - 24px);
}
dialog.modal::backdrop { background: rgba(20, 28, 38, 0.45); }
.modal-card { padding: 20px; overflow: auto; max-height: calc(100vh - 48px); }
.sign-pad {
  width: 100%;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}
.sign-box.is-readonly { cursor: default; }
.choice { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-weight: 600; }
