/* ==========================================================================
   gists.css — listing, viewer and editor for code snippets (pages/gists.php).
   Code block styling itself is shared with rich-content.css via the .rc/.rc-code
   classes, so a gist and a fenced block in a forum post look identical.
   ========================================================================== */

.gist-page {
    width: 100%;
    max-width: 980px;
    min-width: 0;
    margin: 0 auto;
    padding: 24px 18px 64px;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-x: clip;
}

/* ---- Header -------------------------------------------------------------- */
.gist-head {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.gist-head-text { flex: 1 1 260px; min-width: 0; }
.gist-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0;
    font-family: var(--font-display, inherit);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary, #f8fafc);
}
.gist-title a { color: var(--accent, #3b82f6); text-decoration: none; }
.gist-title a:hover { text-decoration: underline; }
.gist-title i { color: var(--text-secondary, #94a3b8); }
.gist-name { min-width: 0; max-width: 100%; font-family: var(--font-mono, ui-monospace, monospace); font-size: 19px; overflow-wrap: anywhere; }
.gist-sep { color: var(--text-tertiary, #64748b); font-weight: 400; }
.gist-meta { font-size: 12.5px; color: var(--text-tertiary, #64748b); }
.gist-meta a { color: var(--accent, #3b82f6); }
.gist-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gist-actions .is-starred i { color: var(--warning, #f59e0b); }
.gist-description {
    margin: 0 0 16px;
    font-size: 15px;
    color: var(--text-secondary, #94a3b8);
    line-height: 1.6;
}
.gist-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: var(--radius-full, 999px);
}
.gist-badge.secret {
    color: var(--warning, #f59e0b);
    background: var(--warning-soft, rgba(245, 158, 11, 0.14));
    border: 1px solid rgba(245, 158, 11, 0.35);
}

/* ---- Search -------------------------------------------------------------- */
.gist-search { position: relative; margin-bottom: 18px; }
.gist-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary, #64748b);
    pointer-events: none;
}
.gist-search .form-input { padding-left: 38px; width: 100%; }

/* ---- Listing ------------------------------------------------------------- */
.gist-list { display: flex; flex-direction: column; gap: 18px; }
.gist-card {
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius-md, 16px);
    background: var(--surface-1, rgba(15, 23, 42, 0.65));
    padding: 14px 16px;
    transition: border-color .16s ease, transform .16s ease;
}
.gist-card:hover { border-color: rgba(59, 130, 246, 0.45); transform: translateY(-1px); }
.gist-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.gist-card-title { flex: 1; min-width: 0; }
.gist-card-title a { color: var(--text-primary, #f8fafc); text-decoration: none; }
.gist-card-title a:hover strong { color: var(--accent, #3b82f6); }
.gist-card-title strong { font-family: var(--font-mono, ui-monospace, monospace); font-size: 14.5px; overflow-wrap: anywhere; }
.gist-card-author { color: var(--text-secondary, #94a3b8); }
.gist-card-stats { display: flex; gap: 12px; font-size: 12.5px; color: var(--text-tertiary, #64748b); white-space: nowrap; }
.gist-card-desc { margin: 0 0 10px; font-size: 14px; color: var(--text-secondary, #94a3b8); }
/* Card previews are excerpts: cap the height so one long snippet cannot own the page. */
.gist-card .rc-code-pre { max-height: 260px; overflow: auto; }
.gist-card,
.gist-card .rc,
.gist-card .rc-code,
.gist-card-markdown { min-width: 0; max-width: 100%; }
.gist-card-markdown {
    max-height: 280px;
    padding: 12px 14px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius-sm, 10px);
    background: rgba(148, 163, 184, 0.04);
}

/* ---- Source / rendered viewer ------------------------------------------ */
.gist-viewer {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: var(--radius-sm, 10px);
    background: #0d1117;
    box-shadow: var(--shadow-sm, 0 4px 14px rgba(0,0,0,.25));
}
.gist-viewer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    padding: 8px 12px;
    background: rgba(148, 163, 184, 0.09);
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}
.gist-viewer-file {
    min-width: 0;
    overflow: hidden;
    color: var(--text-secondary, #94a3b8);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gist-viewer-file i { margin-right: 6px; opacity: .75; }
.gist-viewer-tools,
.gist-view-tabs { display: flex; align-items: center; gap: 6px; min-width: 0; }
.gist-view-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    padding: 4px 9px;
    color: var(--text-tertiary, #64748b);
    font: inherit;
    font-size: 11.5px;
    font-weight: 650;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
}
.gist-view-tab:hover { color: var(--text-primary, #f8fafc); background: rgba(148, 163, 184, .09); }
.gist-view-tab.is-active {
    color: var(--accent, #3b82f6);
    border-color: rgba(59, 130, 246, .35);
    background: var(--accent-soft, rgba(59, 130, 246, .14));
}
.gist-view-panel { width: 100%; min-width: 0; max-width: 100%; }
.gist-view-panel[hidden] { display: none !important; }
.gist-source-panel { background: #0d1117; }
.gist-source-panel .rc-code-pre { width: 100%; max-width: 100%; box-sizing: border-box; }
.gist-markdown-preview {
    padding: 22px 24px 26px;
    overflow-x: hidden;
    background: var(--surface-1, #111827);
}
.gist-markdown-content,
.gist-markdown-content > * { max-width: 100%; }
.gist-markdown-content pre,
.gist-markdown-content .rc-code,
.gist-markdown-content .rc-table-wrap { min-width: 0; max-width: 100%; }

/* ---- Editor -------------------------------------------------------------- */
.gist-form { display: flex; flex-direction: column; gap: 14px; }
.gist-desc { width: 100%; }
.gist-file {
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--radius-md, 16px);
    overflow: hidden;
    background: var(--surface-1, rgba(15, 23, 42, 0.65));
}
.gist-file:focus-within { border-color: var(--accent, #3b82f6); box-shadow: 0 0 0 3px var(--accent-ring, rgba(59,130,246,.35)); }
.gist-file-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: rgba(148, 163, 184, 0.07);
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}
.gist-filename {
    flex: 1 1 240px;
    min-width: 0;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 13.5px;
    color: var(--text-primary, #f8fafc);
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 7px;
    padding: 6px 10px;
    outline: none;
}
.gist-filename:focus { border-color: var(--accent, #3b82f6); }
.gist-file-hint { font-size: 11.5px; color: var(--text-tertiary, #64748b); }
.gist-code-input {
    display: block;
    width: 100%;
    min-height: 380px;
    padding: 14px 16px;
    font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-primary, #f8fafc);
    background: transparent;
    border: 0;
    outline: none;
    resize: vertical;
    tab-size: 4;
    white-space: pre;
    overflow-x: auto;
}
.gist-form-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}
.gist-form-actions { display: flex; gap: 8px; }

/* ---- Comments ------------------------------------------------------------ */
.gist-comments { margin-top: 32px; }
.gist-section-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    color: var(--text-primary, #f8fafc);
}
.gist-comment { display: flex; gap: 12px; margin-bottom: 16px; }
.gist-comment-body {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius-sm, 10px);
    background: var(--surface-1, rgba(15, 23, 42, 0.65));
    overflow: hidden;
}
.gist-comment-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 13px;
    font-size: 13px;
    background: rgba(148, 163, 184, 0.07);
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}
.gist-comment-del {
    margin-left: auto;
    background: none;
    border: 0;
    color: var(--text-tertiary, #64748b);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 5px;
}
.gist-comment-del:hover { color: var(--danger, #f43f5e); background: var(--danger-soft, rgba(244,63,94,.14)); }
.gist-comment-body .rc { padding: 12px 13px; }
.gist-comment-form { margin-top: 18px; }
.gist-comment-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---- Empty state & pager ------------------------------------------------- */
.gist-empty {
    text-align: center;
    padding: 70px 20px;
    color: var(--text-secondary, #94a3b8);
}
.gist-empty i { font-size: 52px; color: var(--text-quaternary, #475569); margin-bottom: 16px; display: block; }
.gist-empty h2 { margin: 0 0 8px; font-size: 20px; color: var(--text-primary, #f8fafc); }
.gist-empty p { margin: 0 0 18px; }
.gist-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 26px;
}

@media (max-width: 640px) {
    .gist-page { padding: 16px 12px 48px; }
    .gist-title { font-size: 18px; }
    .gist-name { font-size: 16px; }
    .gist-actions { width: 100%; }
    .gist-code-input { min-height: 280px; font-size: 12.5px; }
    .gist-head-text,
    .gist-card-title,
    .gist-comment-body,
    .gist-viewer,
    .gist-view-panel,
    .gist-markdown-content { min-width: 0; max-width: 100%; }
    .gist-viewer-head { align-items: stretch; flex-direction: column; }
    .gist-viewer-tools { justify-content: space-between; width: 100%; }
    .gist-view-tabs { overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; }
    .gist-view-tabs::-webkit-scrollbar { display: none; }
    .gist-view-tab { flex: 0 0 auto; }
    .gist-markdown-preview { padding: 16px 13px 20px; }
    .gist-source-panel .rc-code-pre { padding: 12px; overflow-x: auto; }
    .gist-card { padding: 12px 10px; overflow: hidden; }
    .gist-card-markdown { padding: 11px; }
    .gist-card-stats { width: 100%; justify-content: flex-end; }
}

[data-theme="light"] .gist-card,
[data-theme="light"] .gist-file,
[data-theme="light"] .gist-comment-body { background: #fff; border-color: rgba(15, 23, 42, 0.12); }
[data-theme="light"] .gist-viewer { border-color: rgba(15, 23, 42, 0.12); }
[data-theme="light"] .gist-markdown-preview { background: #fff; }
[data-theme="light"] .gist-card-markdown { background: rgba(15, 23, 42, .025); border-color: rgba(15, 23, 42, .1); }
