:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #d8dee6;
  --primary: #1f5fa8;
  --primary-text: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --warn-bg: #fff6e0;
  --warn-text: #7a4b00;
  --error-bg: #fdecea;
  --brand: #1e3250;
  --radius: 8px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --surface: #1a212a;
    --text: #e6ebf1;
    --muted: #9aa6b4;
    --border: #2c3643;
    --primary: #4d8fd9;
    --danger: #f97066;
    --ok: #47cd89;
    --warn-bg: #3a2c0c;
    --warn-text: #f5c86b;
    --error-bg: #3d1b18;
    --brand: #e6ebf1;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; min-width: 0; }
/* Tenant logos are single-colour artwork used as a mask, so they follow the theme. */
.brand-logo {
  display: block; height: 48px; width: 192px; flex: none;
  background-color: var(--brand);
  -webkit-mask: var(--logo) no-repeat left center / contain;
  mask: var(--logo) no-repeat left center / contain;
}
.brand-product { color: var(--muted); font-weight: 500; padding-left: 12px; border-left: 1px solid var(--border); white-space: nowrap; }
.brand-name:empty + .brand-product, .brand-logo[hidden] + .brand-name:empty + .brand-product { border-left: none; padding-left: 0; }
@media (max-width: 560px) { .brand-product { display: none; } }
.user { display: flex; gap: 12px; align-items: center; color: var(--muted); }

.container { max-width: 1040px; margin: 24px auto; padding: 0 16px; }
.container.narrow { max-width: 520px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }

label { display: block; font-weight: 600; margin: 14px 0 4px; }
input[type=text], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
textarea { resize: vertical; }
#recipients-help { margin: 0 0 6px; }
.recipient-summary { margin-top: 6px; font-size: 0.88rem; color: var(--muted); }
.recipient-summary .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.recipient-summary .chip {
  padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); overflow-wrap: anywhere;
}
.recipient-summary .chip.invalid { border-color: var(--danger); color: var(--danger); background: var(--error-bg); }
.recipient-summary .problem { color: var(--danger); }
#code { font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; font-family: ui-monospace, monospace; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 12px 0; }
label.radio { font-weight: 400; margin: 4px 0; }

button, .button {
  display: inline-block; padding: 9px 16px; margin-top: 16px; font: inherit; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
}
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button:disabled { opacity: 0.6; cursor: default; }
button.link { background: none; border: none; padding: 0; margin: 0; color: var(--primary); font-weight: 500; }
button.link.danger { color: var(--danger); }

.hint { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; }
.alert { padding: 10px 12px; border-radius: 6px; margin: 12px 0; }
.alert.error { background: var(--error-bg); color: var(--danger); }
.alert.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice { color: var(--muted); font-size: 0.85rem; text-align: center; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font-family: ui-monospace, monospace; font-size: 0.85rem; }
.copy-row button { margin-top: 0; white-space: nowrap; }

.progress { height: 6px; background: var(--border); border-radius: 3px; margin-top: 16px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width 0.2s; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.actions { white-space: nowrap; }
td.actions button + button { margin-left: 12px; }
.file { font-weight: 600; word-break: break-word; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; border: 1px solid currentColor; }
.badge.ready { color: var(--ok); }
.badge.pending_upload, .badge.scanning { color: var(--primary); }
.badge.rejected { color: var(--danger); }
.badge.revoked, .badge.expired { color: var(--muted); }

dialog {
  max-width: 720px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }

.narrow-card { max-width: 520px; margin-left: auto; margin-right: auto; }
.tenant-list { display: grid; gap: 10px; margin-top: 8px; }
.tenant-list button { margin-top: 0; text-align: left; padding: 14px 16px; }
.tenant-list button:hover { border-color: var(--primary); }
.tenant-list button.current { border-color: var(--primary); }
.tenant-list .hint { display: block; font-weight: 400; }

.label { display: block; font-weight: 600; margin: 14px 0 4px; }
.visually-hidden, input[type=file].visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dropzone {
  position: relative;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px 16px;
  text-align: center; background: var(--bg); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone p { margin: 0; }
.dropzone .hint { margin-top: 6px; }
.dropzone.dragging { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--bg)); }
.dropzone:focus-within { border-color: var(--primary); }
.link-label { display: inline; margin: 0; font-weight: 600; color: var(--primary); cursor: pointer; text-decoration: underline; }
.file-list { list-style: none; padding: 0; margin: 10px 0 0; border: 1px solid var(--border); border-radius: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); }
.file-list li:first-child { border-top: none; }
.file-list .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.file-list .size { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.file-list li.error .size { color: var(--danger); }
.file-list button { margin: 0; }
.file-row + .file-row { margin-top: 2px; }
.download-list { list-style: none; padding: 0; margin: 12px 0 0; }
.download-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.download-list li:first-child { border-top: none; }
.download-list .name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.download-list .meta { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.download-list button { margin: 0; white-space: nowrap; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

.signin-help { margin-top: 14px; }
a { color: var(--primary); }
.help h2 { scroll-margin-top: 16px; }
.toc { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 10px; }
.faq dt { font-weight: 600; margin-top: 14px; }
.faq dd { margin: 4px 0 0; }
.faq ul { padding-left: 18px; margin: 4px 0; }
.help-inline details { border-top: 1px solid var(--border); padding: 10px 0; }
.help-inline details:first-of-type { border-top: none; }
.help-inline summary { cursor: pointer; font-weight: 600; }
.help-inline details p { margin: 8px 0 0; }
.user .link { text-decoration: none; }

a.brand { color: inherit; text-decoration: none; }
.topbar { gap: 16px; flex-wrap: wrap; }
.menu { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 18px; margin-left: auto; }
.menu-link { color: var(--primary); font-weight: 500; text-decoration: none; }
.menu-link:hover { text-decoration: underline; }
.menu-link[aria-current="page"] { color: var(--text); font-weight: 600; }
.menu-user { color: var(--muted); display: inline-flex; flex-direction: column; line-height: 1.2; text-align: right; }
.menu-tenant { font-size: 0.8rem; }
.menu-tenant:empty { display: none; }
@media (max-width: 560px) { .menu { margin-left: 0; width: 100%; justify-content: flex-start; } .menu-user { text-align: left; } }
