/* elpan-httpd-autoindex: the look of mod_autoindex's listings.

   It styles the markup mod_autoindex emits once IndexStyleSheet is set
   (h1#indextitle, table#indexlist, td.indexcol*), and must look right on its
   own: the script is an extra. Everything the script adds is prefixed ai-.
   The page has no wrapper element, so <body> is the column.

   Colours are tokens; dark mode comes from the system unless the user picked
   one, which the script records as <html data-theme="light|dark">. The
   palette follows elpan-excuses. */

:root {
    color-scheme: light dark;
    --bg:       #f5f6f8;
    --panel:    #ffffff;
    --fg:       #1d242c;
    --muted:    #5e6b78;
    --accent:   oklch(55% 0.14 240);
    --weak:     oklch(60% 0.13 240 / 0.14);
    --hover:    oklch(60% 0.13 240 / 0.06);
    --border:   rgba(20, 30, 40, 0.10);
    --field:    #ffffff;
    --shadow:   0 1px 2px rgba(20, 30, 45, 0.06), 0 8px 24px rgba(20, 30, 45, 0.06);
}
:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:       #0f141a;
        --panel:    #171e27;
        --fg:       #e7ecf2;
        --muted:    #94a1b0;
        --accent:   oklch(78% 0.13 240);
        --weak:     oklch(78% 0.13 240 / 0.16);
        --hover:    oklch(78% 0.13 240 / 0.06);
        --border:   rgba(255, 255, 255, 0.09);
        --field:    #10161d;
        --shadow:   0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.3);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg:       #0f141a;
    --panel:    #171e27;
    --fg:       #e7ecf2;
    --muted:    #94a1b0;
    --accent:   oklch(78% 0.13 240);
    --weak:     oklch(78% 0.13 240 / 0.16);
    --hover:    oklch(78% 0.13 240 / 0.06);
    --border:   rgba(255, 255, 255, 0.09);
    --field:    #10161d;
    --shadow:   0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; }

body {
    max-width: 72rem;
    margin: 0 auto;
    padding: 28px 16px 48px;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, "Noto Sans", "Helvetica Neue", Arial, "Noto Sans Arabic",
          "Noto Sans CJK SC", "Noto Sans JP", sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ------------------------------------------------------------- title */

h1#indextitle {
    margin: 0 0 18px;
    font-size: 1.35rem;
    font-weight: 650;
    line-height: 1.3;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.ai-crumbs a { color: inherit; text-decoration: none; border-radius: 4px; }
.ai-crumbs a:hover { color: var(--accent); text-decoration: underline; }
.ai-crumbs .ai-sep { color: var(--muted); font-weight: 400; margin: 0 0.3em; }
.ai-crumbs .ai-host { color: var(--muted); font-weight: 500; }

/* ----------------------------------------------------------- toolbar */

.ai-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    margin: 0 0 14px;
}

.ai-search {
    position: relative;
    flex: 1 1 18rem;
    max-width: 30rem;
    display: flex;
    align-items: center;
}
.ai-search svg {
    position: absolute;
    inset-inline-start: 11px;
    width: 16px;
    height: 16px;
    color: var(--muted);
    pointer-events: none;
}
.ai-search input {
    width: 100%;
    height: 38px;
    padding: 0 40px 0 36px;
    padding-inline: 36px 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--field);
    color: var(--fg);
    font: inherit;
    box-shadow: var(--shadow);
    -webkit-appearance: none;
    appearance: none;
}
.ai-search input::placeholder { color: var(--muted); opacity: 1; }
.ai-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--weak);
}
.ai-search input::-webkit-search-cancel-button { display: none; }
.ai-search kbd, .ai-search .ai-clear {
    position: absolute;
    inset-inline-end: 8px;
}
.ai-search kbd {
    min-width: 22px;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    font: 12px/18px ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    text-align: center;
    pointer-events: none;
}
.ai-search input:focus ~ kbd { display: none; }
.ai-clear {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.ai-clear:hover { background: var(--hover); color: var(--fg); }
.ai-clear svg { position: static; width: 14px; height: 14px; color: inherit; }

.ai-count {
    color: var(--muted);
    font-size: 0.87rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ai-theme {
    margin-inline-start: auto;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--field);
    color: var(--muted);
    box-shadow: var(--shadow);
    cursor: pointer;
}
.ai-theme:hover { color: var(--fg); }
.ai-theme svg { width: 18px; height: 18px; }

/* ------------------------------------------------------------- table */

table#indexlist {
    width: 100%;
    border: 1px solid var(--border);
    border-spacing: 0;
    border-collapse: separate;
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
    font-variant-numeric: tabular-nums;
}

