/*
 * Copyright (c) 2026 AwaCloud SAS
 * Author: Matthieu Bouilloux
 * SPDX-License-Identifier: AGPL-3.0-only
 * Dual-licensed; see the NOTICE file for licensing and any additional terms.
 */

/* apps/services/md-to-html/src/styles/md-to-html.css — the component of
 * AWA Markdown to HTML. Paints only the awaforge tokens (tokens.css, linked
 * first) through the --awh-* aliases; every rule is scoped under `.awh`, so
 * the sheet can be linked into any page without touching the host's styles.
 * Same controls as AWA Office to Markdown's sheet. */

/* ── 1. Aliases ────────────────────────────────────────────────────────────── */
.awh {
    --awh-bg: var(--af-bg);
    --awh-fg: var(--af-fg);
    --awh-muted: var(--af-muted);
    --awh-accent: var(--af-accent);
    --awh-surface: var(--af-surface);
    --awh-rule: var(--af-rule);
    --awh-border: var(--af-muted);            /* control boundary, >= 3:1 (WCAG 1.4.11) */
    --awh-btn-bg: var(--af-hero-cta-bg);
    --awh-btn-fg: var(--af-hero-cta-fg);
    --awh-focus: var(--af-accent);
    --awh-radius: var(--fw-radius-md);
    --awh-target: 2.25rem;                    /* 36 px controls; 44 px under coarse pointers */
}
@media (pointer: coarse) {
    .awh { --awh-target: 2.75rem; }
}

/* ── 2. Frame ──────────────────────────────────────────────────────────────── */
.awh {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 16rem;
    color: var(--awh-fg);
    background: var(--awh-bg);
    font: 400 var(--af-step-0)/1.5 var(--af-sans);
    position: relative;
}
.awh *, .awh *::before, .awh *::after { box-sizing: border-box; }
.awh > * { flex: none; }
.awh [hidden] { display: none !important; }
.awh :focus-visible { outline: 2px solid var(--awh-focus); outline-offset: 2px; }

/* ── 3. Controls ───────────────────────────────────────────────────────────── */
.awh-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--fw-space-2) var(--fw-space-4);
    padding: var(--fw-space-1) var(--fw-space-3);
    background: var(--awh-surface);
    border-bottom: 1px solid var(--awh-rule);
}
.awh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fw-space-2);
    min-width: var(--awh-target);
    min-height: var(--awh-target);
    padding: 0 var(--fw-space-3);
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--awh-radius);
    cursor: pointer;
}
.awh-btn--text { border-color: var(--awh-border); }
.awh-btn:hover { border-color: var(--awh-border); }
.awh-btn--primary { font-weight: 600; color: var(--awh-btn-fg); background: var(--awh-btn-bg); }
.awh-btn--icon { padding: 0; }
.awh-btn:disabled { color: var(--awh-muted); cursor: default; }
.awh-bar [data-action="help"] { margin-left: auto; }
.awh-bar [data-action="paste"][aria-expanded="true"] { color: var(--awh-btn-fg); background: var(--awh-btn-bg); }

/* Paste or type: a form under the toolbar. */
.awh-paste {
    display: grid;
    gap: var(--fw-space-1);
    padding: var(--fw-space-3) var(--fw-space-4);
    background: var(--awh-surface);
    border-bottom: 1px solid var(--awh-rule);
}
.awh-paste textarea {
    width: 100%;
    min-height: 10rem;
    padding: var(--fw-space-2);
    font: var(--af-step--1)/1.5 var(--af-mono);
    color: var(--awh-fg);
    background: var(--awh-bg);
    border: 1px solid var(--awh-border);
    border-radius: var(--awh-radius);
    resize: vertical;
}
.awh-icon {
    flex: none;
    width: 1.25rem; height: 1.25rem;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}

