/* ============================================================
   Pulse — component styles (theme-aware via CSS variables)
   Colours come from --pulse-* tokens defined in base.html.
   Use rgb(var(--pulse-x) / <alpha>) so light/dark both work.
   ============================================================ */

/* Self-hosted Inter (variable). File vendored to static/vendor/. */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('/static/vendor/inter.woff2') format('woff2');
}

[x-cloak] { display: none !important; }

/* ---- Message list ------------------------------------------------ */

#messages-container { scroll-behavior: smooth; }

/* A single message row. Avatar sits in an absolute left gutter so that
   grouped (collapsed) messages stay aligned with full ones. */
.pulse-msg {
    position: relative;
    padding: 2px 3rem 2px 3.75rem;
    border-radius: 6px;
}
.pulse-msg:hover { background: rgb(var(--pulse-muted) / 0.08); }
.pulse-msg .msg-avatar {
    position: absolute;
    left: 0.75rem;
    top: 4px;
}
.pulse-msg .msg-gutter-time {
    position: absolute;
    left: 0;
    top: 6px;
    width: 3.75rem;
    text-align: center;
    font-size: 10px;
    line-height: 1;
    color: rgb(var(--pulse-muted));
    font-variant-numeric: tabular-nums;
    opacity: 0;
    pointer-events: none;
    transition: opacity .1s;
}

/* First message of a group keeps avatar + header; consecutive ones collapse. */
.pulse-msg.grouped { padding-top: 1px; padding-bottom: 1px; margin-top: 0; }
.pulse-msg.grouped .msg-avatar,
.pulse-msg.grouped .msg-header { display: none; }
.pulse-msg.grouped:hover .msg-gutter-time { opacity: 1; }
/* Add breathing room above the start of a new group */
.pulse-msg:not(.grouped) { margin-top: 0.5rem; }

/* Hover action toolbar */
.pulse-msg .msg-actions {
    position: absolute;
    top: -0.75rem;
    right: 0.75rem;
    display: none;
}
.pulse-msg:hover .msg-actions { display: flex; }

/* Date + unread separators */
.msg-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0;
    padding: 0 0.5rem;
}
.msg-divider::before,
.msg-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgb(var(--pulse-border));
}
.msg-divider span {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    color: rgb(var(--pulse-muted));
    text-transform: uppercase;
}
.msg-divider.unread::before,
.msg-divider.unread::after { background: rgb(var(--pulse-danger) / 0.5); }
.msg-divider.unread span { color: rgb(var(--pulse-danger)); }

/* Jump-to-present floating button */
.jump-present {
    position: absolute;
    right: 1.25rem;
    bottom: 6.5rem;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: rgb(var(--pulse-accent));
    border-radius: 999px;
    box-shadow: 0 6px 20px rgb(var(--pulse-accent) / 0.4);
    transition: transform .12s, opacity .12s;
}
.jump-present:hover { transform: translateY(-1px); }

/* ---- Markdown rendering (moved out of base.html, now theme-aware) - */
.msg-content { line-height: 1.45; }
.msg-content code:not(pre code) {
    background: rgb(var(--pulse-accent) / 0.14);
    color: rgb(var(--pulse-accent-hover));
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace;
}
.msg-content pre {
    background: rgb(var(--pulse-rail));
    border: 1px solid rgb(var(--pulse-border));
    color: rgb(var(--pulse-text));
    border-radius: 8px;
    padding: 0.75em 1em;
    overflow-x: auto;
    margin: 0.35em 0;
}
.msg-content pre code {
    background: none; color: inherit; padding: 0;
    font-size: 0.85em;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace;
}
.msg-content a { color: rgb(var(--pulse-accent)); text-decoration: underline; text-underline-offset: 2px; }
.msg-content a:hover { color: rgb(var(--pulse-accent-hover)); }
.msg-content strong { font-weight: 600; }
.msg-content em { font-style: italic; }
.msg-content s { text-decoration: line-through; opacity: 0.7; }
.msg-content blockquote {
    border-left: 3px solid rgb(var(--pulse-accent));
    padding-left: 0.75em;
    margin: 0.25em 0;
    color: rgb(var(--pulse-muted));
}
.msg-content .custom-emoji {
    height: 1.4em;
    width: auto;
    vertical-align: -0.25em;
    display: inline-block;
    margin: 0 1px;
}
.msg-content .msg-gif {
    display: block;
    max-width: min(360px, 100%);
    max-height: 280px;
    width: auto;
    border-radius: 10px;
    margin-top: 0.35rem;
    border: 1px solid rgb(var(--pulse-border));
}
.msg-content .mention {
    background: rgb(var(--pulse-accent) / 0.15);
    color: rgb(var(--pulse-accent-hover));
    padding: 0 0.25rem;
    border-radius: 4px;
    font-weight: 500;
}

