/* Aligned with the rest of the tools ------------------------------------
   The theme attribute is now the site-wide data-bs-theme, set before paint by
   includes/theme_boot.php, and the accent comes from this tool's entry in
   tools_meta.json via the --sg-* tokens includes/tool_header.php emits. The
   original colours stay as var() fallbacks, so the tool still stands up if it
   is ever opened outside the SenHOST shell.
   --------------------------------------------------------------------- */
/* ---------------------------------------------------------------- tokens */

:root {
    --bg: var(--page, #f6f7f9);
    --surface: var(--glass, #ffffff);
    --surface-2: var(--glassH, #f0f2f5);
    --surface-3: var(--well, #e6e9ee);
    --border: var(--stroke, #dce0e6);
    --border-strong: var(--strokeH, #c3c9d2);
    --text: var(--ink, #14181f);
    --text-dim: var(--ink2, #59616e);
    --text-faint: var(--ink3, #8a919c);
    --accent: var(--sg-accent-ink, #2f6df6);
    --accent-hover: color-mix(in oklch, var(--sg-accent-ink, #1f5ae0) 84%, black);
    --accent-soft: color-mix(in oklch, var(--sg-accent-ink, #e8f0ff) 12%, transparent);
    --ok: #17864a;
    --ok-soft: color-mix(in oklch, var(--ok) 14%, transparent);
    --warn: #a1620a;
    --warn-soft: color-mix(in oklch, var(--warn) 14%, transparent);
    --error: #c0332e;
    --error-soft: color-mix(in oklch, var(--error) 14%, transparent);
    --shadow: var(--sg-shadow-card, 0 1px 2px rgba(16, 22, 32, .06));
    --radius: var(--sg-r-md, 10px);
    --mono: var(--sg-font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
    --sans: var(--sg-font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
}

:root[data-bs-theme="dark"] {
    --accent: var(--sg-accent-ink, #5b8dff);
    --accent-hover: color-mix(in oklch, var(--sg-accent-ink, #7aa3ff) 84%, white);
    --accent-soft: color-mix(in oklch, var(--sg-accent-ink, #1b2740) 18%, transparent);
    --ok: #4ac97e;
    --ok-soft: color-mix(in oklch, var(--ok) 14%, transparent);
    --warn: #e0a34a;
    --warn-soft: color-mix(in oklch, var(--warn) 14%, transparent);
    --error: #f0736c;
    --error-soft: color-mix(in oklch, var(--error) 14%, transparent);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--page, var(--bg));
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- panels */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tabs {
    display: flex;
    gap: 2px;
    padding: 6px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius) var(--radius) 0 0;
}

.tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 14px;
    font-weight: 550;
    padding: 7px 14px;
    border-radius: 7px;
    cursor: pointer;
    transition: background .12s, color .12s;
}

.tab:hover { color: var(--text); background: var(--surface-3); }

.tab[aria-selected="true"] {
    background: var(--surface);
    color: var(--text);
}

.tab-panel { padding: 18px; }
.tab-panel[hidden] { display: none; }

/* ------------------------------------------------------------- drop zone */

.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.dropzone:hover,
.dropzone:focus-visible {
    border-color: var(--accent);
    background: var(--accent-soft);
    outline: none;
}

.dropzone.is-dragging {
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: scale(1.005);
}

.dropzone h2 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
}

.dropzone p {
    margin: 0;
    color: var(--text-dim);
    font-size: 14px;
}

.dropzone .icon {
    font-size: 26px;
    line-height: 1;
    display: block;
    margin-bottom: 10px;
}

/* ---------------------------------------------------------------- fields */

.field { display: flex; gap: 8px; }

input[type="url"],
input[type="text"],
textarea,
select {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 9px 12px;
    transition: border-color .12s, box-shadow .12s;
}

textarea {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    min-height: 190px;
    resize: vertical;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.hint {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--text-faint);
}

/* --------------------------------------------------------------- buttons */

.btn {
    appearance: none;
    font: inherit;
    font-size: 14px;
    font-weight: 550;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s, transform .06s;
}

.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--sg-accent-fill, var(--accent));
    border-color: var(--sg-accent-fill, var(--accent));
    color: var(--sg-on-accent, #fff);
    /* The shared style.css also defines .btn-primary, and its rule ends in
       "0 14px 30px -16px var(--a1)" - a coloured glow under the button. The
       other tools never meet it because they use .btn-brand. Flat, like them. */
    box-shadow: none;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

.btn-sm { padding: 5px 11px; font-size: 13px; }

/* --------------------------------------------------------------- options */

.options {
    margin-top: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.options > summary {
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 550;
    font-size: 14px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.options > summary::-webkit-details-marker { display: none; }

.options > summary::before {
    content: "▸";
    color: var(--text-faint);
    transition: transform .15s;
    display: inline-block;
}

.options[open] > summary::before { transform: rotate(90deg); }

.options > summary:hover { background: var(--surface-2); }

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 6px 22px;
    padding: 4px 18px 18px;
    border-top: 1px solid var(--border);
}

.opt {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 7px 0;
    cursor: pointer;
    font-size: 14px;
}

.opt input[type="checkbox"] {
    margin: 2px 0 0;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex: 0 0 auto;
}

.opt span { display: block; }
.opt small { display: block; color: var(--text-faint); font-size: 12.5px; line-height: 1.4; }

.opt-select {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 0;
    font-size: 14px;
}

.opt-select select { width: auto; padding: 5px 9px; font-size: 13px; }

/* --------------------------------------------------------------- formats */

.formats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    margin-top: 18px;
    font-size: 13px;
    color: var(--text-faint);
}

.formats b {
    color: var(--text-dim);
    font-weight: 600;
    margin-right: 5px;
}

.formats code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    margin-right: 3px;
    color: var(--text-dim);
}

/* --------------------------------------------------------------- results */

.results { margin-top: 26px; }
.results[hidden] { display: none; }

.results-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.results-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 620;
}

.results-head .spacer { flex: 1; }

.workspace {
    display: grid;
    grid-template-columns: minmax(190px, 250px) 1fr;
    gap: 16px;
    align-items: start;
}

@media (max-width: 820px) {
    .workspace { grid-template-columns: 1fr; }
}

.filelist {
    list-style: none;
    margin: 0;
    padding: 6px;
    max-height: 520px;
    overflow-y: auto;
}

.filelist li { margin: 0; }

.filelist button {
    display: block;
    width: 100%;
    text-align: left;
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    color: var(--text);
    padding: 8px 10px;
    border-radius: 7px;
    cursor: pointer;
    transition: background .1s;
}

.filelist button:hover { background: var(--surface-2); }

.filelist button[aria-current="true"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 550;
}

.filelist .fname {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.filelist .fmeta {
    display: block;
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 1px;
}

.filelist button[aria-current="true"] .fmeta { color: var(--accent); opacity: .8; }
.filelist .failed .fname::before { content: "⚠ "; color: var(--error); }

/* ----------------------------------------------------------------- output */

.output { min-width: 0; overflow: hidden; }

.output-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    flex-wrap: wrap;
}

.output-bar .spacer { flex: 1; }

.switch {
    display: inline-flex;
    background: var(--surface-3);
    border-radius: 7px;
    padding: 2px;
}

.switch button {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 550;
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: 5px;
    cursor: pointer;
}

.switch button[aria-selected="true"] {
    background: var(--surface);
    color: var(--text);
}

.stats {
    font-size: 12.5px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.stats .chip {
    display: inline-block;
    background: var(--surface-3);
    border-radius: 4px;
    padding: 1px 6px;
    margin-right: 6px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-dim);
}

.viewport {
    max-height: 620px;
    overflow: auto;
    padding: 20px 22px;
}

pre.raw {
    margin: 0;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
}

/* -------------------------------------------------------- rendered preview */

.preview { font-size: 15px; }
.preview > :first-child { margin-top: 0; }
.preview > :last-child { margin-bottom: 0; }

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
    margin: 1.5em 0 .5em;
    line-height: 1.3;
    font-weight: 630;
    letter-spacing: -.01em;
}

.preview h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: .28em; }
.preview h2 { font-size: 1.35em; border-bottom: 1px solid var(--border); padding-bottom: .24em; }
.preview h3 { font-size: 1.16em; }
.preview h4 { font-size: 1.02em; }
.preview h5, .preview h6 { font-size: .94em; color: var(--text-dim); }

.preview p { margin: 0 0 1em; }
.preview ul, .preview ol { margin: 0 0 1em; padding-left: 1.6em; }
.preview li { margin: .22em 0; }
.preview li > ul, .preview li > ol { margin: .22em 0; }

.preview a { color: var(--accent); text-decoration: none; }
.preview a:hover { text-decoration: underline; }

.preview blockquote {
    margin: 0 0 1em;
    padding: .1em 0 .1em 1em;
    border-left: 3px solid var(--border-strong);
    color: var(--text-dim);
}

.preview code {
    font-family: var(--mono);
    font-size: .86em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: .1em .35em;
}

.preview pre {
    margin: 0 0 1em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 13px 15px;
    overflow-x: auto;
}

.preview pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: 13px;
    line-height: 1.55;
}

.preview hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }

.table-scroll { overflow-x: auto; margin: 0 0 1em; }

.preview table {
    border-collapse: collapse;
    font-size: .92em;
    min-width: 100%;
}

.preview th, .preview td {
    border: 1px solid var(--border);
    padding: 6px 11px;
    text-align: left;
    vertical-align: top;
}

.preview th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.preview tbody tr:nth-child(even) td { background: var(--surface-2); }

.preview img { max-width: 100%; height: auto; border-radius: 6px; }

/* -------------------------------------------------------------- messaging */

.notice {
    display: flex;
    gap: 9px;
    align-items: flex-start;
    padding: 10px 13px;
    border-radius: 8px;
    font-size: 13.5px;
    margin: 0 0 10px;
    line-height: 1.5;
}

.notice:last-child { margin-bottom: 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--error-soft); color: var(--error); }
.notice .glyph { flex: 0 0 auto; }

.notices { padding: 12px 12px 2px; }
.notices:empty { display: none; }

.empty {
    padding: 54px 20px;
    text-align: center;
    color: var(--text-faint);
    font-size: 14px;
}

/* ---------------------------------------------------------------- overlay */

.busy {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    margin-top: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 14px;
    color: var(--text-dim);
}

.busy[hidden] { display: none; }

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: 0 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2s; }
    * { transition: none !important; }
}

/* ------------------------------------------------------------------ toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(14px);
    background: var(--text);
    color: var(--bg);
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 550;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s, transform .18s;
    z-index: 50;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------------------------------------------- footer */

.colophon {
    margin-top: 40px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-faint);
    line-height: 1.65;
}

.colophon code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
}

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