/* ChitChat "Electric Plum" brand tokens. Single source of truth for this app — see
   docs/brand/BRAND.md and docs/brand/contrast-report.md for the reasoning and the
   WCAG AA verification behind every value here (re-run after this retarget — §6.4).
   Do not hardcode hex colors in markup; add a token here instead. Mirrored 1:1 (same
   token names, kebab-cased) in the Android app's Color.kt/Theme.kt. */
@font-face {
    font-family: "Plus Jakarta Sans Variable";
    src: url("/fonts/PlusJakartaSansVariable.ttf") format("truetype-variations"), url("/fonts/PlusJakartaSansVariable.ttf") format("truetype");
    font-weight: 200 800;
    font-display: swap;
}

@font-face {
    font-family: "Inter Variable";
    src: url("/fonts/InterVariable.ttf") format("truetype-variations"), url("/fonts/InterVariable.ttf") format("truetype");
    font-weight: 100 900;
    font-display: swap;
}

:root {
    /* Surfaces */
    --chitchat-bg: #F8F9FA;
    --chitchat-surface: #FFFFFF;
    --chitchat-surface-variant: #F1ECFB;
    --chitchat-surface-elevated: #FFFFFF;
    --chitchat-border: #E5E7EB;

    /* Brand */
    --chitchat-primary: #1A0B2E;
    --chitchat-on-primary: #FFFFFF;
    --chitchat-primary-deep: #6D28D9; /* §6.4: light-mode-safe substitute for small secondary/accent-colored text. */
    --chitchat-secondary: #8B5CF6;
    --chitchat-on-secondary: #FFFFFF;
    --chitchat-accent: #EC4899;
    --chitchat-on-accent: #FFFFFF;
    --chitchat-glow: rgba(139, 92, 246, 0.3);
    --chitchat-gradient-electric: linear-gradient(135deg, #8B5CF6, #EC4899);
    --chitchat-gradient-midnight: linear-gradient(180deg, #1A0B2E, #3B1C6B);

    /* Chat bubbles */
    --chitchat-bubble-mine-bg: var(--chitchat-gradient-electric);
    --chitchat-bubble-mine-text: #FFFFFF;
    --chitchat-bubble-theirs-bg: #FFFFFF;
    --chitchat-bubble-theirs-text: #0F172A;
    --chitchat-bubble-theirs-border: #EDE9FE;

    /* Text */
    --chitchat-text-primary: #0F172A;
    --chitchat-text-secondary: #475569;
    --chitchat-text-tertiary: #94A3B8;

    /* Status. §6.4 requires WCAG AA everywhere — the brief's literal §6.2 values read 2.15-3.76:1
       as text/icons on a WHITE light-mode surface (verified with docs/brand/contrast-check.mjs,
       re-run after touching any of these), so light mode gets its own deepened shade instead;
       dark mode keeps the brief's exact values (4.93-8.64:1 against #1A0B2E, already compliant). */
    --chitchat-success: #15803D;
    --chitchat-warning: #B45309;
    --chitchat-error: #DC2626;
    --chitchat-info: #2563EB;
    --chitchat-call-accept: #15803D;
    --chitchat-call-decline: #DC2626;

    /* Shape (§6.6) */
    --chitchat-radius-sm: 8px;
    --chitchat-radius-md: 12px;
    --chitchat-radius-lg: 16px;
    --chitchat-radius-xl: 24px;
    --chitchat-radius-full: 999px;
    --chitchat-radius-bubble: 18px;
    --chitchat-radius-bubble-tail: 4px;

    /* Spacing (4pt grid — §6.6) */
    --chitchat-space-xxs: 4px;
    --chitchat-space-xs: 8px;
    --chitchat-space-sm: 12px;
    --chitchat-space-md: 16px;
    --chitchat-space-lg: 20px;
    --chitchat-space-xl: 24px;
    --chitchat-space-xxl: 32px;

    /* Motion (§6.6) */
    --chitchat-motion-short: 150ms;
    --chitchat-motion-medium: 220ms;
    --chitchat-motion-long: 300ms;
    --chitchat-motion-easing: cubic-bezier(0.2, 0, 0, 1);

    /* Type (§6.5) */
    --chitchat-font-brand: "Plus Jakarta Sans Variable", -apple-system, "Segoe UI", Roboto, sans-serif;
    --chitchat-font-body: "Inter Variable", -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --chitchat-bg: #0F0618;
        --chitchat-surface: #1A0B2E;
        --chitchat-surface-variant: #2E1A4A;
        --chitchat-surface-elevated: #24133D;
        --chitchat-border: #33224F;
        --chitchat-primary: #1A0B2E;
        --chitchat-on-primary: #FFFFFF;
        --chitchat-primary-deep: #A78BFA;
        --chitchat-secondary: #A78BFA;
        --chitchat-on-secondary: #0F0618;
        --chitchat-accent: #F472B6;
        --chitchat-on-accent: #0F0618;
        --chitchat-bubble-mine-bg: var(--chitchat-gradient-electric);
        --chitchat-bubble-mine-text: #FFFFFF;
        --chitchat-bubble-theirs-bg: #2E1A4A;
        --chitchat-bubble-theirs-text: #FFFFFF;
        --chitchat-bubble-theirs-border: #33224F;
        --chitchat-text-primary: #FFFFFF;
        --chitchat-text-secondary: #CBD5E1;
        --chitchat-text-tertiary: #94A3B8;
        /* Brief's original §6.2 values — correct against a dark surface (4.93-8.64:1); it's only
           light mode that needed its own deepened shade (see :root). Gradients are unchanged. */
        --chitchat-success: #22C55E;
        --chitchat-warning: #F59E0B;
        --chitchat-error: #EF4444;
        --chitchat-info: #3B82F6;
        /* Deliberately the LIGHT-mode-deepened values, not the lines above — a white icon
           directly on #22C55E fails even the 3:1 icon bar (2.28:1) regardless of surrounding
           theme; --chitchat-success only passes as small text/a dot against THIS dark surface,
           a different pairing. Same "reuse light theme's values in both themes" call-button
           pattern this codebase already used pre-retarget. */
        --chitchat-call-accept: #15803D;
        --chitchat-call-decline: #DC2626;
    }
}

:root[data-theme="dark"] {
    --chitchat-bg: #0F0618;
    --chitchat-surface: #1A0B2E;
    --chitchat-surface-variant: #2E1A4A;
    --chitchat-surface-elevated: #24133D;
    --chitchat-border: #33224F;
    --chitchat-primary: #1A0B2E;
    --chitchat-on-primary: #FFFFFF;
    --chitchat-primary-deep: #A78BFA;
    --chitchat-secondary: #A78BFA;
    --chitchat-on-secondary: #0F0618;
    --chitchat-accent: #F472B6;
    --chitchat-on-accent: #0F0618;
    --chitchat-bubble-mine-bg: var(--chitchat-gradient-electric);
    --chitchat-bubble-mine-text: #FFFFFF;
    --chitchat-bubble-theirs-bg: #2E1A4A;
    --chitchat-bubble-theirs-text: #FFFFFF;
    --chitchat-bubble-theirs-border: #33224F;
    --chitchat-text-primary: #FFFFFF;
    --chitchat-text-secondary: #CBD5E1;
    --chitchat-text-tertiary: #94A3B8;
    --chitchat-success: #22C55E;
    --chitchat-warning: #F59E0B;
    --chitchat-error: #EF4444;
    --chitchat-info: #3B82F6;
    --chitchat-call-accept: #15803D;
    --chitchat-call-decline: #DC2626;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--chitchat-font-body);
    background: var(--chitchat-bg);
    color: var(--chitchat-text-primary);
}

h1, h2, h3, h4, h5, h6, .brand, .brand-logo-text {
    font-family: var(--chitchat-font-brand);
    font-weight: 600;
}

h1:focus {
    outline: none;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--chitchat-primary);
    color: var(--chitchat-on-primary);
}

