/* ===================================================================
   A2Z embeddable widgets - the stylesheet every /embed/w/{slug} frame
   loads. One file, no web fonts, no images, no framework.

   Theme: <html data-theme="light|dark|auto">. "auto" follows the
   visitor's OS through prefers-color-scheme. The accent colour arrives
   as --e-accent set through the CSSOM by a2z-embed-core.js (the frame's
   CSP has no 'unsafe-inline' for styles, so it can never be a style
   attribute in the markup).

   Options map to attributes on <html>:
     data-compact="1"  tighter spacing, smaller type
     data-border="0"   no outer border / shadow
     data-title="0"    header hidden (set by the server, not here)
   and --e-radius (0-24px) through the CSSOM.
   =================================================================== */

:root {
    --e-accent: #2563eb;
    --e-accent-ink: #ffffff;
    --e-bg: #ffffff;
    --e-surface: #f6f8fb;
    --e-line: #d9dee8;
    --e-line-strong: #b8c0cf;
    --e-ink: #111827;
    --e-ink-2: #4b5563;
    --e-ink-3: #6b7280;
    --e-ok: #067647;
    --e-warn: #9a4a06;
    --e-bad: #b42318;
    --e-bad-soft: #fef3f2;
    --e-focus: #1d4ed8;
    --e-radius: 12px;
    --e-pad: 16px;
    --e-gap: 12px;
    --e-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --e-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}

html[data-theme="dark"] {
    --e-bg: #0f141c;
    --e-surface: #172030;
    --e-line: #2a3446;
    --e-line-strong: #3d4a60;
    --e-ink: #eef2f8;
    --e-ink-2: #b7c1d1;
    --e-ink-3: #93a0b5;
    --e-ok: #4ade80;
    --e-warn: #fbbf24;
    --e-bad: #fca5a5;
    --e-bad-soft: #3a1d1d;
    --e-focus: #93c5fd;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --e-bg: #0f141c;
        --e-surface: #172030;
        --e-line: #2a3446;
        --e-line-strong: #3d4a60;
        --e-ink: #eef2f8;
        --e-ink-2: #b7c1d1;
        --e-ink-3: #93a0b5;
        --e-ok: #4ade80;
        --e-warn: #fbbf24;
        --e-bad: #fca5a5;
        --e-bad-soft: #3a1d1d;
        --e-focus: #93c5fd;
        color-scheme: dark;
    }
}

html[data-compact="1"] { --e-pad: 11px; --e-gap: 8px; }

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over every display rule below (showIf fields, toggled panels). */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; background: transparent; }

body {
    font: 15px/1.45 var(--e-font);
    color: var(--e-ink);
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}
html[data-compact="1"] body { font-size: 14px; }

.e-card {
    background: var(--e-bg);
    border: 1px solid var(--e-line);
    border-radius: var(--e-radius);
    padding: var(--e-pad);
    max-width: 100%;
}
html[data-border="0"] .e-card { border-color: transparent; }

.e-head { display: flex; align-items: center; gap: 8px; margin: 0 0 var(--e-gap); }
.e-head h1 { font-size: 1.08em; line-height: 1.3; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.e-head .e-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--e-accent); flex: none; }

.e-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------------- form ---------------- */
.e-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--e-gap); }
.e-form.e-form-1 { grid-template-columns: 1fr; }
.e-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.e-field.e-wide { grid-column: 1 / -1; }
.e-field > label, .e-field > .e-label { font-size: .86em; font-weight: 600; color: var(--e-ink-2); }
.e-control { position: relative; display: flex; align-items: stretch; min-width: 0; }
.e-affix {
    display: flex; align-items: center; padding: 0 9px; font-size: .9em; color: var(--e-ink-3); white-space: nowrap;
    background: var(--e-surface); border: 1px solid var(--e-line-strong);
}
.e-affix.e-pre { border-right: 0; border-radius: 8px 0 0 8px; }
.e-affix.e-suf { border-left: 0; border-radius: 0 8px 8px 0; }

