:root {
	color-scheme: light;
	--bg: #f3f5f8; --fg: #1b1f23; --muted: #667085; --card: #fff; --line: #d6dbe3;
	--brand: #1f4e8c; --ok: #1a7f37; --warn: #b26a00; --bad: #c62828;
}
/* Dark theme: explicit choice, or the system preference while no choice was made (before the script runs). */
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #14171c; --fg: #e6e9ee; --muted: #9aa4b2; --card: #1e2229; --line: #333a45; --brand: #6aa3f0; --ok: #4cc38a; --warn: #f0b34a; --bad: #ff7b72;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme]) {
		color-scheme: dark;
		--bg: #14171c; --fg: #e6e9ee; --muted: #9aa4b2; --card: #1e2229; --line: #333a45; --brand: #6aa3f0; --ok: #4cc38a; --warn: #f0b34a; --bad: #ff7b72;
	}
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
	font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.bar { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px 12px;
	padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { margin: 0; font-size: 18px; letter-spacing: .02em; justify-self: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.brand-short { display: none; }
/* Little room: just "ISDOC", so the title never wraps or gets cut. */
@media (max-width: 540px) {
	.brand-full { display: none; }
	.brand-short { display: inline; }
}
.center { display: flex; gap: 8px; justify-self: center; }
.tools { display: flex; gap: 2px; align-items: center; justify-self: end; }
.btn { font: inherit; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--card);
	color: var(--fg); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.btn { white-space: nowrap; }
.btn .ico { flex: none; }
.lbl-short { display: none; }
/* Narrow widths: "Open" instead of "Open file" so the button never wraps to two lines. */
@media (max-width: 900px) {
	.lbl-long { display: none; }
	.lbl-short { display: inline; }
}
/* Little room: icons only (the buttons keep their title and aria-label). */
@media (max-width: 640px) {
	.btn .lbl { display: none; }
	.btn { padding: 7px 12px; }
}
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 0; border-radius: 8px;
	background: none; color: var(--muted); cursor: pointer; text-decoration: none; padding: 0; }
.icon-btn:hover, .icon-btn:focus-visible { background: color-mix(in srgb, var(--fg) 8%, transparent); color: var(--fg); }
.icon-btn.heart:hover { color: #e0245e; }
.icon-btn.star:hover { color: #d99a00; }
#theme .sun { display: none; }
:root[data-theme="dark"] #theme .sun { display: block; }
:root[data-theme="dark"] #theme .moon { display: none; }
/* Language menu: opens after a click on the globe icon. */
.langmenu { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; min-width: 170px; padding: 4px; background: var(--card);
	border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .22); }
.menu button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px;
	background: none; color: var(--fg); font: inherit; text-align: left; cursor: pointer; white-space: nowrap; }
.menu button:hover, .menu button:focus-visible { background: color-mix(in srgb, var(--fg) 9%, transparent); outline: none; }
.menu button[aria-checked="true"] { font-weight: 600; color: var(--brand); }
.menu .code { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 320px) {
	.bar { padding-left: 6px; padding-right: 6px; gap: 4px; }
	.brand { font-size: 14px; }
	.center { gap: 4px; }
	.btn { padding: 6px 8px; }
	.icon-btn { width: 26px; height: 30px; }
}
/* Not enough room for one row: first the heart, then the star disappear ("ISDOC", the buttons, theme and language stay). */
@media (max-width: 290px) { #sponsor { display: none; } }
@media (max-width: 260px) { #star { display: none; } }
@media (max-width: 480px) {
	.bar { padding-left: 10px; padding-right: 10px; gap: 8px; }
	.brand { font-size: 15px; letter-spacing: 0; }
	.tools { gap: 0; }
	.icon-btn { width: 30px; height: 32px; }
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
main { max-width: 900px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 28px 16px; text-align: center; background: var(--card); }
.drop.over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--card)); }
.drop p { margin: .25em 0; }
.muted { color: var(--muted); }
.error { background: color-mix(in srgb, var(--bad) 12%, var(--card)); border: 1px solid var(--bad); border-radius: 8px; padding: 10px 14px; }
.sig, .opts, .att { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.sig p { margin: 4px 0; }
.sig-head { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.sig.ok .dot { background: var(--ok); } .sig.warn .dot { background: var(--warn); } .sig.bad .dot { background: var(--bad); }
.sig-body, #sig-body, #val-body { font-size: 13px; }
#val-body ul { margin: 4px 0 0 18px; padding: 0; }
#val-body li { margin: 2px 0; word-break: break-word; }
#sig-body dl, #val-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0; }
#sig-body dd.fp, .cert-text .fp { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
#sig-body dt, #val-body dt { color: var(--muted); } #sig-body dd, #val-body dd { margin: 0; word-break: break-word; }
.opts { display: flex; gap: 8px 20px; align-items: center; flex-wrap: wrap; }
.opts label { cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.opts select { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); }
.opts select:disabled { opacity: .45; cursor: default; }
.qr-opts { display: inline-flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.att-file { font: inherit; background: none; border: 0; padding: 0 12px 0 0; color: var(--brand); cursor: pointer; text-decoration: underline; }
#view { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #e9ecef; min-height: 400px; }
@media print { .bar, .drop, .sig, .opts, .att, .error { display: none !important; } main { padding: 0; } #view { border: 0; } }

/* Toast: offline-ready / update notice */
.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 12px;
	max-width: calc(100vw - 24px); padding: 10px 14px; background: var(--fg); color: var(--bg); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); font-size: 14px; }
.toast .btn { padding: 4px 12px; background: var(--bg); color: var(--fg); border-color: transparent; }
@media print { .toast { display: none !important; } }

/* Sign dialog: choose an existing certificate or add a new one. */
.dlg { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px;
	background: var(--card); color: var(--fg); box-shadow: 0 16px 48px rgba(0, 0, 0, .35); overflow: auto; }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.dlg form { display: grid; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg p { margin: 0; }
.small { font-size: 12.5px; }
.cmd { display: grid; gap: 4px; }
.cmd pre { margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; user-select: all; }
.cmd code { font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.cert-list { display: grid; gap: 6px; }
.cert-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.cert-item:hover { background: color-mix(in srgb, var(--fg) 5%, transparent); }
.cert-item.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--card)); }
.cert-item input { flex: none; margin: 0; }
.cert-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cert-text .muted { font-size: 13px; }
.btn.mini, .cert-item .btn { padding: 3px 10px; font-size: 13px; }
.cert-text .btn.mini { margin-top: 4px; }
#sig-body dd .btn.mini { margin-left: 6px; }
.form-error { color: var(--bad); }
.dlg .error { padding: 8px 12px; }
.dlg .error.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--card)); }
@media print { .dlg { display: none !important; } }