/* ── 4. Layout: the side panel, then the view; each scrolls on its own ─────── */
.awh > .awh-body { flex: 1 1 auto; min-height: 0; }
.awh-body { display: grid; grid-template-columns: minmax(14rem, 20rem) minmax(0, 1fr); }
.awh-body > .awh-side[hidden] + .awh-view { grid-column: 1 / -1; }
.awh-side {
    min-height: 0;
    overflow-y: auto;
    padding: var(--fw-space-3);
    background: var(--awh-surface);
    border-right: 1px solid var(--awh-rule);
}
.awh-view { min-width: 0; min-height: 0; overflow-y: auto; padding: var(--fw-space-4); }
@media (max-width: 45rem) {
    .awh-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
    .awh-side { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--awh-rule); }
}
.awh-visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
    white-space: nowrap;
}
.awh-note { color: var(--awh-muted); font-size: var(--af-step--1); }

/* ── 5. Intake and the empty state ────────────────────────────────────────── */
.awh-drop {
    display: grid;
    gap: var(--fw-space-1);
    justify-items: center;
    padding: var(--fw-space-4);
    min-height: var(--awh-target);
    text-align: center;
    border: 2px dashed var(--awh-border);
    border-radius: var(--fw-radius-lg);
    cursor: pointer;
}
.awh-drop-text { font-weight: 600; }
.awh[data-dragover="true"] .awh-drop,
.awh-drop[data-dragover="true"] { border-color: var(--awh-accent); background: var(--awh-surface); }
.awh-empty {
    max-width: var(--af-measure);
    margin: var(--fw-space-4) auto 0;
    padding: 0 var(--fw-space-4);
    color: var(--awh-muted);
    text-align: center;
}

/* ── 6. The side panel: files and the page's options ──────────────────────── */
.awh-files { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--fw-space-1); }
.awh-files > li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    column-gap: var(--fw-space-2);
    padding: var(--fw-space-1) var(--fw-space-2);
    background: var(--awh-bg);
    border-radius: var(--awh-radius);
}
.awh-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.awh-files > li > .awh-note { grid-column: 1; }
.awh-file-moves { grid-column: 2; grid-row: 1 / span 2; display: flex; }
.awh-file-moves .awh-btn { min-width: 1.75rem; color: var(--awh-muted); }
.awh-file-moves .awh-btn:disabled { visibility: hidden; }
.awh-file-remove { grid-column: 3; grid-row: 1 / span 2; color: var(--awh-muted); }
.awh-file-remove:hover { color: var(--awh-fg); }
.awh-capability { margin: var(--fw-space-3) 0; }
.awh-form fieldset { margin: 0 0 var(--fw-space-3); padding: var(--fw-space-2) 0 0; border: 0; border-top: 1px solid var(--awh-rule); }
.awh-form legend { font-weight: 600; padding: 0 var(--fw-space-1) 0 0; }
.awh-field { display: grid; gap: var(--fw-space-1); margin: var(--fw-space-2) 0; }
.awh-field input, .awh-field select {
    min-height: var(--awh-target);
    padding: 0 var(--fw-space-2);
    font: inherit;
    color: var(--awh-fg);
    background: var(--awh-bg);
    border: 1px solid var(--awh-border);
    border-radius: var(--awh-radius);
}
.awh-check { display: flex; align-items: center; gap: var(--fw-space-2); min-height: var(--awh-target); }
.awh-check input { width: 1.25rem; height: 1.25rem; }

/* ── 7. The result: the actions first, the notes, then the preview ─────────── */
.awh-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--fw-space-2) var(--fw-space-3); }
.awh-state { margin: 0; color: var(--awh-muted); }
.awh-feedback { align-self: center; }
.awh-alert {
    margin: var(--fw-space-3) 0;
    padding: var(--fw-space-2) var(--fw-space-3);
    border-left: 3px solid var(--awh-accent);
    background: var(--awh-surface);
    border-radius: var(--awh-radius);
}
.awh-alert p { margin: 0 0 var(--fw-space-1); }
.awh-notes { margin: var(--fw-space-3) 0; }
.awh-notes summary { cursor: pointer; }
.awh-notes ul { margin: var(--fw-space-1) 0; padding-left: var(--fw-space-4); font-size: var(--af-step--1); overflow-wrap: anywhere; }
/* The preview box: the containing block of the page's fixed header and menu. */
.awh-preview {
    position: relative;
    transform: translateZ(0);
    height: min(75vh, 52rem);
    overflow: hidden;
    border: 1px solid var(--awh-rule);
    border-radius: var(--fw-radius-lg);
}