/* ---- clickable message avatars open a profile card (PULSE-38) */
.msg-avatar { cursor: pointer; }

/* ---- spoilers (||text||) + pipe tables (PULSE-21) */
.msg-content .spoiler {
    background: rgb(var(--pulse-text) / 0.18);
    color: transparent;
    border-radius: 4px;
    padding: 0 0.2rem;
    cursor: pointer;
    filter: blur(5px);
    user-select: none;
    transition: filter 0.1s, color 0.1s, background 0.1s;
}
.msg-content .spoiler.revealed {
    background: rgb(var(--pulse-text) / 0.08);
    color: inherit;
    filter: none;
    cursor: text;
    user-select: text;
}
.msg-content .md-table {
    border-collapse: collapse;
    margin: 0.4em 0;
    font-size: 0.9em;
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
}
.msg-content .md-table th,
.msg-content .md-table td {
    border: 1px solid rgb(var(--pulse-border));
    padding: 0.3em 0.6em;
    text-align: left;
}
.msg-content .md-table th {
    background: rgb(var(--pulse-input));
    font-weight: 600;
}

/* ---- highlight.js tokens (theme-driven, no separate hljs theme css) */
.hljs { color: rgb(var(--pulse-text)); background: transparent; }
.hljs-comment, .hljs-quote { color: rgb(var(--pulse-muted)); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-link { color: rgb(var(--pulse-accent)); }
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-addition { color: rgb(var(--pulse-success)); }
.hljs-number, .hljs-meta, .hljs-built_in, .hljs-builtin-name, .hljs-symbol { color: rgb(var(--pulse-warning)); }
.hljs-title, .hljs-class .hljs-title, .hljs-type, .hljs-function .hljs-title { color: rgb(var(--pulse-accent-hover)); font-weight: 600; }
.hljs-variable, .hljs-name, .hljs-tag { color: rgb(var(--pulse-danger)); }
.hljs-deletion { color: rgb(var(--pulse-danger)); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---- Composer ---------------------------------------------------- */
.composer-toolbar button { transition: color .12s, background .12s; }

/* Slash-command & mention autocomplete popovers share this look */
.composer-popover {
    background: rgb(var(--pulse-sidebar));
    border: 1px solid rgb(var(--pulse-border));
    border-radius: 12px;
    box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}

/* Emoji picker */
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid button {
    width: 2rem; height: 2rem; font-size: 1.15rem; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px; transition: background .1s, transform .05s;
}
.emoji-grid button:hover { background: rgb(var(--pulse-hover)); transform: scale(1.12); }
.emoji-cat-tabs button { opacity: .55; transition: opacity .12s; }
.emoji-cat-tabs button:hover, .emoji-cat-tabs button.active { opacity: 1; }

/* ---- Misc -------------------------------------------------------- */
.typing-dots span { animation: blink 1.4s both infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

.unread-badge { min-width: 18px; text-align: center; }

@keyframes badge-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.badge-new { animation: badge-pulse 0.5s ease-in-out; }

/* Flash highlight when jumping to a message */
@keyframes msg-flash {
    0% { background: rgb(var(--pulse-accent) / 0.22); }
    100% { background: transparent; }
}
.msg-flash { animation: msg-flash 2s ease-out; }

/* Mobile sidebar slide-in */
@media (max-width: 768px) {
    .sidebar-mobile { transform: translateX(-100%); transition: transform 0.2s; }
    .sidebar-mobile.open { transform: translateX(0); }
    .pulse-msg .msg-actions { display: flex; } /* touch: always show */
}

@media print {
    aside, header, .composer, .msg-actions { display: none !important; }
}

/* ---- Accessibility ---------------------------------------------- */

/* Keyboard focus ring on every interactive element. :where() keeps zero
   specificity (component styles still win), and :focus-visible means it only
   shows for keyboard / assistive-tech navigation, not mouse clicks. */
:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
    outline: 2px solid rgb(var(--pulse-accent));
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip-to-content link: off-screen until focused. */
.skip-link {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    margin: 0.5rem;
    padding: 0.5rem 0.9rem;
    background: rgb(var(--pulse-accent));
    color: #fff;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    transform: translateY(-150%);
    transition: transform 0.15s;
}
.skip-link:focus { transform: translateY(0); }

/* Honour the reduced-motion preference: kill animations / transitions / smooth-scroll. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
