*, *::before, *::after { box-sizing: border-box; }
:root {
  --brand: #0b5394;
  --bg: #f4f6f8;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --ok: #1a7f37;
  --warn: #9a6700;
  --err: #cf222e;
}
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--brand); }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.15rem; margin-top: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--brand); color: #fff; padding: .75rem 1rem;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar .who { display: flex; gap: 1rem; align-items: center; }
.topbar form { margin: 0; }
button.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; padding: 0; font: inherit; min-height: 0; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 420px; margin: 3rem auto; }

label { display: block; font-weight: 600; margin: 1rem 0 .3rem; }
input, select, textarea {
  width: 100%; font: inherit; padding: .6rem .7rem;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
button, .button {
  display: inline-block; font: inherit; padding: .6rem 1rem; min-height: 44px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
  cursor: pointer; text-decoration: none; text-align: center;
}
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; width: 100%; margin-top: 1.25rem; font-weight: 600; }
button.secondary { margin-top: .5rem; }
button:disabled { opacity: .6; cursor: wait; }
.pdf-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 0; }
.pdf-actions .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.email-form { margin-top: 1rem; }
.email-form .muted { margin: 0 0 .25rem; overflow-wrap: anywhere; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.filters input { flex: 2 1 220px; width: auto; }
.filters select { flex: 1 1 160px; width: auto; }
.filters .date-nav { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; flex: 1 1 100%; }
.filters .date-nav input[type="date"] { flex: 0 1 11rem; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #f6f8fa; font-size: .85rem; text-transform: capitalize; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.done { background: #dafbe1; color: var(--ok); }
.badge.pending { background: #fff8c5; color: var(--warn); }

.alert { padding: .75rem 1rem; border-radius: 6px; margin: 0 0 1rem; }
.alert ul { margin: 0; padding-left: 1.2rem; }
.alert.error { background: #ffebe9; color: var(--err); border: 1px solid #ffcecb; }
.alert.success { background: #dafbe1; color: var(--ok); border: 1px solid #aceebb; }
.alert.info { background: #ddf4ff; color: #0969da; border: 1px solid #b6e3ff; }
.alert.warn { background: #fff8c5; color: var(--warn); border: 1px solid #f5e0a0; }
.logout-warning { max-width: 1200px; margin: 1rem auto 0; font-weight: 600; }
.hidden { display: none; }
.muted { color: var(--muted); }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.details dt { font-weight: 600; color: var(--muted); text-transform: capitalize; }
.details dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.details.two-col { grid-template-columns: max-content 1fr max-content 1fr; column-gap: 1.25rem; }
.collapsible > summary { display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none; user-select: none; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.collapsible[open] > summary::before { transform: rotate(90deg); }
.collapsible > summary h2 { margin: 0; }
.collapsible[open] > summary { margin-bottom: 1rem; }
.collapsible > summary:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; border-radius: 4px; }

.signature-box { position: relative; border: 2px dashed var(--border); border-radius: 8px; background: #fff; }
#signature-pad { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.signature-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #b0b7bf; pointer-events: none; font-size: 1.25rem; }
.signature-img { display: block; max-width: 100%; margin-top: 1rem; border: 1px solid var(--border); border-radius: 6px; }

.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin: 1rem 0; }

.refresh-status { font-size: .85rem; }
.subtext { font-size: .85rem; color: #57606a; }
tr.is-new td { background: #fff8c5; }
.group-row th { background: #eaeef2; font-size: .95rem; text-transform: none; white-space: normal; border-top: 2px solid var(--border); }
.group-row .group-name { font-weight: 700; margin-right: .5rem; }
.group-row .subtext { font-weight: 400; margin-right: .5rem; }
.group-row .group-count { float: right; font-weight: 400; font-size: .85rem; color: var(--muted); }
.group-row .group-detail { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); margin-top: .15rem; }
.modal { border: 0; border-radius: 10px; padding: 1.25rem; width: min(900px, 95vw); max-height: 85vh; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

@media (max-width: 700px) {
  .details, .details.two-col { grid-template-columns: 1fr; }
  .details dd { margin-bottom: .5rem; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
  td { border: 0; padding: .2rem .75rem; }
  td[data-label]::before { content: attr(data-label) ": "; font-weight: 600; color: var(--muted); text-transform: capitalize; }
  tr.group-row { padding: 0; border-bottom: 1px solid var(--border); }
  .group-row th { display: block; padding: .6rem .75rem; }
}