.e-input, .e-select, .e-textarea {
    width: 100%; min-width: 0; font: inherit; color: var(--e-ink);
    background: var(--e-bg); border: 1px solid var(--e-line-strong); border-radius: 8px;
    padding: 8px 10px; min-height: 40px;
}
html[data-compact="1"] .e-input, html[data-compact="1"] .e-select { min-height: 36px; padding: 6px 9px; }
.e-control .e-pre ~ .e-input { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.e-control.e-has-suf .e-input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.e-textarea { min-height: 120px; resize: vertical; font-family: var(--e-mono); font-size: .9em; line-height: 1.45; }
.e-textarea.e-prose { font-family: var(--e-font); font-size: 1em; }
.e-select { appearance: auto; }
.e-input[type="color"] { padding: 3px; height: 40px; }

.e-input:focus-visible, .e-select:focus-visible, .e-textarea:focus-visible,
.e-btn:focus-visible, .e-seg button:focus-visible, .e-foot a:focus-visible, .e-check input:focus-visible {
    outline: 2px solid var(--e-focus); outline-offset: 2px;
}
.e-input[aria-invalid="true"], .e-textarea[aria-invalid="true"] { border-color: var(--e-bad); }
.e-err { font-size: .82em; color: var(--e-bad); }
.e-help { font-size: .8em; color: var(--e-ink-3); }

.e-check { display: flex; align-items: center; gap: 8px; font-size: .92em; color: var(--e-ink-2); min-height: 40px; }
.e-check input { width: 18px; height: 18px; accent-color: var(--e-accent); }

.e-seg { display: inline-flex; border: 1px solid var(--e-line-strong); border-radius: 9px; overflow: hidden; }
.e-seg button {
    font: inherit; font-size: .85em; border: 0; background: var(--e-bg); color: var(--e-ink-2);
    padding: 6px 12px; cursor: pointer; min-height: 34px;
}
.e-seg button + button { border-left: 1px solid var(--e-line-strong); }
.e-seg button[aria-pressed="true"] { background: var(--e-accent); color: var(--e-accent-ink); }
.e-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 var(--e-gap); }

.e-btn {
    font: inherit; font-size: .9em; font-weight: 600; cursor: pointer;
    border: 1px solid var(--e-accent); background: var(--e-accent); color: var(--e-accent-ink);
    border-radius: 8px; padding: 8px 14px; min-height: 38px;
}
.e-btn.e-ghost { background: transparent; color: var(--e-ink); border-color: var(--e-line-strong); }
.e-btn[disabled] { opacity: .55; cursor: not-allowed; }
.e-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- result ---------------- */
.e-result { margin-top: var(--e-gap); border-top: 1px solid var(--e-line); padding-top: var(--e-gap); }
.e-result:empty { display: none; }
.e-rows { display: grid; gap: 6px; margin: 0; }
.e-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.e-row dt { color: var(--e-ink-2); font-size: .92em; }
.e-row dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.e-row.e-primary { padding: 10px 12px; background: var(--e-surface); border-radius: 10px; }
.e-row.e-primary dd { font-size: 1.35em; color: var(--e-ink); }
.e-row.e-primary dt { font-weight: 600; }
.e-hint { display: block; font-size: .78em; font-weight: 400; color: var(--e-ink-3); }

.e-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 10px 0 4px; background: var(--e-surface); }
.e-bar span { display: block; height: 100%; }
.e-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8em; color: var(--e-ink-2); }
.e-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

.e-note { margin: 10px 0 0; font-size: .82em; color: var(--e-ink-3); }
.e-warn { margin: 10px 0 0; font-size: .85em; color: var(--e-warn); }
.e-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--e-bad-soft); color: var(--e-bad); font-size: .9em; }
.e-empty { margin: 0; color: var(--e-ink-3); font-size: .9em; }