.topbar .brand {
    font-weight: 600;
}

.topbar .me {
    margin-left: auto;
    opacity: 0.9;
    font-size: 0.9rem;
}

.topbar .link {
    background: none;
    border: none;
    color: var(--chitchat-on-primary);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Scan-to-link */
.link-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.link-card {
    width: 100%;
    max-width: 380px;
    background: var(--chitchat-surface);
    border: 1px solid var(--chitchat-border);
    border-radius: var(--chitchat-radius-lg);
    padding: 2rem;
    text-align: center;
}

.brand-logo {
    height: 32px;
    margin-bottom: 1rem;
}

.link-card h1 {
    margin: 0 0 0.5rem;
    color: var(--chitchat-primary-deep);
    font-size: 1.4rem;
}

.link-card .hint {
    color: var(--chitchat-text-secondary);
    font-size: 0.9rem;
}

.qr-frame {
    margin: 1.5rem auto 0;
    width: 240px;
    height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-frame svg {
    width: 100%;
    height: 100%;
}

.qr-expired {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

button.primary {
    padding: 0.6rem 1.2rem;
    background: var(--chitchat-gradient-electric);
    color: #FFFFFF;
    border: none;
    border-radius: var(--chitchat-radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter var(--chitchat-motion-short) var(--chitchat-motion-easing);
}

button.primary:hover:not(:disabled) {
    filter: brightness(1.06);
}

button.primary:disabled {
    opacity: 0.5;
    cursor: default;
}

.error {
    color: var(--chitchat-error);
    font-size: 0.9rem;
}

/* Chat list */
.chat-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-width: 640px;
    width: 100%;
    margin-inline: auto;
}

.chat-row {
    display: flex;
    gap: 0.75rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--chitchat-border);
    cursor: pointer;
    align-items: center;
}

.chat-row:hover {
    background: var(--chitchat-surface);
}

.chat-row.unread .name {
    font-weight: 700;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chitchat-primary);
    color: var(--chitchat-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-row-body {
    flex: 1;
    min-width: 0;
}

.chat-row-top {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.chat-row-top .time {
    color: var(--chitchat-text-secondary);
    font-size: 0.8rem;
}

.chat-row-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--chitchat-text-secondary);
    font-size: 0.85rem;
}

.preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chitchat-success);
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--chitchat-text-secondary);
}