#indexlist tr.indexbreakrow { display: none; }

#indexlist th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: start;
    white-space: nowrap;
}
#indexlist th:first-child { border-start-start-radius: 12px; }
#indexlist th:last-child { border-start-end-radius: 12px; }
#indexlist th a { color: inherit; text-decoration: none; }
#indexlist th a:hover { color: var(--fg); }
#indexlist th[aria-sort] { color: var(--fg); }
#indexlist th[aria-sort] a::after {
    content: "";
    display: inline-block;
    width: 0.5em;
    height: 0.5em;
    margin-inline-start: 0.45em;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    transform: translateY(-0.2em) rotate(45deg);
}
#indexlist th[aria-sort="ascending"] a::after { transform: translateY(0.1em) rotate(-135deg); }

#indexlist td {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}
#indexlist tr:nth-child(3) td,
#indexlist tr.ai-first td { border-top: 0; }
#indexlist tr.ai-last td:first-child { border-end-start-radius: 12px; }
#indexlist tr.ai-last td:last-child { border-end-end-radius: 12px; }
#indexlist tr:not(.indexhead):hover td,
#indexlist tr:focus-within td { background: var(--hover); }

#indexlist .indexcolicon {
    width: 1px;
    padding-inline-end: 0;
    padding-inline-start: 14px;
}
#indexlist .indexcolicon img { display: block; width: 20px; height: 20px; }
#indexlist th.indexcolicon img { visibility: hidden; }

#indexlist td.indexcolname { overflow-wrap: anywhere; }
#indexlist td.indexcolname a {
    /* a file name keeps its own direction on a right-to-left page */
    unicode-bidi: plaintext;
    color: var(--fg);
    text-decoration: none;
    font-weight: 500;
}
#indexlist td.indexcolname a:hover { color: var(--accent); text-decoration: underline; }
#indexlist td.indexcolname a::before {
    /* the whole row is the link's target area */
    content: "";
    position: absolute;
    inset: 0;
}
#indexlist tr { position: relative; }
#indexlist td.indexcoldesc a { position: relative; z-index: 1; }

#indexlist .indexcollastmod,
#indexlist .indexcolsize {
    width: 1px;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}
#indexlist .indexcolsize { text-align: end; }
#indexlist .indexcoldesc { color: var(--muted); font-size: 0.9rem; }
#indexlist.ai-nodesc .indexcoldesc { display: none; }

/* the parent directory row */
#indexlist tr[class$="-parent"] td.indexcolname a { color: var(--muted); font-weight: 400; }

#indexlist mark {
    padding: 0 1px;
    border-radius: 3px;
    background: var(--weak);
    color: inherit;
    font-weight: 650;
}

/* date and size under the name, for narrow screens (added by the script) */
.ai-meta {
    display: none;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 400;
}

#indexlist tr.ai-note td {
    padding: 28px 12px;
    color: var(--muted);
    text-align: center;
}

/* ------------------------------------------------- the rest of the page */

address {
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.82rem;
    font-style: normal;
}

/* The listing without HTMLTable (IndexOptions in a .htaccess, ?F=1): a
   <pre>, which at least keeps the colours and the font. */
body > pre {
    overflow-x: auto;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    font: 13px/1.6 ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
body > pre img { vertical-align: middle; width: 20px; height: 20px; }
body > hr { display: none; }

/* HEADER.html / README.html content */
body > p, body > ul, body > ol { max-width: 48rem; }
body > h1:not(#indextitle), body > h2, body > h3 { line-height: 1.3; }

/* ------------------------------------------------------- small screens */

@media (max-width: 720px) {
    #indexlist .indexcoldesc { display: none; }
}
@media (max-width: 600px) {
    body { padding-top: 20px; font-size: 14px; }
    h1#indextitle { font-size: 1.15rem; }
    /* search and theme switch on one line, the count under them */
    .ai-search { flex: 1 1 0; min-width: 0; max-width: none; }
    .ai-count { order: 3; flex-basis: 100%; }
    #indexlist th, #indexlist td { padding-inline: 10px; }
    #indexlist .indexcolicon { padding-inline-start: 12px; }
    /* only with the script, which puts date and size under the name */
    .ai #indexlist .indexcollastmod,
    .ai #indexlist .indexcolsize { display: none; }
    .ai .ai-meta { display: block; }
    #indexlist .indexcollastmod { white-space: normal; }
}

@media (prefers-reduced-motion: no-preference) {
    #indexlist td { transition: background-color 0.12s; }
}

@media print {
    .ai-bar { display: none; }
    table#indexlist, .ai-search input { box-shadow: none; }
    #indexlist th { position: static; }
}