.e-table-wrap { margin-top: 10px; max-height: 260px; overflow: auto; border: 1px solid var(--e-line); border-radius: 8px; }
.e-table { width: 100%; border-collapse: collapse; font-size: .82em; font-variant-numeric: tabular-nums; }
.e-table caption { text-align: left; padding: 6px 8px; color: var(--e-ink-2); font-weight: 600; }
.e-table th, .e-table td { padding: 5px 8px; border-bottom: 1px solid var(--e-line); text-align: right; white-space: nowrap; }
.e-table th:first-child, .e-table td:first-child { text-align: left; }
.e-table thead th { position: sticky; top: 0; background: var(--e-surface); color: var(--e-ink-2); }

.e-out {
    width: 100%; margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--e-surface);
    border: 1px solid var(--e-line); font: .88em/1.5 var(--e-mono); white-space: pre-wrap; overflow-wrap: anywhere;
    max-height: 320px; overflow: auto;
}
.e-big { font-size: 2.1em; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.e-center { text-align: center; }
.e-muted { color: var(--e-ink-3); }

.e-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.e-actions .e-btn { font-size: .82em; padding: 6px 10px; min-height: 32px; }

.e-status { font-size: .82em; color: var(--e-ok); min-height: 1.2em; }

/* ---------------- footer ---------------- */
.e-foot {
    display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
    margin-top: var(--e-gap); padding-top: 8px; border-top: 1px solid var(--e-line);
    font-size: .76em; color: var(--e-ink-3);
}
.e-foot a { color: var(--e-ink-2); text-decoration: none; font-weight: 600; }
.e-foot a:hover { text-decoration: underline; }
.e-privacy::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--e-ok); margin-right: 6px; vertical-align: 1px; }
.e-privacy.e-server::before { background: var(--e-accent); }

.e-loading { color: var(--e-ink-3); font-size: .9em; padding: 12px 0; }

@media (max-width: 360px) {
    :root { --e-pad: 12px; }
    .e-form { grid-template-columns: 1fr; }
    .e-row.e-primary dd { font-size: 1.2em; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------- checker widgets (engines/checker-kit.js) ---------------- */
.ck-form { display: grid; gap: 6px; }
.ck-label { font-size: .86em; font-weight: 600; color: var(--e-ink-2); }
.ck-row { display: flex; gap: 8px; }
.ck-row .e-input { flex: 1; min-width: 0; }
.ck-out { display: grid; gap: 10px; margin-top: var(--e-gap); }
.ck-item { border: 1px solid var(--e-line); border-left-width: 4px; border-radius: 10px; padding: 10px 12px; background: var(--e-surface); }
.ck-ok { border-left-color: var(--e-ok); }
.ck-warn { border-left-color: var(--e-warn); }
.ck-bad { border-left-color: var(--e-bad); }
.ck-unknown { border-left-color: var(--e-line-strong); }
.ck-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.ck-mark { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: .8em; font-weight: 800; color: #fff; background: var(--e-ink-3); }
.ck-ok .ck-mark { background: var(--e-ok); }
.ck-warn .ck-mark { background: var(--e-warn); }
.ck-bad .ck-mark { background: var(--e-bad); }
html[data-theme="dark"] .ck-mark { color: #0f141c; }
.ck-tone { font-size: .86em; font-weight: 600; color: var(--e-ink-2); }
.ck-sum { margin: 6px 0 0; font-size: .9em; }
.ck-facts { margin: 8px 0 0; display: grid; gap: 3px; font-size: .84em; }
.ck-facts div { display: flex; justify-content: space-between; gap: 12px; }
.ck-facts dt { color: var(--e-ink-3); }
.ck-facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-weight: 600; }
.ck-link { display: inline-block; margin-top: 8px; font-size: .84em; color: var(--e-accent); font-weight: 600; }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] .ck-mark { color: #0f141c; } }
.e-field.e-toggle { justify-content: flex-end; }
