/* ==========================================================================
   heftos.css — Heftos branding layer on top of Django admin.

   RULE: ALL custom classes MUST be prefixed with `ht-`.
   This avoids collisions with Django admin classes and third-party CSS.

   When adding, renaming, or removing utility classes, update the CSS primer
   at docs/css.md so the live samples stay in sync.
   ========================================================================== */

/* Override Django admin color variables */
:root {
    --secondary: rgb(0, 7, 61);
    --link-fg: rgb(97, 131, 231);
    --primary: rgb(97, 131, 231);
    --font-family-primary: system-ui, sans-serif;
    --font-family-monospace: ui-monospace, monospace;
}

#changelist-search label img {
    width: 15px;
    height: 15px;
}

/* ---------- Text utilities ----------------------------------------------- */

.ht-text-muted {
    color: #666;
}
.ht-text-error {
    color: var(--error-fg);
    font-weight: bold;
}

/* ---------- Color utilities ---------------------------------------------- */

.ht-color-green { color: #28a745; }
.ht-color-red { color: #dc3545; }
.ht-color-yellow { color: #ffc107; }
.ht-color-orange { color: #ff8c00; }
.ht-color-gray { color: #888; }

/* ---------- Spacing ------------------------------------------------------ */

.ht-mt {
    margin-top: 20px;
}
.ht-mb {
    margin-bottom: 15px;
}
.ht-mt-neg {
    margin-top: -5px;
}

/* ---------- Form input sizes --------------------------------------------- */

.ht-input-sm,
.ht-input-md,
.ht-input-lg,
.ht-select-sm {
    padding: 6px;
}
.ht-input-sm {
    width: 120px;
}
.ht-input-md {
    width: 140px;
}
.ht-input-lg {
    width: 300px;
}
.ht-input-full {
    width: 100%;
    box-sizing: border-box;
}

/* ---------- Admin base site ---------------------------------------------- */

.ht-pr-badge {
    font-size: 0.7em;
    margin-left: 10px;
    opacity: 0.8;
}
.ht-pr-badge a {
    color: inherit;
    text-decoration: none;
}
.ht-branch-badge {
    font-family: ui-monospace, monospace;
    font-size: 0.7em;
    margin-left: 8px;
    opacity: 0.85;
}
.ht-flex-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* ---------- Badge -------------------------------------------------------- */

.ht-badge {
    display: inline-block;
    font-size: 0.85em;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    background: var(--darkened-bg, #f0f0f0);
    color: var(--body-fg, #333);
    border: 1px solid var(--border-color, #ddd);
}
.ht-badge.success { background: var(--message-success-bg, #dfd); color: #155724; }
.ht-badge.error { background: var(--message-error-bg, #fdd); color: #721c24; }
.ht-badge.warning { background: var(--message-warning-bg, #ffc); color: #856404; }
.ht-badge.info { background: var(--message-info-bg, #bee5eb); color: #0c5460; }
@media (prefers-color-scheme: dark) {
    .ht-badge.success { color: #a3cfbb; }
    .ht-badge.error { color: #f5c6cb; }
    .ht-badge.warning { color: #ffe69c; }
    .ht-badge.info { color: #9cdcfe; }
}

/* ---------- Detail view — reusable across detail pages ------------------- */

.ht-detail-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}
.ht-detail-header h2 {
    margin: 0;
    font-size: 1.4em;
}

.ht-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
    background: var(--darkened-bg, #f8f8f8);
    padding: 15px;
    border-radius: 6px;
}
.ht-info-item {
    display: flex;
    flex-direction: column;
}
.ht-info-label {
    font-size: 0.75em;
    color: var(--body-quiet-color, #666);
    text-transform: uppercase;
    margin-bottom: 3px;
}
.ht-info-value {
    font-weight: 500;
    font-family: monospace;
}

.ht-section-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 25px 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color, #ddd);
}

.ht-data-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85em;
    margin-bottom: 25px;
}
.ht-data-table th,
.ht-data-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #ddd);
}
.ht-data-table th {
    background: var(--darkened-bg, #f0f0f0);
    font-weight: 600;
}

/* ---------- Tool content wrapper ----------------------------------------- */

.ht-tool-content {
    max-width: 1200px;
    margin: 20px 0;
}
.ht-tool-content.ht-tool-content-narrow {
    max-width: 1000px;
}
.ht-tool-content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85em;
}
.ht-tool-content th,
.ht-tool-content td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #ddd);
}
.ht-tool-content th {
    background: var(--darkened-bg, #f8f8f8);
    font-weight: 600;
}
.ht-tool-content tr:hover {
    background: var(--darkened-bg, #f5f5f5);
}
.ht-tool-content a {
    color: var(--link-fg, #447e9b);
    text-decoration: none;
}
.ht-tool-content a:hover {
    text-decoration: underline;
}
.ht-tool-content pre {
    margin: 0;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    padding: 15px;
}

/* ---------- Empty message ------------------------------------------------ */

.ht-empty-msg {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 40px;
}

/* ---------- Tool link (admin header) ------------------------------------- */

#user-tools a.ht-tool-link,
#user-tools a.ht-tool-link:visited {
    color: rgb(97, 131, 231);
}
#user-tools a.ht-tool-link:hover {
    color: #a33;
}

/* ---------- Tab bar ------------------------------------------------------ */

.ht-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border-color, #ccc);
}
.ht-tabs button {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    cursor: pointer;
    color: var(--body-fg, inherit);
    font-size: 14px;
    margin-bottom: -2px;
    border-radius: 4px 4px 0 0;
}
.ht-tabs button:hover:not(:disabled) {
    background: var(--darkened-bg, #f8f8f8);
}
.ht-tabs button:disabled {
    border-color: var(--border-color, #ccc);
    border-bottom-color: var(--body-bg, #fff);
    font-weight: bold;
    cursor: default;
}

/* ---------- Tag pill ------------------------------------------------------ */

.ht-tag {
    display: inline-block;
    background: #e8f0fe;
    color: #1a73e8;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.8em;
    margin-right: 4px;
}

/* ---------- Ask bot — inline form ---------------------------------------- */

.ht-ask-bot-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 0;
}
.ht-ask-bot-editor {
    border: 1px solid #ccc;
    border-radius: 4px;
}
.ht-ask-bot-button {
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}
.ht-ask-bot-button-primary {
    background: var(--secondary);
    color: #fff;
    border: none;
}
.ht-ask-bot-button-primary:hover {
    background: #205067;
}
.ht-ask-bot-button-secondary {
    background: #fff;
    color: var(--secondary);
    border: 1px solid var(--secondary);
}
.ht-ask-bot-button-secondary:hover {
    background: #f0f7fa;
}

/* ---------- Ask bot — floating widget ------------------------------------ */

.ht-ask-bot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}
.ht-ask-bot-widget-panel {
    display: none;
    width: 380px;
    max-width: calc(100vw - 40px);
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 12px;
    flex-direction: column;
    gap: 8px;
}
.ht-ask-bot-widget-open .ht-ask-bot-widget-panel {
    display: flex;
}
.ht-ask-bot-widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}
.ht-ask-bot-widget-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    padding: 0 4px;
    line-height: 1;
}
.ht-ask-bot-widget-close:hover {
    color: #333;
}
.ht-ask-bot-widget-toggle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgb(97, 131, 231);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: background 0.2s;
}
.ht-ask-bot-widget-toggle:hover {
    background: #205067;
}

/* ---------- Ask bot — comment history ------------------------------------ */

.ht-ask-bot-comments {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ht-ask-bot-comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 4px;
    border-bottom: 1px solid #e0e0e0;
}
.ht-ask-bot-comments-title {
    font-weight: 600;
    font-size: 12px;
    color: #555;
}
.ht-ask-bot-refresh-btn {
    padding: 2px 8px !important;
    font-size: 11px !important;
}
.ht-ask-bot-comments-list {
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}
.ht-ask-bot-comments-loading,
.ht-ask-bot-comments-empty {
    font-size: 12px;
    color: #888;
    text-align: center;
    padding: 12px 0;
}
.ht-ask-bot-comment {
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
}
.ht-ask-bot-comment-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
}
.ht-ask-bot-comment-avatar {
    border-radius: 50%;
    vertical-align: middle;
}
.ht-ask-bot-comment-user {
    font-weight: 600;
    color: var(--link-fg);
    text-decoration: none;
    font-size: 11px;
}
.ht-ask-bot-comment-date {
    color: #888;
    font-size: 10px;
    margin-left: auto;
}
.ht-ask-bot-comment-body {
    white-space: pre-wrap;
    word-break: break-word;
    color: #333;
    line-height: 1.4;
    max-height: 80px;
    overflow-y: auto;
}

/* ---------- Dark mode ---------------------------------------------------- */

@media (prefers-color-scheme: dark) {
    /* Tool content */
    .ht-tool-content a {
        color: #9cdcfe;
    }
    .ht-ask-bot-editor {
        border-color: #555;
    }
    .ht-ask-bot-button-primary {
        background: #264b5d;
    }
    .ht-ask-bot-button-primary:hover {
        background: #1a3545;
    }
    .ht-ask-bot-button-secondary {
        background: transparent;
        color: #9cdcfe;
        border-color: #9cdcfe;
    }
    .ht-ask-bot-button-secondary:hover {
        background: #2a3a44;
    }
    .ht-ask-bot-widget-panel {
        background: #1e1e1e;
        border-color: #444;
        color: #d4d4d4;
    }
    .ht-ask-bot-widget-close {
        color: #aaa;
    }
    .ht-ask-bot-widget-close:hover {
        color: #d4d4d4;
    }
    .ht-ask-bot-widget-toggle {
        background: rgb(97, 131, 231);
    }
    .ht-ask-bot-widget-toggle:hover {
        background: #1a3545;
    }
    .ht-ask-bot-comments-header {
        border-bottom-color: #444;
    }
    .ht-ask-bot-comments-title {
        color: #aaa;
    }
    .ht-ask-bot-comment {
        border-color: #444;
    }
    .ht-ask-bot-comment-body {
        color: #d4d4d4;
    }
    .ht-ask-bot-comments-loading,
    .ht-ask-bot-comments-empty {
        color: #888;
    }
    #user-tools a.ht-tool-link,
    #user-tools a.ht-tool-link:visited {
        color: rgb(97, 131, 231);
    }
    #user-tools a.ht-tool-link:hover {
        color: #faa;
    }

    /* Tag pill */
    .ht-tag {
        background: #264b5d;
        color: #9cdcfe;
    }
}

/* ---------- Image pipeline test ------------------------------------------ */

.ht-pipeline-form {
    margin-bottom: 20px;
}
.ht-result-preview {
    background: var(--darkened-bg, #f8f8f8);
    border: 1px solid var(--border-color, #ddd);
    padding: 15px;
    text-align: center;
}
.ht-result-preview img {
    max-width: 100%;
}

/* ---------- Login page --------------------------------------------------- */

.ht-login-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}
.ht-login-divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px solid #ccc;
}
.ht-login-divider span {
    background: var(--body-bg, #fff);
    padding: 0 12px;
    position: relative;
    color: #999;
    font-size: 13px;
    text-transform: uppercase;
}
@media (prefers-color-scheme: dark) {
    .ht-login-divider::before {
        border-color: #444;
    }
    .ht-login-divider span {
        background: var(--body-bg, #121212);
    }
}
#passwordless-login h2,
#password-login h2 {
    font-size: 16px;
    margin: 0 0 10px;
    font-weight: 600;
}
#passwordless-login .form-row input[type="email"] {
    padding: 8px;
    width: 100%;
    box-sizing: border-box;
}

/* ---------- Docs viewer -------------------------------------------------- */

.ht-docs-content { max-width: 860px; }
.ht-docs-content h1,
.ht-docs-content h2,
.ht-docs-content h3,
.ht-docs-content h4,
.ht-docs-content h5,
.ht-docs-content h6 { margin-top: 1.2em; }
.ht-docs-content :is(h1,h2,h3,h4,h5,h6) .headerlink {
    opacity: 0; margin-left: 0.4em; text-decoration: none; color: #888; font-weight: normal; transition: opacity 0.1s;
}
.ht-docs-content :is(h1,h2,h3,h4,h5,h6):hover .headerlink { opacity: 1; }
.ht-docs-content pre { background: #2a2a2a; padding: 1em; overflow-x: auto; }
.ht-docs-content code { background: #2a2a2a; padding: 0.15em 0.3em; border-radius: 3px; font-size: 0.9em; }
.ht-docs-content pre code { background: none; padding: 0; }
.ht-docs-content table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.ht-docs-content th,
.ht-docs-content td { border: 1px solid #444; padding: 6px 10px; text-align: left; }
.ht-docs-content th { background: #333; }
.ht-docs-content blockquote { border-left: 4px solid #555; margin: 0; padding-left: 1em; color: #aaa; }
.ht-docs-content img { max-width: 100%; }
.ht-docs-content .highlight { background: #2a2a2a; padding: 0.5em; overflow-x: auto; border-radius: 4px; font-size: 0.9em; }
.ht-docs-content pre.mermaid { background: none; padding: 0; overflow: visible; }

.ht-docs-content .md-alert { border-left: 4px solid; padding: 0.6em 1em; margin: 1em 0; border-radius: 0 4px 4px 0; }
.ht-docs-content .md-alert-title { font-weight: bold; margin: 0 0 0.4em; text-transform: uppercase; font-size: 0.85em; }
.ht-docs-content .md-alert-note { border-color: #0969da; background: #0c2d6b; }
.ht-docs-content .md-alert-note .md-alert-title { color: #0969da; }
.ht-docs-content .md-alert-tip { border-color: #1a7f37; background: #0a3320; }
.ht-docs-content .md-alert-tip .md-alert-title { color: #1a7f37; }
.ht-docs-content .md-alert-important { border-color: #8250df; background: #2d1a5e; }
.ht-docs-content .md-alert-important .md-alert-title { color: #8250df; }
.ht-docs-content .md-alert-warning { border-color: #9a6700; background: #3a2800; }
.ht-docs-content .md-alert-warning .md-alert-title { color: #9a6700; }
.ht-docs-content .md-alert-caution { border-color: #cf222e; background: #4a0c0f; }
.ht-docs-content .md-alert-caution .md-alert-title { color: #cf222e; }

.ht-docs-content .toc { background: #1e1e1e; border: 1px solid #444; border-radius: 4px; padding: 0.8em 1.2em; display: inline-block; min-width: 200px; margin: 1em 0; }
.ht-docs-content .toc ul { margin: 0.2em 0; padding-left: 1.4em; }
.ht-docs-content .toc > ul { padding-left: 0; list-style: none; }
.ht-docs-content .toc li { margin: 0.2em 0; }
.ht-docs-content .toc a { text-decoration: none; color: #6af; }
.ht-docs-content .toc a:hover { text-decoration: underline; }

.ht-file-truncated-notice { background: #3a2800; border: 1px solid #9a6700; border-radius: 4px; padding: 0.5em 0.8em; margin-bottom: 1em; font-size: 0.9em; }

/* ---------- Info box & stats --------------------------------------------- */

.ht-info-box {
    background: var(--darkened-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}
.ht-info-box p { margin: 5px 0; }
.ht-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}
.ht-stat-card {
    background: var(--darkened-bg);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.ht-stat-label {
    font-size: 11px;
    color: var(--body-quiet-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ht-stat-value {
    font-size: 20px;
    font-weight: 700;
    margin-top: 2px;
}
.ht-thumbnail { width: 50px; height: 50px; object-fit: contain; }

/* ==========================================================================
   Catalog page
   ========================================================================== */

.ht-catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    list-style: none;
    padding: 0;
    margin: 0;
}
.ht-catalog-grid > li {
    background: var(--body-bg);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--hairline-color);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}
.ht-catalog-grid > li:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.ht-catalog-grid .cover {
    background: var(--darkened-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 300px;
    border-bottom: 1px solid var(--hairline-color);
}
.ht-catalog-grid .cover img {
    max-width: 160px;
    width: 100%;
    height: auto;
    max-height: 260px;
    object-fit: contain;
    border-radius: 2px;
    box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.15);
}
.ht-catalog-grid .no-cover {
    width: 160px;
    height: 240px;
    background: var(--darkened-bg);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}
.ht-catalog-grid .no-cover span {
    font-size: 0.95rem;
    color: var(--body-quiet-color);
    text-align: center;
    font-style: italic;
}
.ht-catalog-grid .info {
    padding: 1.25rem 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.ht-catalog-grid .title {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--body-fg);
    margin: 0 0 0.3rem;
}
.ht-catalog-grid .author {
    font-size: 0.9rem;
    color: var(--body-quiet-color);
    font-weight: 500;
    margin: 0 0 0.5rem;
}
.ht-catalog-grid .desc {
    font-size: 0.875rem;
    color: var(--body-fg);
    line-height: 1.55;
    margin: 0 0 0.75rem;
}
.ht-catalog-grid .year {
    font-size: 0.75rem;
    color: var(--body-quiet-color);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 600;
    margin: 0 0 1rem;
}
.ht-spacer { flex: 1; }
.ht-btn-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--link-fg);
    text-decoration: none;
    padding: 0.6rem 1.2rem;
    border: 1.5px solid var(--link-fg);
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}
.ht-btn-outline:hover {
    background: var(--link-fg);
    color: var(--body-bg);
}
.ht-btn-outline svg { width: 15px; height: 15px; flex-shrink: 0; }
.ht-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--body-quiet-color);
    font-size: 1rem;
}
.ht-catalog-footer {
    text-align: center;
    padding: 1.5rem 2rem;
    color: var(--body-quiet-color);
    font-size: 0.875rem;
    border-top: 1px solid var(--hairline-color);
}
.ht-catalog-footer p { margin: 0.25rem 0; }
@media (max-width: 680px) {
    .ht-catalog-grid { grid-template-columns: 1fr; gap: 1.5rem; }
    .ht-catalog-grid .cover { min-height: 260px; }
}

/* ---------- XML Editor --------------------------------------------------- */

body.ht-editor { overflow: hidden; }
body.ht-editor #container { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
body.ht-editor #main { flex: 1; overflow: hidden; display: flex; }
body.ht-editor .content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
body.ht-editor #content { padding: 0; overflow: hidden; flex: 1; }
body.ht-editor #ht-editor-wrap { height: 100%; display: flex; flex-direction: column; }
body.ht-editor #editor { flex: 1; }
