/* Certificates (layout shared with /badges/ and /address/). Wide screens: the form on the left, the bar (count + Download)
   and the live preview on the right, sticky. Below 900 px: Edit / Preview tabs and a fixed bottom bar. */
.ct-wrap { max-width: 1240px; margin: 0 auto; padding: 96px 16px 48px; color: var(--text-primary); box-sizing: border-box;
  --ct-accent: var(--color-primary, #6366f1); --ct-warn: var(--color-warning, #f59e0b); --ct-ok: #4ade80; --ct-bad: #f43f5e; --ct-info: #60a5fa; }
:root[data-theme="light"] .ct-wrap { --ct-accent: #4f46e5; --ct-warn: #b45309; --ct-ok: #15803d; --ct-bad: #e11d48; --ct-info: #1d4ed8; }
.ct-wrap *, .ct-wrap *::before, .ct-wrap *::after { box-sizing: border-box; }
.ct-wrap [hidden] { display: none !important; }
.ct-intro h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 8px; }
.ct-intro p { color: var(--text-secondary); margin: 0 0 16px; max-width: 70ch; }
.ct-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.ct-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.ct-form { display: grid; gap: 16px; min-width: 0; margin: 0; }
.ct-side { display: grid; gap: 12px; min-width: 0; align-content: start; }

.ct-card { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.ct-card h2 { font-size: 1.1rem; margin: 0; }
.ct-field { display: grid; gap: 4px; min-width: 0; }
.ct-label { font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); }
.ct-req { font-weight: 500; font-size: 0.78rem; color: var(--ct-accent); }
.ct-input { width: 100%; max-width: 100%; min-width: 0; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border-color);
  background: var(--bg-primary); color: var(--text-primary); font: inherit; font-size: 16px; min-height: 44px; }
textarea.ct-input { resize: vertical; line-height: 1.4; }
.ct-input:focus-visible { outline: 2px solid var(--ct-accent); outline-offset: 1px; }
.ct-input.is-bad { border-color: var(--ct-bad); box-shadow: 0 0 0 1px var(--ct-bad); }
.ct-row2 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .ct-row2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.ct-hint { color: var(--text-secondary); font-size: 0.88rem; margin: 0; overflow-wrap: anywhere; }
.ct-hint--info { color: var(--ct-info); }
.ct-msg { margin: 0; font-weight: 600; color: var(--ct-warn); overflow-wrap: anywhere; font-size: 0.92rem; }
.ct-msg--ok { color: var(--ct-ok); }
.ct-msg:empty { display: none; }
.ct-check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; min-height: 44px; }
.ct-check input { width: 20px; height: 20px; accent-color: var(--ct-accent); margin: 0; flex: 0 0 auto; }
.ct-check input:disabled + span { opacity: 0.5; }
.ct-remember { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; border-top: 1px solid var(--border-color); padding-top: 8px; }
.ct-link { background: none; border: 0; padding: 8px 4px; color: var(--ct-accent); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; min-height: 44px; }