.empty-state img {
    width: 160px;
    opacity: 0.8;
}

/* Single chat view */
.chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-width: 640px;
    width: 100%;
    margin-inline: auto;
}

.chat-view .back {
    padding: 0.6rem 1rem;
    text-align: left;
    background: none;
    border: none;
    color: var(--chitchat-primary-deep);
    cursor: pointer;
    align-self: flex-start;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.bubble-row {
    display: flex;
}

.bubble-row.mine {
    justify-content: flex-end;
}

.bubble {
    max-width: 75%;
    padding: 0.5rem 0.8rem;
    /* §6.6: 18px bubble radius with a 4px "tail" corner — bottom-left for a received bubble
       (this one), bottom-right for a sent one (.mine override below). */
    border-radius: var(--chitchat-radius-bubble) var(--chitchat-radius-bubble) var(--chitchat-radius-bubble) var(--chitchat-radius-bubble-tail);
    background: var(--chitchat-bubble-theirs-bg);
    color: var(--chitchat-bubble-theirs-text);
    border: 1px solid var(--chitchat-bubble-theirs-border);
}

.bubble-row.mine .bubble {
    border-radius: var(--chitchat-radius-bubble) var(--chitchat-radius-bubble) var(--chitchat-radius-bubble-tail) var(--chitchat-radius-bubble);
    background: var(--chitchat-bubble-mine-bg);
    color: var(--chitchat-bubble-mine-text);
    border: none;
}

.bubble .body {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble .meta {
    display: block;
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.15rem;
}

.bubble.typing {
    font-style: italic;
    opacity: 0.7;
}

.composer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--chitchat-border);
    background: var(--chitchat-surface);
}

.composer input {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--chitchat-border);
    border-radius: 20px;
    font-size: 1rem;
    background: var(--chitchat-surface);
    color: var(--chitchat-text-primary);
}

.composer .mic {
    background: none;
    border: 1px solid var(--chitchat-border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
    cursor: pointer;
}

.recording-indicator {
    color: var(--chitchat-error);
    font-weight: 600;
    flex: 1;
}

.voice-play {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    color: inherit;
}

.voice-label {
    font-size: 0.9rem;
    opacity: 0.85;
}

.bubble audio {
    display: block;
    margin-top: 0.4rem;
    max-width: 220px;
    height: 32px;
}

.chat-image {
    display: block;
    max-width: 260px;
    max-height: 260px;
    border-radius: 10px;
    object-fit: cover;
}

.bubble .body.deleted {
    font-style: italic;
    opacity: 0.7;
}

.bubble .meta .edited {
    font-style: italic;
}

/* §3.4 reactions — built from scratch (this client had none before). A hover/click equivalent of
   the Android picker's long-press: .reaction-trigger stays low-opacity until the bubble is
   hovered (desktop) or always effectively "visible enough" to tap on touch screens, since
   opacity:0 elements are still hit-testable. */
.bubble-wrap {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    max-width: 75%;
}

.bubble-row.mine .bubble-wrap {
    align-items: flex-end;
}

.reaction-trigger {
    align-self: flex-start;
    margin-top: 2px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity var(--chitchat-motion-short) var(--chitchat-motion-easing);
    padding: 2px 6px;
    border-radius: var(--chitchat-radius-full);
    color: var(--chitchat-text-secondary);
}

.bubble-row.mine .reaction-trigger {
    align-self: flex-end;
}

.bubble-wrap:hover .reaction-trigger,
.bubble-wrap:focus-within .reaction-trigger {
    opacity: 1;
}

.reaction-chips {
    display: flex;
    gap: 4px;
    margin-top: -8px;
    cursor: pointer;
}

.bubble-row.mine .reaction-chips {
    align-self: flex-end;
}

.reaction-chip {
    background: var(--chitchat-surface-elevated);
    border: 1px solid var(--chitchat-border);
    border-radius: var(--chitchat-radius-full);
    padding: 1px 7px;
    font-size: 0.8rem;
}

.reaction-chip.mine {
    background: var(--chitchat-secondary);
    color: var(--chitchat-on-secondary);
    border-color: var(--chitchat-secondary);
}

.picker-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 40;
}

.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    z-index: 41;
    display: flex;
    gap: 2px;
    background: var(--chitchat-surface-elevated);
    border-radius: var(--chitchat-radius-full);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    padding: 6px;
    margin-bottom: 6px;
    animation: reactionPickerIn var(--chitchat-motion-medium) var(--chitchat-motion-easing);
}

.bubble-row.mine .reaction-picker {
    left: auto;
    right: 0;
}

@media (prefers-reduced-motion: reduce) {
    .reaction-picker {
        animation: none;
    }
}

@keyframes reactionPickerIn {
    from { opacity: 0; transform: scale(0.85) translateY(6px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.reaction-option {
    border: none;
    background: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--chitchat-motion-short) var(--chitchat-motion-easing);
}

.reaction-option:hover {
    transform: scale(1.3);
}

.reaction-option.mine {
    background: var(--chitchat-surface-variant);
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2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TE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }
