/* Extra widgets for tool pages on the shared layout (assets/layout/layout.css tokens), Bootstrap-free.
   Added with the step 3 batch A tools (blacklist, SPF, redirects, header analyzer, HTML inspector, webhook tester):
   textareas, selects, data tables, stat tiles, key/value lists, code blocks, tags, notes, segmented toggles and the
   empty results state. Load it through layout_start(['styles' => ['assets/layout/tool-widgets.css']]).
   Every colour is a token, so light and dark both work. */

/* ---------- form controls ---------- */
/* sizing and fonts only: border, colours, chevron and the hover / focus / invalid / disabled states come from
   assets/layout/controls.css (the .lay-field look) */
.tw-textarea, .tw-select, .tw-input { width: 100%; min-width: 0; font-family: var(--f-mono); font-size: 12.5px; }
.tw-textarea { display: block; min-height: 200px; padding: 10px 12px; line-height: 1.55; resize: vertical; }
.tw-select, .tw-input { height: 36px; padding: 0 10px; }
.tw-select { font-family: var(--f-sans); font-size: 13px; font-weight: 500; padding-right: 30px; }
.tw-select[multiple], .tw-select[size] { height: auto; padding: 4px; }
.tw-textarea::placeholder, .tw-input::placeholder { font-family: var(--f-sans); font-size: 13px; }

/* segmented toggle built from radio inputs: <div class="tw-seg"><label><input type="radio"><span>JSON</span></label>...</div> */
.tw-seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line2); border-radius: 7px; background: var(--sub); }
.tw-seg label { margin: 0; cursor: pointer; position: relative; }
.tw-seg input { position: absolute; opacity: 0; pointer-events: none; }
.tw-seg span { display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 5px; color: var(--dim); font-size: 12px; font-weight: 500; }
.tw-seg input:checked + span { background: var(--bg); color: var(--ink); box-shadow: 0 0 0 1px var(--line2); }
.tw-seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.tw-seg button { height: 26px; padding: 0 12px; border: 0; border-radius: 5px; background: none; color: var(--dim); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.tw-seg button.is-active, .tw-seg button[aria-selected="true"] { background: var(--bg); color: var(--ink); box-shadow: 0 0 0 1px var(--line2); }

/* file drop zone */
.tw-drop {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; padding: 14px;
    border: 1px dashed var(--line2); border-radius: 8px; background: var(--sub); color: var(--dim); font-size: 12.5px; text-align: center;
}
.tw-drop.dragover { border-color: var(--accent); background: var(--accent-bg); color: var(--ink); }
.tw-drop label { margin: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.tw-drop strong { color: var(--ink); font-weight: 500; }

/* ---------- results ---------- */
.tool-results-empty {
    display: flex; align-items: center; gap: 12px; padding: 16px 18px; border: 1px dashed var(--line2); border-radius: var(--radius);
    background: var(--sub); color: var(--dim);
}
.tool-results-empty::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.tool-results-empty > div { display: grid; gap: 2px; }
.tool-results-empty strong { color: var(--ink); font-weight: 500; }
.tool-results-empty span { font-size: 12.5px; }

.tw-stack { display: grid; gap: 16px; min-width: 0; }
.tw-section { display: grid; gap: 12px; min-width: 0; }
.tw-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tw-section-head h2, .tw-section-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
.tw-section-head p { margin: 2px 0 0; color: var(--dim); font-size: 12.5px; max-width: 70ch; }
.tw-count { font-family: var(--f-mono); font-size: 12px; color: var(--faint); white-space: nowrap; }
.tw-body { padding: 10px 14px 14px; display: grid; gap: 10px; min-width: 0; }
.tw-body > p { margin: 0; color: var(--dim); }
.tw-body strong { color: var(--ink); font-weight: 500; }

/* stat tiles */
.tw-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tw-stat { display: grid; gap: 2px; padding: 12px 14px; border-left: 1px solid var(--line); min-width: 0; background: var(--bg); }
.tw-stat:first-child { border-left: 0; }
.tw-stat b { font-size: 20px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.tw-stat span { font-size: 12px; color: var(--dim); line-height: 1.4; }

/* key / value list */
.tw-kv { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); margin: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; font-size: 12.5px; }
.tw-kv dt, .tw-kv dd { margin: 0; padding: 7px 10px; border-top: 1px solid var(--line); }
.tw-kv dt:first-of-type, .tw-kv dt:first-of-type + dd { border-top: 0; }
.tw-kv dt { color: var(--faint); font-weight: 400; }
.tw-kv dd { color: var(--ink); font-family: var(--f-mono); font-size: 12px; overflow-wrap: anywhere; }

/* data table */
.tw-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; max-width: 100%; }
.tw-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tw-table th, .tw-table td { padding: 7px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.tw-table thead th { border-top: 0; background: var(--sub); color: var(--faint); font-weight: 500; font-size: 11.5px; white-space: nowrap; }
.tw-table td { color: var(--ink); overflow-wrap: anywhere; }
.tw-table td.tw-num { font-family: var(--f-mono); color: var(--faint); width: 1%; white-space: nowrap; }
.tw-table small { color: var(--dim); font-size: 11.5px; }
.tw-table code, .tw-code { font-family: var(--f-mono); font-size: 12px; color: var(--ink); background: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; }

/* code block */
.tw-pre {
    margin: 0; padding: 12px 14px; max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 6px;
    background: var(--sub); color: var(--ink); font-family: var(--f-mono); font-size: 12px; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word;
}
.tw-pre-scroll { max-height: 280px; }

/* tag / chip (neutral) */
.tw-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tw-tag {
    display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border: 1px solid var(--line2); border-radius: 999px;
    background: var(--bg); color: var(--dim); font-family: var(--f-mono); font-size: 11.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* note rows: a dot plus a sentence (error / warn / info / ok) */
.tw-notes { display: grid; gap: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tw-note { display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); color: var(--ink); font-size: 12.5px; overflow-wrap: anywhere; }
.tw-note:first-child { border-top: 0; }
.tw-note::before { content: ""; flex: none; width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: var(--accent); }
.tw-note-error::before, .tw-note-fail::before { background: var(--bad); }
.tw-note-warn::before { background: var(--warn); }
.tw-note-ok::before, .tw-note-pass::before { background: var(--ok); }
.tw-note code { font-family: var(--f-mono); font-size: 12px; }

/* status word with a dot, coloured by class (same look as .badge-*) */
.tw-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; color: var(--dim); }
.tw-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.tw-status.is-pass { color: var(--ok); }
.tw-status.is-warn { color: var(--warn); }
.tw-status.is-fail { color: var(--bad); }
.tw-status.is-info { color: var(--accent); }
.tw-status.is-none { color: var(--faint); }

/* small card grid (provider cards, auth cards) */
.tw-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.tw-card { display: grid; gap: 10px; align-content: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; }
a.tw-card { color: inherit; text-decoration: none; }
a.tw-card:hover { border-color: var(--line2); background: var(--hover); text-decoration: none; }
.tw-card.is-fail { box-shadow: inset 3px 0 0 var(--bad); }
.tw-card.is-warn { box-shadow: inset 3px 0 0 var(--warn); }
.tw-card.is-pass { box-shadow: inset 3px 0 0 var(--ok); }
.tw-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
.tw-card-head h3, .tw-card-head h4 { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.tw-card p, .tw-card li { margin: 0; color: var(--dim); font-size: 12.5px; overflow-wrap: anywhere; }
.tw-card > * { min-width: 0; }
.tw-card ul { margin: 0; padding-left: 16px; display: grid; gap: 2px; }
.tw-label { font-size: 11.5px; color: var(--faint); }
.tw-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tw-meta > div { display: grid; gap: 2px; min-width: 0; }
.tw-meta .tw-full { grid-column: 1 / -1; }
.tw-meta b { font-weight: 500; color: var(--ink); font-size: 12.5px; overflow-wrap: anywhere; }

@media (max-width: 860px) {
    .tw-kv { grid-template-columns: minmax(0, 1fr); }
    .tw-kv dd { border-top: 0; padding-top: 0; }
    .tw-stat { border-left: 0; border-top: 1px solid var(--line); }
    .tw-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tw-stat:nth-child(-n+2) { border-top: 0; }
    .tw-stat:nth-child(even) { border-left: 1px solid var(--line); }
    .tw-meta { grid-template-columns: minmax(0, 1fr); }
}