.ct-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); border-radius: 10px; padding: 9px 16px; cursor: pointer; font: inherit; font-weight: 600; line-height: 1.2; min-height: 44px; }
.ct-btn:hover:not(:disabled) { border-color: var(--ct-accent); }
.ct-btn--primary { background: var(--ct-accent); border-color: var(--ct-accent); color: #fff; }
.ct-btn--primary:hover:not(:disabled) { background: var(--color-primary-active, #4f46e5); }
.ct-btn--quiet { background: transparent; color: var(--text-secondary); }
.ct-btn--small { min-height: 40px; padding: 6px 12px; font-size: 0.92rem; }
.ct-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ct-btn:focus-visible, .ct-icon:focus-visible, .ct-link:focus-visible { outline: 2px solid var(--ct-accent); outline-offset: 2px; }

/* bar: total + Download */
.ct-bar { display: grid; gap: 6px; padding: 12px 16px; border-radius: 12px; background: var(--bg-secondary); border: 1px solid var(--border-color);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); min-width: 0; }
.ct-bar-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ct-sum { display: grid; min-width: 0; flex: 1 1 auto; }
.ct-sum-label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.ct-sum-amt { font-size: 1.25rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-bar .ct-btn--primary { flex: 0 0 auto; }

/* preview */
.ct-preview { display: grid; gap: 8px; min-width: 0; }
.ct-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ct-preview-head h2 { font-size: 1rem; margin: 0; color: var(--text-secondary); }
.ct-pagesel { width: auto; min-height: 40px; }
.ct-sheet { position: relative; min-width: 0; display: grid; justify-items: center; }
#ctCanvas { display: block; max-width: 100%; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3); border-radius: 2px; }
#ctCanvas[width="300"][height="150"] { width: 100%; aspect-ratio: 1 / 1.414; height: auto; }

/* tabs (phone only) */
.ct-tabs { display: none; }

@media (min-width: 900px) {
  .ct-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .ct-side { position: sticky; top: 80px; }
}
@media (max-width: 899px) {
  .ct-wrap { padding-bottom: 160px; }
  .ct-tabs { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden;
    background: var(--bg-secondary); margin-bottom: 12px; position: sticky; top: 68px; z-index: 4; }
  .ct-tabs button { border: 0; background: transparent; color: var(--text-primary); font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer; min-height: 44px; }
  .ct-tabs button + button { border-left: 1px solid var(--border-color); }
  .ct-tabs button[aria-selected="true"] { background: var(--ct-accent); color: #fff; }
  .ct-wrap[data-view="edit"] .ct-preview { display: none; }
  .ct-wrap[data-view="preview"] .ct-form { display: none; }
  .ct-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; border-radius: 12px 12px 0 0; border-bottom: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); max-height: 50vh; overflow-y: auto; }
}

.img-foot { text-align: center; padding: 24px 16px; font-size: 0.875rem; }
.img-foot a { color: var(--text-secondary); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (max-width: 899px) { .img-foot { padding-bottom: 150px; } .ct-wrap { padding-bottom: 24px; } }
@media print { .nav, .img-foot, .ct-bar, .ct-tabs { display: none; } }

/* list, matcher, rows */
.ct-fields { display: grid; gap: 12px; min-width: 0; }
.ct-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.ct-card h3 { font-size: 1rem; margin: 0; }
.ct-card--note .ct-note { margin: 0; color: var(--text-secondary); }
.ct-many { display: grid; gap: 10px; padding: 12px; border-radius: 10px; border: 1px dashed var(--border-color); min-width: 0; }
.ct-matcher { display: grid; gap: 10px; min-width: 0; }
.ct-map { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
@media (min-width: 560px) { .ct-map { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.ct-map-item { display: grid; gap: 4px; min-width: 0; padding: 8px; border-radius: 8px; background: var(--bg-primary); border: 1px solid var(--border-color); }
.ct-map-sample { font-size: 0.85rem; color: var(--text-secondary); overflow-wrap: anywhere; min-height: 1.3em; }
.ct-list { display: grid; gap: 8px; min-width: 0; border-top: 1px solid var(--border-color); padding-top: 8px; }
.ct-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ct-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 360px; overflow-y: auto; min-width: 0; }
.ct-row { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 6px; align-items: stretch; min-width: 0; }
.ct-row-main { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); font: inherit; cursor: pointer; min-height: 44px; min-width: 0; }
.ct-row.is-selected .ct-row-main { border-color: var(--ct-accent); box-shadow: 0 0 0 1px var(--ct-accent); }
.ct-row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-row-status { font-size: 0.85rem; color: var(--ct-ok); overflow-wrap: anywhere; }
.ct-row.is-warn .ct-row-status { color: var(--ct-warn); }
.ct-row.is-error .ct-row-status { color: var(--ct-bad); font-weight: 600; }
.ct-row.is-pending .ct-row-status { color: var(--text-secondary); }
.ct-row .ct-icon { height: auto; min-height: 44px; }
.ct-blocked { display: grid; gap: 4px; min-width: 0; }
.ct-blocked-list { margin: 0; padding-left: 1.2em; color: var(--ct-bad); font-size: 0.9rem; max-height: 160px; overflow-y: auto; overflow-wrap: anywhere; }
.ct-icon { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-primary);
  font: 700 18px/1 system-ui, sans-serif; cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.ct-icon:hover { border-color: var(--ct-bad); color: var(--ct-bad); }
.ct-empty { margin: 0; padding: 48px 16px; text-align: center; color: var(--text-secondary); border: 1px dashed var(--border-color); border-radius: 8px; width: 100%; }
.ct-sum-amt { font-size: 1.1rem; }

.ct-card--note .ct-note, .ct-note { margin: 0; color: var(--text-secondary); }
.ct-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ct-seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; background: var(--bg-primary); }
.ct-seg button { border: 0; background: transparent; color: var(--text-primary); font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer; min-height: 44px; }
.ct-seg button + button { border-left: 1px solid var(--border-color); }
.ct-seg button[aria-selected="true"] { background: var(--ct-accent); color: #fff; }
.ct-seg button:focus-visible { outline: 2px solid var(--ct-accent); outline-offset: -3px; }
.ct-panel { display: grid; gap: 12px; min-width: 0; }
.ct-list-acts { display: flex; flex-wrap: wrap; gap: 0 8px; justify-content: flex-end; }
.ct-row { grid-template-columns: minmax(0, 1fr); }
.ct-row-main { cursor: default; }
.ct-row-sub { font-size: 0.85rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-roles { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 0; }
.ct-role { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 4px 10px; align-items: center; min-width: 0; }
.ct-role-name { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.ct-role-warn { grid-column: 2; margin: 0; font-size: 0.85rem; color: var(--ct-warn); font-weight: 600; }
.ct-colour { width: 52px; height: 44px; padding: 2px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-primary); cursor: pointer; }
.ct-field--colour { grid-template-columns: 52px minmax(0, 1fr); align-items: center; gap: 10px; }
.ct-field--colour .ct-colour { order: -1; }
.ct-logo { display: grid; gap: 8px; min-width: 0; padding-top: 4px; border-top: 1px solid var(--border-color); }
.ct-buildrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ct-buildrow .ct-msg:empty { display: none; }
.ct-canvases { position: relative; max-width: 100%; }
#ctOverlay { position: absolute; left: 0; top: 0; pointer-events: none; }
.ct-pagesel-wrap { display: block; }
.ct-pagesel { width: auto; min-height: 40px; padding: 4px 8px; }
.ct-updating { position: absolute; top: 8px; right: 8px; padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: rgba(15, 23, 42, 0.75); color: #fff; pointer-events: none; }
.ct-msg--bad { color: var(--ct-bad); }
.ct-row-more { font-size: 0.85rem; color: var(--text-secondary); padding: 4px 2px; }

/* certificates */
.ct-seg--style button { display: grid; gap: 2px; padding: 10px 6px; line-height: 1.25; }
.ct-seg--style button[aria-pressed="true"] { background: var(--ct-accent); color: #fff; }
.ct-seg-sub { font-size: 0.8rem; font-weight: 500; opacity: 0.85; }
.ct-wrap[data-style="vertical"] [data-only="western"], .ct-wrap[data-style="western"] [data-only="vertical"] { display: none !important; }
.ct-ph { display: grid; gap: 12px; min-width: 0; }
.ct-ph:empty { display: none; }
.ct-ph-key { font-family: ui-monospace, monospace; }
.ct-sig { display: grid; gap: 10px; min-width: 0; padding-top: 8px; border-top: 1px solid var(--border-color); }
.ct-img { display: grid; gap: 8px; min-width: 0; padding-top: 8px; border-top: 1px solid var(--border-color); }
.ct-swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ct-swatch { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--border-color); background: var(--sw); cursor: pointer; padding: 0; }
.ct-swatch[aria-pressed="true"] { outline: 3px solid var(--ct-accent); outline-offset: 2px; }
.ct-swatch:focus-visible { outline: 3px solid var(--ct-accent); outline-offset: 2px; }
.ct-map-item--ph .ct-label { color: var(--ct-info); }
.ct-map-item.is-unmapped { border-color: var(--ct-bad); }
#ctCanvas[width="300"][height="150"] { aspect-ratio: auto; }
