/* ==========================================================================
   💬 KOMUNIKACE MODULE — RADIM chat shell v2.1 (Sprint V.4)
   Sprint V.4: realigned with Radim gold palette + full dark mode
   Was: teal var(--radim-primary) primary → now: Radim gold #c8a877 (matches ChatModule)
   ========================================================================== */

:root {
    /* Background & surfaces — warm cream paper (matches Konverzace) */
    --radim-bg:           #fbf7ef;
    --radim-surface:      #ffffff;
    --radim-surface-soft: #f5f1e8;
    --radim-panel:        #faf4e4;
    --radim-panel-2:      #f5ead1;

    /* Brand — now Radim gold, not teal */
    --radim-primary:       #c8a877;     /* was var(--radim-primary) */
    --radim-primary-hover: #b89964;     /* was var(--radim-primary) */
    --radim-primary-soft:  #f5e6c3;     /* was #dff3ef */
    --radim-primary-deep:  #8a6b20;     /* was var(--radim-primary) */

    /* Accent (gold emphasis) */
    --radim-accent:      #e8c87a;
    --radim-accent-soft: #fff4d3;
    --radim-accent-deep: #a07a1c;

    /* Text */
    --radim-text:       #1a2530;
    --radim-text-soft:  #5a6772;
    --radim-text-muted: #8090a0;

    /* Borders */
    --radim-border:         rgba(26, 37, 48, 0.09);
    --radim-border-strong:  rgba(26, 37, 48, 0.18);

    /* Semantic */
    --radim-success: #6ba368;
    --radim-warning: #d9a84f;
    --radim-danger:  #c6503a;

    /* Role tints — family stays warm, AI is the gold */
    --radim-role-family:  #c8a877;     /* gold — was teal */
    --radim-role-ai:      #8a6b20;     /* deep gold */
    --radim-role-medical: #6aa7c8;     /* steel blue (unchanged, distinct) */

    /* Shadows — subtler than before, WhatsApp-style layered */
    --radim-shadow-sm: 0 1px 2px rgba(20, 30, 40, 0.05), 0 1px 3px rgba(20, 30, 40, 0.06);
    --radim-shadow-md: 0 2px 4px rgba(20, 30, 40, 0.05), 0 4px 12px rgba(20, 30, 40, 0.08);
    --radim-shadow-lg: 0 6px 16px rgba(20, 30, 40, 0.10), 0 12px 32px rgba(20, 30, 40, 0.06);
    --radim-shadow-gold: 0 4px 16px rgba(200, 168, 119, 0.25);

    /* Radii */
    --radim-radius-sm: 10px;
    --radim-radius-md: 16px;
    --radim-radius-lg: 22px;
    --radim-radius-xl: 28px;

    /* Bubble-specific (WhatsApp idiom) */
    --radim-bubble-radim:     #ffffff;
    --radim-bubble-radim-ink: #1a2530;
    --radim-bubble-user:      #f5e6c3;      /* our WhatsApp "green" = gold cream */
    --radim-bubble-user-ink:  #3a2f16;

    /* Layout */
    --chat-width-list:   360px;
    --chat-input-height: 64px;
    --chat-header-height: 72px;

    /* Motion */
    --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-med:  220ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 420ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Typography */
    --radim-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text",
                  Roboto, "Helvetica Neue", Arial, sans-serif;
    --radim-font-serif: Georgia, "Libre Baskerville", "PT Serif", serif;

    /* Chat wallpaper — subtle gold dot pattern (matches Konverzace) */
    --radim-wallpaper-dot: color-mix(in srgb, var(--radim-primary) 22%, transparent);

    /* Legacy --km-* aliases (backwards compatibility while we migrate) */
    --km-accent:      var(--radim-primary);
    --km-accent-deep: var(--radim-primary-deep);
    --km-accent-soft: var(--radim-primary-soft);
    --km-ink:         var(--radim-text);
    --km-ink-mute:    var(--radim-text-soft);
    --km-surface:     var(--radim-surface);
    --km-parchment:   var(--radim-panel);
    --km-border:      var(--radim-border);
}

/* ══════════════════════════════════════════════════════════════════
   DARK MODE — Sprint V.8: MANUAL ONLY (no more auto-from-OS)
   User must explicitly opt in via Konverzace settings → data-theme="dark".
   OS dark mode NO LONGER auto-switches the app. Senior-friendly default.
   ══════════════════════════════════════════════════════════════════ */
/* @media (prefers-color-scheme: dark) AUTO BLOCK REMOVED in V.8
   Was causing entire app to go dark when OS was dark — confused seniors.
   Dark mode is now opt-in only via data-theme attribute below. */

/* Manual dark override (via Konverzace settings → sets data-theme on html) */
[data-theme="dark"] {
    --radim-bg:           #0c1318;
    --radim-surface:      #1a2530;
    --radim-surface-soft: #243140;
    --radim-panel:        #1a2530;
    --radim-panel-2:      #243140;

    --radim-primary:       #d8b887;
    --radim-primary-hover: #e8c89a;
    --radim-primary-soft:  #4a3d24;
    --radim-primary-deep:  #f0d49b;

    --radim-accent:      #e8c87a;
    --radim-accent-soft: #4a3d24;
    --radim-accent-deep: #f0d49b;

    --radim-text:       #e8eef3;
    --radim-text-soft:  #a8b4c0;
    --radim-text-muted: #758390;

    --radim-border:        rgba(232, 238, 243, 0.10);
    --radim-border-strong: rgba(232, 238, 243, 0.22);

    --radim-shadow-sm: 0 1px 1px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.2);
    --radim-shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3),  0 4px 12px rgba(0, 0, 0, 0.25);
    --radim-shadow-lg: 0 6px 16px rgba(0, 0, 0, 0.4),  0 12px 32px rgba(0, 0, 0, 0.28);

    --radim-bubble-radim:     #1f2a35;
    --radim-bubble-radim-ink: #e8eef3;
    --radim-bubble-user:      #4a3d24;
    --radim-bubble-user-ink:  #f5e6c3;

    --radim-wallpaper-dot: color-mix(in srgb, var(--radim-primary) 10%, transparent);
}

/* ==========================================================================
   Shell — two-panel layout (desktop default, mobile slides between)
   ========================================================================== */

.chat-shell {
    display: grid;
    grid-template-columns: var(--chat-width-list) 1fr;
    gap: 1px;
    background: var(--radim-border);
    border: 1px solid var(--radim-border);
    border-radius: var(--radim-radius-lg);
    box-shadow: var(--radim-shadow-sm);
    overflow: hidden;
    height: calc(100dvh - 170px);
    min-height: 620px;
    max-height: 920px;
    font-family: var(--radim-font);
    color: var(--radim-text);
    font-size: 16px;
    line-height: 1.5;
    width: 100%;
    box-sizing: border-box;
}

/* Neutralize outer module-section styling so the shell fills edge-to-edge */
#module-komunikace {
    padding: 4px !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    max-width: none !important;
}

#module-komunikace #communicationModuleContent {
    padding: 0 !important;
    margin: 0 !important;
}

@media (prefers-reduced-motion: reduce) {
    .chat-shell,
    .chat-shell * { animation: none !important; transition: none !important; }
}

/* ==========================================================================
   List panel (left)
   ========================================================================== */

.chat-list-panel {
    display: flex;
    flex-direction: column;
    background: var(--radim-panel);
    min-width: 0;
    overflow: hidden;
}

.chat-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: var(--radim-surface);
    border-bottom: 1px solid var(--radim-border);
}

.chat-list-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-list-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 18%;
    background: var(--radim-primary-soft);
    border: 2px solid var(--radim-accent);
    flex-shrink: 0;
}

.chat-list-header h2 {
    font-family: var(--radim-font-serif);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--radim-primary-deep);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Icon button — generic (44×44 tap target) */
.chat-icon-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--radim-text-soft);
    font-size: 1.2rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
    position: relative;
    font-family: inherit;
}

.chat-icon-button:hover {
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
}

.chat-icon-button:focus-visible {
    outline: 3px solid var(--radim-primary);
    outline-offset: 2px;
    background: var(--radim-primary-soft);
}

.chat-icon-button:active {
    transform: scale(0.94);
}

.chat-icon-button--primary {
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    box-shadow: 0 3px 10px color-mix(in srgb, var(--radim-primary) 35%, transparent);
}

.chat-icon-button--primary:hover,
.chat-icon-button--primary:focus-visible {
    background: linear-gradient(135deg, var(--radim-primary-hover) 0%, var(--radim-primary-deep) 100%);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px color-mix(in srgb, var(--radim-primary) 45%, transparent);
}

.chat-icon-button--danger {
    color: var(--radim-danger);
}

.chat-icon-button--danger:hover {
    background: rgba(217, 107, 107, 0.08);
}

/* Voice mega button in list header */
.chat-voice-hero {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 10px 12px 4px;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-deep) 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 600;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--radim-primary) 32%, transparent);
    transition: transform var(--transition-fast), box-shadow var(--transition-med);
    min-height: 48px;
}

.chat-voice-hero:hover,
.chat-voice-hero:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px color-mix(in srgb, var(--radim-primary) 42%, transparent);
    outline: none;
}

.chat-voice-hero .chat-voice-icon {
    font-size: 1.35rem;
    line-height: 1;
}

/* Search bar */
.chat-search {
    position: relative;
    margin: 12px;
    display: flex;
    align-items: center;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 999px;
    padding: 4px 6px 4px 12px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-search:focus-within {
    border-color: var(--radim-primary);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
}

.chat-search-icon {
    font-size: 1rem;
    opacity: 0.55;
    margin-right: 6px;
    line-height: 1;
}

.chat-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.98rem;
    color: var(--radim-text);
    padding: 9px 4px;
    outline: none;
    min-height: 38px;
}

.chat-search-input::placeholder { color: var(--radim-text-muted); }

.chat-search-clear {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.chat-search-clear:hover {
    background: var(--radim-primary);
    color: #fff;
}

/* Filters — horizontal with fade-mask edges to hint at overflow */
.chat-filters-wrap {
    position: relative;
    padding-bottom: 10px;
    flex-shrink: 0;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
            mask-image: linear-gradient(to right, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}

.chat-filters {
    display: flex;
    gap: 6px;
    padding: 0 12px 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.chat-filters::-webkit-scrollbar { display: none; }

.chat-filter-chip {
    border: 1px solid var(--radim-border);
    background: var(--radim-surface);
    color: var(--radim-text-soft);
    padding: 7px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
}

.chat-filter-chip:hover {
    background: var(--radim-primary-soft);
    border-color: var(--radim-primary);
    color: var(--radim-primary-deep);
}

.chat-filter-chip:focus-visible {
    outline: 3px solid var(--radim-primary);
    outline-offset: 2px;
}

.chat-filter-chip--active {
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 3px 10px color-mix(in srgb, var(--radim-primary) 25%, transparent);
}

.chat-filter-chip--active:hover {
    background: linear-gradient(135deg, var(--radim-primary-hover) 0%, var(--radim-primary-deep) 100%);
    color: #fff;
}

.chat-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    font-size: 0.75rem;
    font-weight: 700;
}

.chat-filter-chip--active .chat-filter-count {
    background: rgba(255, 255, 255, 0.24);
    color: #fff;
}

.chat-filter-count--hot {
    background: var(--radim-danger);
    color: #fff;
}

/* Conversation list (scrollable) */
.chat-conversation-list {
    list-style: none;
    margin: 0;
    padding: 4px 8px 16px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    scrollbar-color: var(--radim-border-strong) transparent;
    scrollbar-width: thin;
}

.chat-conversation-list::-webkit-scrollbar { width: 6px; }
.chat-conversation-list::-webkit-scrollbar-thumb { background: var(--radim-border-strong); border-radius: 999px; }

/* Conversation card */
.chat-conversation-card {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 11px 12px;
    border-radius: var(--radim-radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    margin-bottom: 2px;
    border: 1px solid transparent;
    min-height: 68px;
}

.chat-conversation-card:hover {
    background: var(--radim-surface);
}

.chat-conversation-card:focus-visible {
    outline: 3px solid var(--radim-primary);
    outline-offset: -3px;
}

.chat-conversation-card--active {
    background: var(--radim-surface);
    border-color: var(--radim-primary-soft);
    box-shadow: inset 3px 0 0 var(--radim-primary), var(--radim-shadow-sm);
}

.chat-conversation-card--unread {
    /* left slim accent bar for unread */
}

.chat-conversation-card--unread .chat-contact-name {
    font-weight: 700;
    color: var(--radim-text);
}

.chat-conversation-card--unread .chat-last-message {
    color: var(--radim-text);
    font-weight: 500;
}

.chat-conversation-card--pinned::before {
    content: '📌';
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.7rem;
    opacity: 0.6;
}

.chat-conversation-card--muted .chat-last-message {
    opacity: 0.6;
}

/* Avatar */
.chat-avatar {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--radim-font-serif);
    font-weight: 700;
    font-size: 1.3rem;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 18%;
}

.chat-avatar--sm { width: 40px; height: 40px; font-size: 1rem; }
.chat-avatar--lg { width: 72px; height: 72px; font-size: 1.8rem; }
.chat-avatar--xl { width: 96px; height: 96px; font-size: 2.4rem; }

/* Avatar role rings */
.chat-avatar--ai {
    box-shadow: 0 0 0 2.5px var(--radim-accent);
}
.chat-avatar--family {
    /* default primary — no extra ring */
}
.chat-avatar--medical {
    box-shadow: 0 0 0 2.5px var(--radim-role-medical);
}

/* Avatar status dot (online / away / offline) */
.chat-avatar-status {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2.5px solid var(--radim-surface);
    background: var(--radim-text-muted);
}

.chat-avatar-status--online {
    background: var(--radim-success);
    animation: chat-online-pulse 2.4s ease-in-out infinite;
}

.chat-avatar-status--away {
    background: var(--radim-warning);
}

@keyframes chat-online-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 125, 0.45); }
    50%      { box-shadow: 0 0 0 5px rgba(76, 175, 125, 0); }
}

.chat-conversation-card--active .chat-avatar-status {
    border-color: var(--radim-surface);
}

/* Conversation body */
.chat-conversation-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.chat-conversation-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-contact-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--radim-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-meta {
    font-size: 0.82rem;
    color: var(--radim-text-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.chat-conversation-card--unread .chat-meta {
    color: var(--radim-primary-deep);
    font-weight: 600;
}

.chat-last-message {
    font-size: 0.92rem;
    color: var(--radim-text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.chat-last-message-icon {
    font-size: 0.85em;
    margin-right: 2px;
    opacity: 0.7;
}

/* Unread badge */
.chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--radim-primary);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-conversation-card--urgent .chat-unread-badge {
    background: var(--radim-danger);
    animation: chat-urgent-pulse 1.8s ease-in-out infinite;
}

@keyframes chat-urgent-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 107, 107, 0.4); }
    50%      { box-shadow: 0 0 0 5px rgba(217, 107, 107, 0); }
}

/* Right-side action cluster (call buttons on hover) */
.chat-conversation-card {
    position: relative;
}

.chat-conversation-actions {
    display: inline-flex;
    gap: 4px;
    opacity: 0;
    transform: translateX(4px);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    flex-shrink: 0;
}

.chat-conversation-card:hover .chat-conversation-actions,
.chat-conversation-card:focus-within .chat-conversation-actions {
    opacity: 1;
    transform: translateX(0);
}

.chat-conversation-actions .chat-icon-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    font-size: 0.95rem;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
}

.chat-conversation-actions .chat-icon-button:hover {
    background: var(--radim-primary);
    color: #fff;
}

/* ==========================================================================
   Chat panel (right)
   ========================================================================== */

.chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--radim-surface);
    min-width: 0;
    overflow: hidden;
    position: relative;
}

/* ─── Empty state (no conversation open) ─────────────────────── */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    background:
        radial-gradient(ellipse 60% 50% at 30% 20%, var(--radim-primary-soft) 0%, transparent 60%),
        radial-gradient(ellipse 55% 45% at 70% 80%, var(--radim-accent-soft) 0%, transparent 60%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'><g fill='%23c8a877' fill-opacity='0.035'><circle cx='50' cy='50' r='1.2'/><circle cx='150' cy='50' r='1.2'/><circle cx='100' cy='100' r='1.2'/><circle cx='50' cy='150' r='1.2'/><circle cx='150' cy='150' r='1.2'/></g></svg>"),
        var(--radim-surface);
    background-size: auto, auto, 200px 200px, auto;
    animation: chat-empty-in 0.45s ease-out;
}

@keyframes chat-empty-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-empty-state-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 18%;
    border: 3px solid var(--radim-accent);
    box-shadow: var(--radim-shadow-md);
    margin-bottom: 18px;
    background: var(--radim-surface);
    position: relative;
}

/* Subtle pulse ring around avatar */
.chat-empty-state-avatar-wrap {
    position: relative;
    margin-bottom: 18px;
}

.chat-empty-state-avatar-wrap::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--radim-accent);
    opacity: 0.35;
    animation: chat-empty-pulse 2.6s ease-in-out infinite;
    pointer-events: none;
}

@keyframes chat-empty-pulse {
    0%, 100% { transform: scale(1);    opacity: 0.35; }
    50%      { transform: scale(1.08); opacity: 0.05; }
}

.chat-empty-state-avatar-wrap .chat-empty-state-avatar {
    margin-bottom: 0;
}

.chat-empty-state h2 {
    font-family: var(--radim-font-serif);
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--radim-primary-deep);
    margin: 0 0 8px;
    max-width: 500px;
}

.chat-empty-state p {
    font-size: 1rem;
    color: var(--radim-text-soft);
    line-height: 1.55;
    margin: 0 auto 20px;
    max-width: 440px;
}

.chat-empty-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    max-width: 620px;
}

.chat-primary-action {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 22px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--radim-primary) 35%, transparent);
    transition: transform var(--transition-fast), box-shadow var(--transition-med);
    min-height: 52px;
}

.chat-primary-action:hover,
.chat-primary-action:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px color-mix(in srgb, var(--radim-primary) 45%, transparent);
    outline: none;
}

.chat-secondary-action {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: 999px;
    border: 2px solid var(--radim-border-strong);
    background: var(--radim-surface);
    color: var(--radim-text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    min-height: 52px;
}

.chat-secondary-action:hover,
.chat-secondary-action:focus-visible {
    border-color: var(--radim-primary);
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    outline: none;
}

.chat-empty-tagline {
    margin-top: 24px;
    font-size: 0.92rem;
    color: var(--radim-text-muted);
    font-style: italic;
    max-width: 520px;
}

/* ─── Chat header ────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--radim-surface);
    border-bottom: 1px solid var(--radim-border);
    min-height: var(--chat-header-height);
    box-sizing: border-box;
    flex-shrink: 0;
}

.chat-back-button {
    display: none; /* mobile only */
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    border: none;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    font-size: 1.3rem;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    font-family: inherit;
}

.chat-back-button:hover {
    background: var(--radim-primary);
    color: #fff;
    transform: translateX(-2px);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-header-info .chat-contact-name {
    font-family: var(--radim-font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--radim-text);
}

.chat-contact-status {
    font-size: 0.85rem;
    color: var(--radim-text-muted);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.chat-contact-status--online {
    color: var(--radim-success);
    font-weight: 600;
}

.chat-contact-status--typing {
    color: var(--radim-primary);
    font-weight: 600;
    font-style: italic;
}

.chat-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* ─── Messages area ──────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* Sprint V.4: gold-cream paper with subtle gold dot wallpaper (matches Konverzace) */
    background:
        radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--radim-primary) 6%, transparent) 0%, transparent 45%),
        radial-gradient(circle at 88% 82%, color-mix(in srgb, var(--radim-accent) 5%, transparent) 0%, transparent 50%),
        radial-gradient(circle at 1px 1px, var(--radim-wallpaper-dot) 1px, transparent 1.5px) 0 0 / 22px 22px,
        var(--radim-bg);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-color: var(--radim-border-strong) transparent;
    scrollbar-width: thin;
}

.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--radim-border-strong); border-radius: 999px; }

/* Date divider */
.chat-date-divider {
    align-self: center;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--radim-text-soft);
    letter-spacing: 0.3px;
    margin: 14px 0 8px;
    border: 1px solid var(--radim-border);
}

/* Message row (for avatar alignment, optional grouping) */
.chat-message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 2px 0;
    max-width: 72%;
    animation: chat-msg-in 0.18s ease-out;
}

.chat-message-row--outgoing {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message-row--incoming {
    align-self: flex-start;
}

.chat-message-row--grouped { margin-top: -4px; }

@keyframes chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Small avatar at message row (incoming only, first of group) */
.chat-message-avatar-slot {
    width: 32px;
    flex-shrink: 0;
    align-self: flex-end;
}

.chat-message-avatar-slot .chat-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
}

.chat-message-row--grouped .chat-message-avatar-slot .chat-avatar {
    visibility: hidden;
}

/* Bubble */
.chat-message-bubble {
    display: inline-flex;
    flex-direction: column;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 1.05rem;
    line-height: 1.45;
    color: var(--radim-text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: var(--radim-shadow-sm);
    min-width: 80px;
    max-width: 100%;
    position: relative;
    transition: opacity var(--transition-fast);
}

.chat-message-bubble--incoming {
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-bottom-left-radius: 6px;
}

/* Incoming bubble tail (only on first-of-group) */
.chat-message-row--incoming:not(.chat-message-row--grouped) .chat-message-bubble--incoming::before {
    content: '';
    position: absolute;
    left: -6px;
    bottom: 0;
    width: 14px;
    height: 14px;
    background: var(--radim-surface);
    border-left: 1px solid var(--radim-border);
    border-bottom: 1px solid var(--radim-border);
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    border-bottom-left-radius: 3px;
}

.chat-message-row--grouped .chat-message-bubble--incoming {
    border-top-left-radius: 6px;
}

.chat-message-bubble--outgoing {
    /* Sprint V.4: WhatsApp idiom × Radim gold */
    background: var(--radim-bubble-user);
    border: 1px solid color-mix(in srgb, var(--radim-primary) 30%, transparent);
    border-bottom-right-radius: 6px;
    color: var(--radim-bubble-user-ink);
}

/* Outgoing bubble tail */
.chat-message-row--outgoing:not(.chat-message-row--grouped) .chat-message-bubble--outgoing::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: 0;
    width: 14px;
    height: 14px;
    background: var(--radim-bubble-user);
    border-right: 1px solid color-mix(in srgb, var(--radim-primary) 30%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--radim-primary) 30%, transparent);
    clip-path: polygon(0 0, 0 100%, 100% 100%);
    border-bottom-right-radius: 3px;
}

.chat-message-row--grouped .chat-message-bubble--outgoing {
    border-top-right-radius: 6px;
}

/* AI bubble tail */
.chat-message-row--incoming:not(.chat-message-row--grouped) .chat-message-bubble--ai::before {
    background: #fbe8b7;
    border-left-color: rgba(244, 201, 93, 0.55);
    border-bottom-color: rgba(244, 201, 93, 0.55);
}

/* URL / link styling in bubbles */
.chat-message-content a {
    color: var(--radim-primary-deep);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    word-break: break-all;
}

.chat-message-bubble--outgoing .chat-message-content a {
    color: #0d4f48;
}

.chat-message-content a:hover { text-decoration-thickness: 2px; }

/* AI bubble variant (Radim) */
.chat-message-bubble--ai {
    background: linear-gradient(135deg, var(--radim-accent-soft) 0%, #fbe8b7 100%);
    border: 1px solid rgba(244, 201, 93, 0.55);
    color: #5a3f08;
}

/* System message */
.chat-message-bubble--system {
    align-self: center;
    max-width: 80%;
    background: rgba(255, 255, 255, 0.78);
    border: 1px dashed var(--radim-border-strong);
    border-radius: 14px;
    padding: 8px 14px;
    font-size: 0.88rem;
    color: var(--radim-text-soft);
    font-style: italic;
    text-align: center;
    margin: 10px auto;
}

.chat-message-bubble--system::before {
    content: '✨ ';
    opacity: 0.8;
}

/* Failed / sending states */
.chat-message-bubble--failed {
    background: rgba(217, 107, 107, 0.08);
    border-color: var(--radim-danger);
    color: #6e1c1c;
}

.chat-message-bubble--sending {
    opacity: 0.6;
}

.chat-message-bubble--highlighted {
    animation: chat-bubble-flash 1.6s ease-out;
}

@keyframes chat-bubble-flash {
    0%   { box-shadow: 0 0 0 0 rgba(244, 201, 93, 0); }
    30%  { box-shadow: 0 0 0 6px rgba(244, 201, 93, 0.45); }
    100% { box-shadow: 0 0 0 0 rgba(244, 201, 93, 0); }
}

/* Message meta (time + status) */
.chat-message-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-size: 0.75rem;
    color: var(--radim-text-muted);
    align-self: flex-end;
}

.chat-message-bubble--incoming .chat-message-meta {
    align-self: flex-start;
}

.chat-message-status {
    font-weight: 700;
    letter-spacing: -1px;
    color: var(--radim-text-muted);
}

.chat-message-status--read {
    color: var(--radim-primary);
}

.chat-message-status--failed {
    color: var(--radim-danger);
    font-style: normal;
    font-weight: 600;
    font-size: 0.72rem;
}

/* Voice message bubble */
.chat-voice-bubble {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    min-width: 190px;
    max-width: 320px;
}

.chat-voice-play {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    border: none;
    background: var(--radim-primary);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: transform var(--transition-fast);
}

.chat-voice-play:hover { transform: scale(1.05); }

.chat-voice-waveform {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 2px;
}

.chat-voice-waveform span {
    flex: 1;
    background: var(--radim-primary-deep);
    border-radius: 2px;
    opacity: 0.45;
}

.chat-voice-waveform span:nth-child(1) { height: 40%; }
.chat-voice-waveform span:nth-child(2) { height: 60%; }
.chat-voice-waveform span:nth-child(3) { height: 85%; }
.chat-voice-waveform span:nth-child(4) { height: 70%; }
.chat-voice-waveform span:nth-child(5) { height: 50%; }
.chat-voice-waveform span:nth-child(6) { height: 75%; }
.chat-voice-waveform span:nth-child(7) { height: 60%; }
.chat-voice-waveform span:nth-child(8) { height: 90%; }
.chat-voice-waveform span:nth-child(9) { height: 55%; }
.chat-voice-waveform span:nth-child(10) { height: 45%; }

.chat-voice-duration {
    font-size: 0.78rem;
    color: var(--radim-text-soft);
    font-variant-numeric: tabular-nums;
}

/* Attachment card */
.chat-attachment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 14px;
    min-width: 220px;
    max-width: 340px;
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-med);
}

.chat-attachment-card:hover {
    border-color: var(--radim-primary);
    box-shadow: var(--radim-shadow-sm);
}

.chat-attachment-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.chat-attachment-info {
    min-width: 0;
    flex: 1;
}

.chat-attachment-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--radim-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attachment-size {
    font-size: 0.8rem;
    color: var(--radim-text-muted);
}

/* Typing indicator */
.chat-typing-indicator {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    margin: 4px 0;
    font-size: 0.85rem;
    color: var(--radim-text-soft);
    animation: chat-msg-in 0.2s ease-out;
}

.chat-typing-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}

.chat-typing-dots span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--radim-primary);
    animation: chat-typing-bounce 1.2s infinite ease-in-out both;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.55; }
    40%           { transform: scale(1);    opacity: 1;    }
}

/* ─── Composer (bottom input) ────────────────────────────────── */
.chat-composer {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: end;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--radim-surface);
    border-top: 1px solid var(--radim-border);
    flex-shrink: 0;
    position: relative;
}

.chat-composer-actions {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 48px;
}

.chat-composer-input {
    width: 100%;
    min-height: 48px;
    max-height: 140px;
    padding: 13px 18px;
    border: 1.5px solid var(--radim-border);
    border-radius: 24px;
    font-family: inherit;
    font-size: 1.05rem;
    line-height: 1.4;
    background: var(--radim-surface-soft);
    color: var(--radim-text);
    resize: none;
    transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
    box-sizing: border-box;
    outline: none;
}

.chat-composer-input::placeholder { color: var(--radim-text-muted); }

.chat-composer-input:focus {
    border-color: var(--radim-primary);
    background: var(--radim-surface);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
}

.chat-composer-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-composer--recording .chat-composer-input {
    border-color: var(--radim-danger);
    background: rgba(217, 107, 107, 0.06);
}

.chat-composer--sending .chat-send-button {
    opacity: 0.6;
    pointer-events: none;
}

.chat-send-button {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-med);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--radim-primary) 35%, transparent);
    font-family: inherit;
}

.chat-send-button:hover,
.chat-send-button:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--radim-primary) 50%, transparent);
    outline: none;
}

.chat-send-button:active { transform: scale(0.94); }

.chat-composer-actions .chat-icon-button {
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
}

.chat-composer-actions .chat-icon-button:hover {
    background: var(--radim-primary);
    color: #fff;
}

/* Emoji / attachment panel (slides up) */
.chat-emoji-panel {
    position: absolute;
    left: 0; right: 0; bottom: 100%;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    padding: 12px 14px;
    background: var(--radim-surface);
    border-top: 1px solid var(--radim-border);
    max-height: 200px;
    overflow-y: auto;
    animation: chat-panel-in 0.18s ease-out;
    z-index: 3;
}

.chat-emoji-panel.hidden { display: none; }

@keyframes chat-panel-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-emoji-item {
    aspect-ratio: 1;
    min-height: 38px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background var(--transition-fast), transform var(--transition-fast);
    line-height: 1;
}

.chat-emoji-item:hover,
.chat-emoji-item:focus-visible {
    background: var(--radim-primary-soft);
    transform: scale(1.2);
    outline: none;
}

/* ==========================================================================
   Scroll shadow + context menu + keyboard hint
   ========================================================================== */

/* Scroll-shadow at top of messages when scrolled down */
.chat-messages.chat-messages--scrolled {
    box-shadow: inset 0 8px 16px -8px rgba(31, 52, 46, 0.15);
}

/* Context menu on message bubble (copy, delete, reply placeholder) */
.chat-context-menu {
    position: fixed;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 12px;
    box-shadow: var(--radim-shadow-lg);
    padding: 6px;
    min-width: 180px;
    z-index: 9400;
    animation: chat-context-in 0.12s ease-out;
}

@keyframes chat-context-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

.chat-context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--radim-text);
    cursor: pointer;
    border-radius: 8px;
    text-align: left;
    transition: background var(--transition-fast);
}

.chat-context-item:hover,
.chat-context-item:focus-visible {
    background: var(--radim-primary-soft);
    outline: none;
}

.chat-context-item--danger { color: var(--radim-danger); }
.chat-context-item--danger:hover { background: rgba(217, 107, 107, 0.08); }

.chat-context-item-icon {
    font-size: 1rem;
    width: 22px;
    text-align: center;
    opacity: 0.85;
}

/* Keyboard shortcut hint on search */
.chat-search-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    margin-right: 4px;
    font-family: var(--radim-font);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--radim-text-muted);
    background: var(--radim-surface-soft);
    border: 1px solid var(--radim-border);
    border-radius: 6px;
    user-select: none;
    letter-spacing: 0.3px;
}

/* Bubble selection state (when context menu is open) */
.chat-message-bubble--selected {
    box-shadow: 0 0 0 2px var(--radim-accent), var(--radim-shadow-md);
}

/* ==========================================================================
   Skeleton loaders
   ========================================================================== */

.chat-skeleton {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 12px;
    padding: 11px 12px;
    align-items: center;
    margin-bottom: 2px;
    border-radius: var(--radim-radius-md);
}

.chat-skeleton-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(90deg, var(--radim-panel-2) 0%, var(--radim-border) 50%, var(--radim-panel-2) 100%);
    background-size: 200% 100%;
    animation: chat-skeleton-shimmer 1.4s linear infinite;
}

.chat-skeleton-lines { display: flex; flex-direction: column; gap: 6px; }

.chat-skeleton-line {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--radim-panel-2) 0%, var(--radim-border) 50%, var(--radim-panel-2) 100%);
    background-size: 200% 100%;
    animation: chat-skeleton-shimmer 1.4s linear infinite;
}

.chat-skeleton-line--long  { width: 180px; }
.chat-skeleton-line--short { width: 100px; height: 8px; }

@keyframes chat-skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   Toast
   ========================================================================== */

.chat-toast {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    padding: 13px 22px;
    background: var(--radim-text);
    color: #fff;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: var(--radim-shadow-lg);
    z-index: 9300;
    max-width: 90vw;
    animation: chat-toast-in 0.22s ease-out;
}

.chat-toast--success { background: var(--radim-primary-deep); }
.chat-toast--warning { background: #8a5a10; }
.chat-toast--danger  { background: var(--radim-danger); }

@keyframes chat-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================================================
   Empty states inside panels (no match, no conversations yet)
   ========================================================================== */

.chat-list-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--radim-text-muted);
}

.chat-list-empty-icon {
    font-size: 2.4rem;
    margin-bottom: 10px;
    opacity: 0.75;
}

.chat-list-empty p { margin: 4px 0; font-size: 0.95rem; }

.chat-list-empty .chat-secondary-action {
    margin-top: 12px;
    font-size: 0.95rem;
    padding: 10px 16px;
    min-height: 44px;
}

/* Demo watermark (when showing demo conversations) */
.chat-conversation-card--demo {
    opacity: 0.78;
}

.chat-conversation-card--demo::after {
    content: 'Ukázka';
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 0.65rem;
    background: var(--radim-accent-soft);
    color: var(--radim-accent-deep);
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1280px) {
    :root { --chat-width-list: 320px; }
    .chat-shell { height: calc(100dvh - 160px); }
}

@media (max-width: 1024px) {
    :root { --chat-width-list: 300px; }
    .chat-list-header h2 { font-size: 1.2rem; }
    .chat-empty-state h2 { font-size: 1.5rem; }
}

@media (max-width: 768px) {
    .chat-shell {
        grid-template-columns: 1fr;
        /* svh = small viewport height (excludes Safari URL bar). Subtract
           the actual top bar + bottom nav chrome (~180px combined). dvh is
           a fallback when svh isn't supported (older iOS). */
        height: calc(100svh - 180px);
        height: calc(100dvh - 180px);
        min-height: 480px;          /* never collapse below readable */
        border-radius: var(--radim-radius-md);
        margin: 0;
        max-width: 100%;
        position: relative;          /* anchor for sticky composer */
    }
    /* Mobile: show list OR chat via data-attr */
    .chat-shell[data-mobile-view="list"] .chat-panel { display: none; }
    .chat-shell[data-mobile-view="chat"] .chat-list-panel { display: none; }
    .chat-back-button { display: inline-flex; }

    /* Mobile chat panel: column layout with composer ALWAYS visible at bottom */
    .chat-panel {
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
    }
    .chat-messages {
        padding: 14px 12px 8px;
        flex: 1 1 auto;
        min-height: 0;               /* allow shrink so composer fits */
        overflow-y: auto;
    }
    .chat-message-row { max-width: 85%; }
    .chat-emoji-panel { grid-template-columns: repeat(7, 1fr); }
    .chat-header {
        padding: 10px 14px;
        flex-shrink: 0;              /* always visible */
    }

    /* Composer: pinned at bottom of panel, always visible above keyboard.
       sticky avoids breaking out of overflow:hidden parent. */
    .chat-composer {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
        position: sticky;
        bottom: 0;
        z-index: 5;
        flex-shrink: 0;
        background: var(--radim-surface);
        box-shadow: 0 -2px 8px color-mix(in srgb, var(--radim-text) 6%, transparent);
        /* Mobile-fix: zmenšíme gap aby input dostal víc místa */
        gap: 6px;
    }
    /* Mobile-fix: input je teď VÝRAZNĚ větší — 56px výšky, font 17px,
       padding 16px. Senior musí vidět co píše. */
    .chat-composer-input {
        min-height: 56px;
        max-height: 120px;
        font-size: 17px;             /* iOS: prevent zoom on focus (≥16px) */
        padding: 16px 18px;
        line-height: 1.4;
    }
    .chat-composer-actions .chat-icon-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    .chat-send-button {
        min-width: 48px;
        height: 48px;
    }
    /* Mobile-fix: 7 tlačítek + input se na 360px-414px obrazovku nevejdou.
       Skryjeme zbytné akce (Radimovy návrhy, diktování), nechaj jen
       attachment + emoji vlevo a record + send vpravo. Skryté akce jsou
       k dispozici v širším browseru / tabletu. */
    .chat-composer button[aria-label="Radim navrhne odpověď"],
    .chat-composer button[aria-label="Diktovat"] {
        display: none;
    }

    .chat-list-header-actions .chat-icon-button { width: 40px; height: 40px; min-width: 40px; }
    .chat-empty-state { padding: 30px 18px; }
    .chat-empty-state-avatar { width: 96px; height: 96px; }
    .chat-empty-state h2 { font-size: 1.35rem; }
    .chat-empty-state p { font-size: 0.98rem; }
}

@media (max-width: 560px) {
    .chat-conversation-card {
        grid-template-columns: 48px 1fr auto;
        padding: 10px;
        min-height: 64px;
    }
    .chat-avatar { width: 48px; height: 48px; font-size: 1.15rem; }
    .chat-contact-name { font-size: 1rem; }
    .chat-last-message { font-size: 0.88rem; }
    .chat-filter-chip { padding: 6px 12px; font-size: 0.82rem; min-height: 32px; }
    .chat-message-bubble { font-size: 1rem; padding: 9px 13px; }
    .chat-empty-actions { flex-direction: column; width: 100%; }
    .chat-primary-action, .chat-secondary-action { width: 100%; justify-content: center; }
    .chat-list-header { padding: 10px 12px; }
    .chat-list-header h2 { font-size: 1.1rem; }
    .chat-header-info .chat-contact-name { font-size: 1.05rem; }
    /* Composer tighter on small phones */
    .chat-composer {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
        gap: 5px;
    }
    /* Mobile-fix: input pořád VELKÝ (senior musí vidět), jen padding nižší */
    .chat-composer-input {
        min-height: 52px;
        font-size: 17px;
        padding: 14px 16px;
    }
    /* Mobile-fix: na malých telefonech (<560px) skryjeme i emoji button —
       máme jen [📎] [input.................] [🎤] [➤]. Emoji se dá vložit
       z klávesnice, je to luxus, ne nutnost. */
    .chat-composer button[aria-label="Emoji"] {
        display: none;
    }
}

/* Landscape on small phones — viewport really squished */
@media (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
    .chat-shell {
        height: calc(100svh - 100px);   /* less chrome subtraction */
        min-height: 320px;
    }
    .chat-header { padding: 6px 10px; }
    .chat-messages { padding: 8px 10px 4px; }
    .chat-composer { padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px)); }
}

/* ==========================================================================
   Print + legacy compatibility
   ========================================================================== */

@media print {
    .chat-composer, .chat-header-actions, .chat-list-panel,
    .chat-icon-button, .chat-send-button, .chat-voice-hero,
    .chat-toast, .chat-emoji-panel { display: none !important; }
    .chat-shell { border: none; box-shadow: none; height: auto; }
}

/* Legacy .km-* classes still referenced by the shell wrapper during migration.
   Minimal compat — new module generates .chat-* and doesn't need these. */
.km-shell, .km-threads, .km-conv { font-family: var(--radim-font); color: var(--radim-text); }
.km-voice-listening {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 22px;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-deep) 100%);
    color: #fff;
    border-radius: 999px;
    box-shadow: var(--radim-shadow-lg);
    font-size: 1.05rem;
    font-weight: 600;
    z-index: 9200;
    max-width: 92vw;
}

.km-voice-wave {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #fff;
    animation: chat-online-pulse 1.2s ease-in-out infinite;
}

/* Legacy toasts from km-* era */
.km-toast {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background: var(--radim-text);
    color: #fff;
    border-radius: 999px;
    z-index: 9300;
    font-size: 0.95rem;
    box-shadow: var(--radim-shadow-lg);
}
.km-toast-warning { background: #8a5a10; }
.km-toast-success { background: var(--radim-primary-deep); }

/* ==========================================================================
   Picker overlay (new conversation dialog)
   ========================================================================== */

.chat-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(31, 52, 46, 0.48);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: chat-overlay-in 0.18s ease-out;
}

@keyframes chat-overlay-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.chat-picker-sheet {
    background: var(--radim-surface);
    border-radius: var(--radim-radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 78vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--radim-shadow-lg);
    overflow: hidden;
    animation: chat-sheet-in 0.22s ease-out;
}

@keyframes chat-sheet-in {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-picker-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--radim-border);
    background: var(--radim-panel);
}

.chat-picker-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-picker-title strong {
    font-family: var(--radim-font-serif);
    font-size: 1.15rem;
    color: var(--radim-primary-deep);
}

.chat-picker-title span {
    font-size: 0.85rem;
    color: var(--radim-text-muted);
}

.chat-picker-sheet .chat-search {
    margin: 12px 14px 6px;
}

.chat-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 6px 12px 16px;
    -webkit-overflow-scrolling: touch;
}

.chat-picker-section {
    margin: 12px 0 8px;
}

.chat-picker-section-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--radim-text-muted);
    padding: 6px 8px;
}

.chat-picker-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-picker-card {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background var(--transition-fast);
    min-height: 60px;
    color: var(--radim-text);
}

.chat-picker-card:hover,
.chat-picker-card:focus-visible {
    background: var(--radim-primary-soft);
    outline: none;
}

.chat-picker-card .chat-avatar { width: 48px; height: 48px; font-size: 1.1rem; }

.chat-picker-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-picker-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--radim-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-picker-rel {
    font-size: 0.82rem;
    color: var(--radim-text-muted);
    font-style: italic;
}

.chat-picker-card--disabled {
    opacity: 0.55;
    cursor: help;
}

.chat-picker-card--disabled:hover {
    background: transparent;
}

.chat-picker-card--radim {
    background: linear-gradient(135deg, var(--radim-accent-soft) 0%, #fff4d3 100%);
    border: 1px solid rgba(244, 201, 93, 0.35);
    margin-bottom: 6px;
}

.chat-picker-card--radim:hover {
    background: linear-gradient(135deg, #fff4d3 0%, #fbe8b7 100%);
}

.chat-picker-badge {
    padding: 3px 9px;
    background: rgba(217, 107, 107, 0.08);
    color: #8a3b3b;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

/* ==========================================================================
   Voice listening banner (legacy — still used)
   ========================================================================== */

.km-voice-listening {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 22px;
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-deep) 100%);
    color: #fff;
    border-radius: 999px;
    box-shadow: var(--radim-shadow-lg);
    font-size: 1.05rem;
    font-weight: 600;
    z-index: 9200;
    max-width: 92vw;
}

/* ==========================================================================
   Dark mode preparedness — triggered via prefers-color-scheme OR
   html[data-theme="dark"] (not activated by default yet).
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    :root[data-chat-theme="auto"] {
        --radim-bg: #0f1614;
        --radim-surface: #1a2421;
        --radim-surface-soft: #1f2b28;
        --radim-panel: #17211e;
        --radim-panel-2: #202d29;
        --radim-text: #e4ebe8;
        --radim-text-soft: #a8b5b0;
        --radim-text-muted: #7a8783;
        --radim-border: #2a3734;
        --radim-border-strong: #3a4a46;
        --radim-primary-soft: color-mix(in srgb, var(--radim-primary) 15%, transparent);
        --radim-accent-soft: rgba(244, 201, 93, 0.18);
    }
}

/* ==========================================================================
   Sprint J — Voice notes, image/file attachments, lightbox, recording bar
   ========================================================================== */

/* Voice-message bubble */
.chat-voice-bubble-inner {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px 4px 2px;
    min-width: 200px;
}

.chat-voice-bubble-inner .chat-voice-play {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    background: var(--radim-primary);
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform var(--transition-fast), background var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: inherit;
}

.chat-voice-bubble-inner .chat-voice-play:hover,
.chat-voice-bubble-inner .chat-voice-play:focus-visible {
    background: var(--radim-primary-deep);
    transform: scale(1.06);
    outline: none;
}

.chat-message-bubble--outgoing .chat-voice-bubble-inner .chat-voice-play {
    background: var(--radim-primary-deep);
}

.chat-voice-bubble-inner .chat-voice-waveform {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 100px;
}

.chat-voice-bubble-inner .chat-voice-waveform span {
    flex: 1;
    background: var(--radim-primary-deep);
    border-radius: 2px;
    opacity: 0.4;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(1) { height: 45%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(2) { height: 70%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(3) { height: 55%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(4) { height: 85%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(5) { height: 65%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(6) { height: 40%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(7) { height: 75%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(8) { height: 60%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(9) { height: 90%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(10) { height: 50%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(11) { height: 70%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(12) { height: 45%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(13) { height: 80%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(14) { height: 55%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(15) { height: 65%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(16) { height: 40%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(17) { height: 75%; }
.chat-voice-bubble-inner .chat-voice-waveform span:nth-child(18) { height: 50%; }

/* Playing state animates bars */
.chat-voice-bubble-inner--playing .chat-voice-waveform span {
    animation: chat-voice-wave 1.1s ease-in-out infinite;
    opacity: 0.85;
}

.chat-voice-bubble-inner--playing .chat-voice-waveform span:nth-child(2n) { animation-delay: 0.15s; }
.chat-voice-bubble-inner--playing .chat-voice-waveform span:nth-child(3n) { animation-delay: 0.3s; }
.chat-voice-bubble-inner--playing .chat-voice-waveform span:nth-child(5n) { animation-delay: 0.45s; }

@keyframes chat-voice-wave {
    0%, 100% { transform: scaleY(0.6); }
    50%      { transform: scaleY(1); }
}

.chat-voice-duration {
    font-size: 0.78rem;
    color: var(--radim-text-soft);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 32px;
    text-align: right;
}

.chat-voice-transcript {
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    font-size: 0.85rem;
    color: var(--radim-text-soft);
    font-style: italic;
    line-height: 1.4;
    max-width: 320px;
}

.chat-message-bubble--outgoing .chat-voice-transcript {
    background: rgba(0, 0, 0, 0.05);
    color: var(--radim-text);
}

/* Image-message bubble */
.chat-message-bubble--image {
    padding: 4px 4px 6px !important;
    max-width: 320px;
}

.chat-image-preview {
    width: 100%;
    max-width: 320px;
    max-height: 320px;
    object-fit: cover;
    border-radius: 14px;
    cursor: pointer;
    display: block;
    background: var(--radim-surface-soft);
    transition: filter 0.15s ease, transform 0.2s ease;
}

.chat-image-preview:hover {
    filter: brightness(0.95);
    transform: scale(1.01);
}

.chat-image-caption {
    padding: 6px 10px 2px;
    font-size: 0.88rem;
    color: var(--radim-text);
}

/* Lightbox */
.chat-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: chat-overlay-in 0.2s ease-out;
}

.chat-lightbox img {
    max-width: 94vw;
    max-height: 92vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 60px rgba(0,0,0,0.5);
}

.chat-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background var(--transition-fast);
}

.chat-lightbox-close:hover { background: rgba(255,255,255,0.28); }

/* File attachment bubble — reuse .chat-attachment-card (already styled) */

/* Recording bar (appears above composer while recording voice note) */
.chat-recording-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(90deg, rgba(217, 107, 107, 0.12), rgba(217, 107, 107, 0.04));
    border-top: 1px solid var(--radim-border);
    z-index: 3;
    animation: chat-panel-in 0.2s ease-out;
}

.chat-recording-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--radim-danger);
    animation: chat-recording-pulse 1s ease-in-out infinite;
}

@keyframes chat-recording-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 107, 107, 0.5); opacity: 1; }
    50%      { box-shadow: 0 0 0 8px rgba(217, 107, 107, 0);   opacity: 0.6; }
}

.chat-recording-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--radim-danger);
}

.chat-recording-timer {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--radim-text);
    font-size: 1rem;
    min-width: 40px;
}

.chat-recording-cancel,
.chat-recording-send {
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    min-height: 40px;
}

.chat-recording-cancel {
    background: var(--radim-surface-soft);
    color: var(--radim-text-soft);
    border: 1px solid var(--radim-border);
}

.chat-recording-cancel:hover {
    background: var(--radim-surface);
    color: var(--radim-danger);
    border-color: var(--radim-danger);
}

.chat-recording-send {
    background: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    color: #fff;
    box-shadow: 0 3px 10px color-mix(in srgb, var(--radim-primary) 35%, transparent);
}

.chat-recording-send:hover { transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--radim-primary) 50%, transparent); }

/* Record button in composer (active when recording) */
.chat-record-btn {
    background: transparent !important;
    color: var(--radim-text-soft);
}

.chat-record-btn:hover {
    background: rgba(217, 107, 107, 0.1) !important;
    color: var(--radim-danger);
}

/* Attach menu (bubbles from + button) */
.chat-attach-menu {
    position: fixed;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 14px;
    box-shadow: var(--radim-shadow-lg);
    padding: 6px;
    min-width: 200px;
    z-index: 100;
    animation: chat-context-in 0.14s ease-out;
}

.chat-attach-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--radim-text);
    cursor: pointer;
    border-radius: 10px;
    text-align: left;
    transition: background var(--transition-fast);
}

.chat-attach-option:hover,
.chat-attach-option:focus-visible {
    background: var(--radim-primary-soft);
    outline: none;
}

.chat-attach-icon {
    font-size: 1.25rem;
    width: 28px;
    text-align: center;
}

/* Mobile tweak for recording bar */
@media (max-width: 560px) {
    .chat-recording-bar {
        grid-template-columns: auto auto 1fr auto;
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    .chat-recording-label { display: none; }
    .chat-recording-cancel { padding: 6px 12px; }
    .chat-recording-send { padding: 6px 14px; }
    .chat-voice-bubble-inner { min-width: 160px; }
    .chat-voice-bubble-inner .chat-voice-waveform { min-width: 70px; }
    .chat-image-preview { max-width: 260px; max-height: 260px; }
}

/* ==========================================================================
   Sprint K — Speed & accessibility
   Quick replies, BIG mode, High contrast, A11y menu, SOS
   ========================================================================== */

/* Quick reply chip row (above composer) */
.chat-quick-replies {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    background: var(--radim-surface);
    border-top: 1px solid var(--radim-border);
    flex-shrink: 0;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
            mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
}

.chat-quick-replies::-webkit-scrollbar { display: none; }

.chat-quick-replies.hidden { display: none; }

.chat-quick-reply {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1.5px solid var(--radim-border);
    background: var(--radim-surface-soft);
    color: var(--radim-text);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    min-height: 38px;
}

.chat-quick-reply:hover,
.chat-quick-reply:focus-visible {
    background: var(--radim-primary-soft);
    border-color: var(--radim-primary);
    color: var(--radim-primary-deep);
    transform: translateY(-1px);
    outline: none;
}

.chat-quick-reply:active { transform: translateY(0) scale(0.98); }

.chat-quick-reply-emoji { font-size: 1.05rem; line-height: 1; }

/* A11y dropdown menu (from ♿ button) */
.chat-a11y-menu {
    position: fixed;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 16px;
    box-shadow: var(--radim-shadow-lg);
    padding: 6px;
    min-width: 280px;
    max-width: 92vw;
    z-index: 9400;
    animation: chat-context-in 0.15s ease-out;
}

.chat-a11y-menu-title {
    padding: 10px 14px 6px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--radim-text-muted);
}

.chat-a11y-item {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 12px;
    align-items: center;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: transparent;
    font-family: inherit;
    color: var(--radim-text);
    cursor: pointer;
    border-radius: 10px;
    text-align: left;
    transition: background var(--transition-fast);
    min-height: 56px;
}

.chat-a11y-item:hover,
.chat-a11y-item:focus-visible {
    background: var(--radim-primary-soft);
    outline: none;
}

.chat-a11y-item--on {
    background: var(--radim-primary-soft);
}

.chat-a11y-icon {
    font-size: 1.4rem;
    text-align: center;
    line-height: 1;
}

.chat-a11y-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-a11y-body strong {
    font-size: 0.98rem;
    color: var(--radim-text);
}

.chat-a11y-body span {
    font-size: 0.82rem;
    color: var(--radim-text-muted);
}

.chat-a11y-toggle-state {
    color: var(--radim-success);
    font-weight: 700;
    font-size: 1.1rem;
}

.chat-a11y-divider {
    height: 1px;
    background: var(--radim-border);
    margin: 6px 4px;
}

.chat-a11y-item--danger {
    color: var(--radim-danger);
}

.chat-a11y-item--danger strong { color: var(--radim-danger); }

.chat-a11y-item--danger:hover {
    background: rgba(217, 107, 107, 0.08);
}

/* SOS confirmation overlay */
.chat-sos-overlay {
    position: fixed;
    inset: 0;
    background: rgba(31, 52, 46, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: chat-overlay-in 0.18s ease-out;
}

.chat-sos-card {
    background: var(--radim-surface);
    border-radius: var(--radim-radius-lg);
    padding: 30px 28px;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: var(--radim-shadow-lg);
    animation: chat-sheet-in 0.22s ease-out;
    border: 3px solid var(--radim-danger);
}

.chat-sos-icon {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 12px;
    animation: chat-sos-pulse 1.4s ease-in-out infinite;
}

@keyframes chat-sos-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

.chat-sos-card h2 {
    font-family: var(--radim-font-serif);
    font-size: 1.5rem;
    color: var(--radim-danger);
    margin: 0 0 10px;
}

.chat-sos-card p {
    font-size: 1.05rem;
    color: var(--radim-text);
    line-height: 1.5;
    margin: 0 0 22px;
}

.chat-sos-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.chat-sos-cancel,
.chat-sos-send {
    border: none;
    border-radius: 999px;
    padding: 14px 24px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 52px;
    transition: transform var(--transition-fast), box-shadow var(--transition-med);
}

.chat-sos-cancel {
    background: var(--radim-surface-soft);
    color: var(--radim-text);
    border: 2px solid var(--radim-border-strong);
}

.chat-sos-cancel:hover {
    background: var(--radim-surface);
    border-color: var(--radim-text-muted);
}

.chat-sos-send {
    background: linear-gradient(135deg, var(--radim-danger) 0%, #b94545 100%);
    color: #fff;
    box-shadow: 0 6px 20px rgba(217, 107, 107, 0.4);
}

.chat-sos-send:hover,
.chat-sos-send:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(217, 107, 107, 0.55);
    outline: none;
}

/* ==========================================================================
   BIG mode — html[data-chat-size="big"]
   Doubles font sizes, increases tap targets, more padding
   ========================================================================== */

html[data-chat-size="big"] .chat-shell {
    font-size: 18px;
}

html[data-chat-size="big"] .chat-message-bubble {
    font-size: 1.3rem;
    line-height: 1.55;
    padding: 14px 18px;
}

html[data-chat-size="big"] .chat-icon-button,
html[data-chat-size="big"] .chat-back-button,
html[data-chat-size="big"] .chat-send-button {
    width: 56px;
    height: 56px;
    min-width: 56px;
    font-size: 1.45rem;
}

html[data-chat-size="big"] .chat-search-input,
html[data-chat-size="big"] .chat-composer-input {
    font-size: 1.18rem;
    min-height: 56px;
    padding: 16px 22px;
}

html[data-chat-size="big"] .chat-contact-name {
    font-size: 1.25rem;
}

html[data-chat-size="big"] .chat-last-message {
    font-size: 1.08rem;
}

html[data-chat-size="big"] .chat-conversation-card {
    min-height: 84px;
    padding: 14px 16px;
    grid-template-columns: 64px 1fr auto;
}

html[data-chat-size="big"] .chat-avatar {
    width: 64px;
    height: 64px;
    font-size: 1.55rem;
}

html[data-chat-size="big"] .chat-list-header h2 {
    font-size: 1.55rem;
}

html[data-chat-size="big"] .chat-empty-state h2 {
    font-size: 1.85rem;
}

html[data-chat-size="big"] .chat-empty-state p {
    font-size: 1.18rem;
}

html[data-chat-size="big"] .chat-quick-reply {
    font-size: 1.1rem;
    padding: 12px 18px;
    min-height: 48px;
}

html[data-chat-size="big"] .chat-filter-chip {
    font-size: 1.02rem;
    padding: 10px 18px;
    min-height: 42px;
}

html[data-chat-size="big"] .chat-message-time,
html[data-chat-size="big"] .chat-meta {
    font-size: 0.95rem;
}

html[data-chat-size="big"] .chat-header-info .chat-contact-name {
    font-size: 1.35rem;
}

html[data-chat-size="big"] .chat-contact-status {
    font-size: 1rem;
}

/* ==========================================================================
   HIGH CONTRAST mode — html[data-chat-contrast="high"]
   WCAG AAA palette: pure black text on white, strong borders, no gradients
   ========================================================================== */

html[data-chat-contrast="high"] {
    --radim-bg: #ffffff;
    --radim-surface: #ffffff;
    --radim-surface-soft: #f4f4f4;
    --radim-panel: #f7f7f7;
    --radim-panel-2: #ededed;
    --radim-text: #000000;
    --radim-text-soft: #1a1a1a;
    --radim-text-muted: #404040;
    --radim-border: #707070;
    --radim-border-strong: #303030;
    --radim-primary: #006666;
    --radim-primary-hover: #004d4d;
    --radim-primary-soft: #d6efee;
    --radim-primary-deep: #002222;
    --radim-accent: #b87800;
    --radim-accent-soft: #fce4b8;
    --radim-accent-deep: #5a3b00;
    --radim-success: #006d3a;
    --radim-warning: #8a4a00;
    --radim-danger: #a01010;
    --radim-shadow-sm: 0 0 0 1px #000;
    --radim-shadow-md: 0 0 0 2px #000;
    --radim-shadow-lg: 0 0 0 3px #000;
}

html[data-chat-contrast="high"] .chat-message-bubble {
    border-width: 2px !important;
}

html[data-chat-contrast="high"] .chat-message-bubble--outgoing {
    background: #d6efee !important;
    border-color: #006666 !important;
}

html[data-chat-contrast="high"] .chat-message-bubble--ai {
    background: #fce4b8 !important;
    border-color: #b87800 !important;
}

html[data-chat-contrast="high"] .chat-icon-button,
html[data-chat-contrast="high"] .chat-back-button {
    border: 2px solid #000;
}

html[data-chat-contrast="high"] .chat-conversation-card--active {
    background: #fce4b8 !important;
    border: 2px solid #000;
    box-shadow: inset 4px 0 0 #006666 !important;
}

/* Combined: BIG + High contrast */
html[data-chat-size="big"][data-chat-contrast="high"] .chat-message-bubble {
    border-width: 3px !important;
}

/* ==========================================================================
   Sprint L — Radim AI as active companion
   Smart replies, translate, summarize, extract event
   ========================================================================== */

/* AI suggestions row (between messages and quick replies) */
.chat-ai-suggestions {
    padding: 0;
    background: linear-gradient(180deg, transparent, var(--radim-accent-soft));
    border-top: 1px solid var(--radim-border);
    flex-shrink: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.chat-ai-suggestions:empty,
.chat-ai-suggestions.hidden { display: none; }

.chat-ai-suggestions-loading,
.chat-ai-suggestions-empty {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--radim-accent-deep);
    font-size: 0.92rem;
    font-style: italic;
}

.chat-ai-loader {
    width: 14px;
    height: 14px;
    border: 2px solid var(--radim-accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: chat-ai-spin 0.8s linear infinite;
}

@keyframes chat-ai-spin { to { transform: rotate(360deg); } }

.chat-ai-suggestions-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px 4px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--radim-accent-deep);
    letter-spacing: 0.2px;
}

.chat-ai-icon { font-size: 1rem; line-height: 1; }

.chat-ai-close {
    margin-left: auto;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--radim-text-muted);
    cursor: pointer;
    border-radius: 50%;
    font-size: 0.85rem;
    transition: background var(--transition-fast);
}

.chat-ai-close:hover {
    background: rgba(0,0,0,0.06);
    color: var(--radim-text);
}

.chat-ai-suggestions-row {
    display: flex;
    gap: 8px;
    padding: 4px 16px 12px;
    flex-wrap: wrap;
}

.chat-ai-suggestion {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    border: 1.5px solid var(--radim-accent);
    background: var(--radim-surface);
    color: var(--radim-text);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    min-height: 40px;
}

.chat-ai-suggestion:hover,
.chat-ai-suggestion:focus-visible {
    background: var(--radim-accent);
    color: #5a3f08;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(244, 201, 93, 0.3);
    outline: none;
}

/* Inline AI translation/summary in bubble */
.chat-ai-translation,
.chat-ai-summary {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px dashed var(--radim-accent);
    font-size: 0.92rem;
    line-height: 1.4;
    animation: chat-msg-in 0.2s ease-out;
}

.chat-message-bubble--outgoing .chat-ai-translation,
.chat-message-bubble--outgoing .chat-ai-summary {
    background: rgba(0, 0, 0, 0.05);
}

.chat-ai-translation--loading,
.chat-ai-summary--loading {
    font-style: italic;
    opacity: 0.75;
}

.chat-ai-translation-label,
.chat-ai-summary-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--radim-accent-deep);
    margin-bottom: 3px;
    letter-spacing: 0.2px;
}

.chat-ai-translation-text,
.chat-ai-summary-text {
    color: var(--radim-text);
}

/* Event extraction modal — reuses chat-event-overlay */
.chat-event-overlay {
    position: fixed;
    inset: 0;
    background: rgba(31, 52, 46, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: chat-overlay-in 0.18s ease-out;
}

.chat-event-card {
    background: var(--radim-surface);
    border-radius: var(--radim-radius-lg);
    padding: 26px 24px;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: var(--radim-shadow-lg);
    animation: chat-sheet-in 0.22s ease-out;
}

.chat-event-icon {
    font-size: 2.6rem;
    line-height: 1;
    margin-bottom: 8px;
}

.chat-event-card h2 {
    font-family: var(--radim-font-serif);
    font-size: 1.35rem;
    color: var(--radim-primary-deep);
    margin: 0 0 16px;
}

.chat-event-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
    margin-bottom: 18px;
}

.chat-event-fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--radim-text-soft);
}

.chat-event-fields input {
    padding: 10px 14px;
    border: 1.5px solid var(--radim-border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--radim-surface-soft);
    color: var(--radim-text);
}

.chat-event-fields input:focus {
    outline: none;
    border-color: var(--radim-primary);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
}

.chat-event-fields input:disabled {
    opacity: 0.7;
    background: var(--radim-panel);
}

.chat-event-notes {
    padding: 8px 12px;
    background: var(--radim-accent-soft);
    border-radius: 10px;
    font-size: 0.88rem;
    color: var(--radim-text-soft);
    font-style: italic;
}

.chat-event-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Context menu divider */
.chat-context-divider {
    height: 1px;
    background: var(--radim-border);
    margin: 4px 4px;
}

/* ==========================================================================
   Sprint M — WhatsApp parity: reactions, reply, search, forward, starred,
                                delete (tombstone), undo
   ========================================================================== */

/* Bubble wrap allows reactions chips outside bubble */
.chat-message-bubble-wrap {
    display: flex;
    flex-direction: column;
    align-items: inherit;
    gap: 4px;
    min-width: 0;
}

.chat-message-row--outgoing .chat-message-bubble-wrap { align-items: flex-end; }
.chat-message-row--incoming .chat-message-bubble-wrap { align-items: flex-start; }

/* Reaction chips under bubble */
.chat-message-reactions {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: -2px;
    padding: 0 4px;
}

.chat-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border: 1px solid var(--radim-border);
    background: var(--radim-surface);
    color: var(--radim-text);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    line-height: 1.4;
    box-shadow: var(--radim-shadow-sm);
}

.chat-reaction-chip:hover {
    transform: translateY(-1px);
    border-color: var(--radim-primary);
}

.chat-reaction-chip--mine {
    background: var(--radim-primary-soft);
    border-color: var(--radim-primary);
    color: var(--radim-primary-deep);
    font-weight: 600;
}

.chat-reaction-count {
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Reaction picker (popover above bubble) */
.chat-reaction-picker {
    position: fixed;
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: 999px;
    box-shadow: var(--radim-shadow-lg);
    padding: 6px 8px;
    display: inline-flex;
    gap: 2px;
    z-index: 9450;
    animation: chat-context-in 0.15s ease-out;
}

.chat-reaction-pick {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 50%;
    transition: transform var(--transition-fast), background var(--transition-fast);
    line-height: 1;
}

.chat-reaction-pick:hover,
.chat-reaction-pick:focus-visible {
    background: var(--radim-primary-soft);
    transform: scale(1.25);
    outline: none;
}

.chat-reaction-pick--mine {
    background: var(--radim-primary-soft);
}

/* Reply quoted block above bubble content */
.chat-reply-quote {
    margin-bottom: 6px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.05);
    border-left: 3px solid var(--radim-primary);
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-reply-quote:hover { background: rgba(0,0,0,0.08); }

.chat-reply-quote strong {
    display: block;
    color: var(--radim-primary-deep);
    font-size: 0.78rem;
    margin-bottom: 2px;
}

.chat-reply-quote span {
    color: var(--radim-text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.chat-reply-quote--missing {
    background: var(--radim-surface-soft);
    color: var(--radim-text-muted);
    font-style: italic;
    font-size: 0.85rem;
    padding: 6px 10px;
    border-left: 3px solid var(--radim-border-strong);
    border-radius: 8px;
    margin-bottom: 6px;
}

.chat-message-bubble--outgoing .chat-reply-quote {
    background: rgba(0,0,0,0.06);
    border-left-color: var(--radim-primary-deep);
}

/* Reply composer bar (above input row) */
.chat-reply-bar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 14px;
    background: var(--radim-primary-soft);
    border-top: 1px solid var(--radim-primary);
    flex-shrink: 0;
    animation: chat-panel-in 0.18s ease-out;
}

.chat-reply-bar-icon {
    color: var(--radim-primary-deep);
    font-size: 1.15rem;
}

.chat-reply-bar-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-reply-bar-body strong {
    font-size: 0.78rem;
    color: var(--radim-primary-deep);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.chat-reply-bar-body span {
    font-size: 0.92rem;
    color: var(--radim-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-reply-bar-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--radim-surface);
    color: var(--radim-text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: background var(--transition-fast);
}

.chat-reply-bar-close:hover { background: var(--radim-border); color: var(--radim-text); }

/* In-conversation search bar */
.chat-inconv-search {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px 14px;
    background: var(--radim-surface);
    border-bottom: 1px solid var(--radim-border);
    flex-shrink: 0;
    animation: chat-panel-in 0.18s ease-out;
}

.chat-inconv-search-icon {
    font-size: 1rem;
    opacity: 0.7;
}

.chat-inconv-search input {
    border: 1.5px solid var(--radim-border);
    border-radius: 999px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--radim-surface-soft);
    outline: none;
    min-height: 38px;
}

.chat-inconv-search input:focus {
    border-color: var(--radim-primary);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
    background: var(--radim-surface);
}

.chat-inconv-search-counter {
    font-size: 0.78rem;
    color: var(--radim-text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: center;
}

.chat-inconv-search-nav,
.chat-inconv-search-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--radim-text-soft);
    cursor: pointer;
    font-size: 0.95rem;
    transition: background var(--transition-fast);
}

.chat-inconv-search-nav:hover,
.chat-inconv-search-close:hover {
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
}

/* Highlight matched bubbles during in-conv search */
.chat-message-bubble--matched {
    box-shadow: 0 0 0 2px rgba(244, 201, 93, 0.5);
}

.chat-message-bubble--matched-active {
    box-shadow: 0 0 0 3px var(--radim-accent), 0 0 0 6px rgba(244, 201, 93, 0.25);
    background: var(--radim-accent-soft) !important;
}

/* Forward picker list */
.chat-forward-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid var(--radim-border);
    border-radius: 12px;
    padding: 6px;
}

.chat-forward-item {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: var(--radim-text);
    font-size: 0.95rem;
    transition: background var(--transition-fast);
    min-height: 52px;
}

.chat-forward-item:hover {
    background: var(--radim-primary-soft);
}

.chat-forward-item .chat-avatar { width: 40px; height: 40px; font-size: 0.95rem; }

/* Starred message indicator */
.chat-message-star {
    color: var(--radim-accent-deep);
    font-size: 0.85rem;
}

.chat-message-bubble--starred {
    box-shadow: 0 0 0 1px var(--radim-accent), var(--radim-shadow-sm);
}

/* Undo-send toast */
.chat-undo-toast {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px 12px 22px;
    background: var(--radim-text);
    color: #fff;
    border-radius: 999px;
    box-shadow: var(--radim-shadow-lg);
    font-size: 0.95rem;
    z-index: 9300;
    animation: chat-undo-in 0.18s ease-out;
}

@keyframes chat-undo-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.chat-undo-btn {
    background: var(--radim-accent);
    color: var(--radim-text);
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-undo-btn:hover {
    background: #fff;
    color: var(--radim-text);
}

.chat-undo-timer {
    font-variant-numeric: tabular-nums;
    margin-left: 2px;
}

/* ==========================================================================
   Sprint N — Caregiver, PIN lock, Night mode, Dashboard
   ========================================================================== */

/* Lock badge in conversation list */
.chat-lock-badge {
    display: inline-block;
    margin-right: 4px;
    font-size: 0.85em;
    opacity: 0.75;
    vertical-align: middle;
}

/* PIN modal */
.chat-pin-card {
    max-width: 360px;
}

.chat-pin-input {
    width: 100%;
    padding: 16px 20px;
    margin: 14px 0 6px;
    border: 2px solid var(--radim-border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 2rem;
    text-align: center;
    letter-spacing: 0.6em;
    background: var(--radim-surface-soft);
    color: var(--radim-text);
    box-sizing: border-box;
    font-variant-numeric: tabular-nums;
}

.chat-pin-input:focus {
    outline: none;
    border-color: var(--radim-primary);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
}

.chat-pin-error {
    margin-bottom: 10px;
    color: var(--radim-danger);
    font-size: 0.85rem;
    font-weight: 600;
}

/* Dashboard */
.chat-dashboard {
    padding: 24px 28px;
    overflow-y: auto;
    height: 100%;
    background:
        radial-gradient(circle at 15% 15%, var(--radim-primary-soft) 0%, transparent 50%),
        radial-gradient(circle at 85% 85%, var(--radim-accent-soft) 0%, transparent 50%),
        var(--radim-surface);
}

.chat-dashboard-header {
    text-align: center;
    margin-bottom: 22px;
}

.chat-dashboard-header h2 {
    font-family: var(--radim-font-serif);
    font-size: 1.85rem;
    color: var(--radim-primary-deep);
    margin: 0 0 6px;
}

.chat-dashboard-header p {
    color: var(--radim-text-muted);
    font-size: 0.95rem;
    margin: 0;
}

.chat-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.chat-dashboard-card {
    background: var(--radim-surface);
    border: 1px solid var(--radim-border);
    border-radius: var(--radim-radius-md);
    padding: 18px 16px;
    text-align: center;
    box-shadow: var(--radim-shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-med);
}

.chat-dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--radim-shadow-md);
}

.chat-dashboard-card--good {
    border-color: var(--radim-success);
    background: linear-gradient(180deg, var(--radim-surface) 0%, rgba(76, 175, 125, 0.06) 100%);
}

.chat-dashboard-card--warning {
    border-color: var(--radim-warning);
    background: linear-gradient(180deg, var(--radim-surface) 0%, rgba(239, 180, 67, 0.06) 100%);
}

.chat-dashboard-icon {
    font-size: 2.2rem;
    line-height: 1;
    margin-bottom: 6px;
}

.chat-dashboard-value {
    font-family: var(--radim-font-serif);
    font-size: 2rem;
    font-weight: 700;
    color: var(--radim-text);
    margin-bottom: 2px;
    font-variant-numeric: tabular-nums;
}

.chat-dashboard-label {
    font-size: 0.88rem;
    color: var(--radim-text-soft);
}

.chat-dashboard-hint {
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--radim-text-muted);
    font-style: italic;
}

.chat-dashboard-section {
    margin-bottom: 24px;
}

.chat-dashboard-section h3 {
    font-family: var(--radim-font-serif);
    font-size: 1.15rem;
    color: var(--radim-primary-deep);
    margin: 0 0 10px;
}

.chat-dashboard-top-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-dashboard-top-item {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 2fr auto;
    gap: 14px;
    align-items: center;
    padding: 8px 12px;
    background: var(--radim-surface);
    border-radius: 12px;
    border: 1px solid var(--radim-border);
}

.chat-dashboard-top-name {
    font-weight: 600;
    color: var(--radim-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-dashboard-top-bar {
    height: 8px;
    background: var(--radim-surface-soft);
    border-radius: 999px;
    overflow: hidden;
    display: block;
}

.chat-dashboard-top-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--radim-primary), var(--radim-primary-deep));
    border-radius: 999px;
    transition: width 0.4s ease;
}

.chat-dashboard-top-count {
    font-weight: 700;
    color: var(--radim-primary-deep);
    font-variant-numeric: tabular-nums;
    min-width: 28px;
    text-align: right;
}

.chat-dashboard-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

@media (max-width: 560px) {
    .chat-dashboard { padding: 16px 14px; }
    .chat-dashboard-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .chat-dashboard-icon { font-size: 1.8rem; }
    .chat-dashboard-value { font-size: 1.5rem; }
    .chat-dashboard-top-item { grid-template-columns: 1fr auto; }
    .chat-dashboard-top-bar { display: none; }
}

/* ==========================================================================
   Sprint O — Komunita & rituály (memory of day, save-memory, family tree,
                                   daily greeting, conversation insights)
   ========================================================================== */

/* Memory of day card (top of messages area) */
.chat-memory-card {
    background: linear-gradient(135deg, var(--radim-accent-soft) 0%, #fbe8b7 100%);
    border: 1px solid var(--radim-accent);
    border-radius: 14px;
    padding: 12px 14px;
    margin: 6px 8px 14px;
    box-shadow: var(--radim-shadow-sm);
    animation: chat-msg-in 0.3s ease-out;
}

.chat-memory-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--radim-accent-deep);
    font-family: var(--radim-font-serif);
    font-size: 0.95rem;
}

.chat-memory-card-icon { font-size: 1.2rem; line-height: 1; }

.chat-memory-card-close {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--radim-accent-deep);
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 50%;
    transition: background var(--transition-fast);
}

.chat-memory-card-close:hover {
    background: rgba(0,0,0,0.08);
}

.chat-memory-card-item {
    padding: 6px 4px;
    cursor: pointer;
    border-radius: 8px;
    transition: background var(--transition-fast);
}

.chat-memory-card-item + .chat-memory-card-item {
    border-top: 1px dashed rgba(160, 122, 28, 0.3);
    margin-top: 6px;
    padding-top: 8px;
}

.chat-memory-card-item:hover {
    background: rgba(255, 255, 255, 0.5);
}

.chat-memory-card-when {
    font-size: 0.78rem;
    color: var(--radim-accent-deep);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 2px;
}

.chat-memory-card-snippet {
    font-size: 0.92rem;
    color: #5a3f08;
    line-height: 1.4;
}

/* Family tree SVG inside group info panel */
.chat-family-tree {
    width: 100%;
    max-width: 280px;
    height: auto;
    display: block;
    margin: 0 auto;
    cursor: default;
}

.chat-tree-node {
    transition: opacity var(--transition-fast);
    cursor: pointer;
}

.chat-tree-node:hover circle {
    stroke-width: 4;
    filter: brightness(1.08);
}

/* Conversation insights rows (in info panel) */
.chat-insight-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: 0.95rem;
    color: var(--radim-text);
}

.chat-insight-icon {
    width: 24px;
    text-align: center;
    font-size: 1.05rem;
    opacity: 0.85;
}

.chat-insight-row strong {
    color: var(--radim-primary-deep);
}

/* ==========================================================================
   Sprint P — Production hardening (audit, GDPR, health, offline, status)
   ========================================================================== */

/* Connection status indicator (in list header next to title) */
.chat-connection-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-left: 8px;
}

.chat-connection-status--offline {
    background: rgba(217, 107, 107, 0.12);
    color: var(--radim-danger);
}

.chat-connection-status--queued {
    background: var(--radim-accent-soft);
    color: var(--radim-accent-deep);
}

.chat-connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: chat-conn-pulse 1.6s ease-in-out infinite;
}

@keyframes chat-conn-pulse {
    0%, 100% { opacity: 0.5; }
    50%      { opacity: 1; }
}

/* Audit log list (modal) */
.chat-audit-list {
    max-height: 50vh;
    overflow-y: auto;
    margin: 8px 0 14px;
    border: 1px solid var(--radim-border);
    border-radius: 12px;
    background: var(--radim-surface-soft);
}

.chat-audit-item {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--radim-border);
}

.chat-audit-item:last-child { border-bottom: none; }

.chat-audit-icon {
    text-align: center;
    font-size: 1.1rem;
}

.chat-audit-body { min-width: 0; }

.chat-audit-action {
    font-weight: 600;
    color: var(--radim-text);
    font-size: 0.95rem;
}

.chat-audit-meta {
    font-size: 0.78rem;
    color: var(--radim-text-muted);
}

.chat-audit-when {
    font-size: 0.78rem;
    color: var(--radim-text-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Health modal rows */
.chat-health-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 0.95rem;
    color: var(--radim-text-soft);
}

.chat-health-row strong {
    color: var(--radim-text);
    font-variant-numeric: tabular-nums;
}

/* Queued message bubble state */
.chat-message-bubble--sending::after {
    content: '';
}

html[data-chat-theme="dark"] {
    --radim-bg: #0f1614;
    --radim-surface: #1a2421;
    --radim-surface-soft: #1f2b28;
    --radim-panel: #17211e;
    --radim-panel-2: #202d29;
    --radim-text: #e4ebe8;
    --radim-text-soft: #a8b5b0;
    --radim-text-muted: #7a8783;
    --radim-border: #2a3734;
    --radim-border-strong: #3a4a46;
    --radim-primary-soft: color-mix(in srgb, var(--radim-primary) 15%, transparent);
    --radim-accent-soft: rgba(244, 201, 93, 0.18);
}

/* ==========================================================================
   Sprint I.5 — GROUP CHAT + POLISH
   Types, avatars, headers, info panel, author labels, pins, mute, dark toggle
   ========================================================================== */

/* Group type color tokens */
:root {
    --group-family-ring: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-accent) 100%);
    --group-medical-ring: linear-gradient(135deg, var(--radim-role-medical) 0%, #8db9d4 100%);
    --group-friends-ring: linear-gradient(135deg, var(--radim-primary) 0%, var(--radim-primary-hover) 100%);
    --group-community-ring: linear-gradient(135deg, #7ab87f 0%, #5a9e60 100%);
    --group-workshop-ring: linear-gradient(135deg, #9e7dc9 0%, #7f5fb3 100%);
    --group-custom-ring: linear-gradient(135deg, var(--radim-text-soft) 0%, var(--radim-text-muted) 100%);
}

/* ─── Group conversation card ────────────────────────────────── */
.chat-conversation-card--group {
    /* Slight left-accent to visually separate group from 1:1 */
}

.chat-conversation-card--group .chat-avatar--group {
    background: var(--group-custom-ring);
}
.chat-conversation-card--group[data-group-type="family"] .chat-avatar--group    { background: var(--group-family-ring); }
.chat-conversation-card--group[data-group-type="medical"] .chat-avatar--group   { background: var(--group-medical-ring); }
.chat-conversation-card--group[data-group-type="friends"] .chat-avatar--group   { background: var(--group-friends-ring); }
.chat-conversation-card--group[data-group-type="community"] .chat-avatar--group { background: var(--group-community-ring); }
.chat-conversation-card--group[data-group-type="workshop"] .chat-avatar--group  { background: var(--group-workshop-ring); }

.chat-avatar--group {
    position: relative;
    font-size: 1.3rem;
    color: #fff;
}

/* Group emoji inside avatar */
.chat-avatar--group .chat-avatar-emoji {
    font-size: 1.5rem;
    line-height: 1;
}

/* Composite avatar — 2-3 member thumbnails stacked (fallback when no emoji) */
.chat-avatar--composite {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    padding: 2px;
    gap: 2px;
    background: var(--radim-border);
}

.chat-avatar--composite .chat-mini-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--radim-primary);
    color: #fff;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* Small group "members" icon next to name in list */
.chat-group-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px 1px 5px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-right: 6px;
    vertical-align: middle;
}

.chat-group-badge .chat-group-badge-icon { font-size: 0.78rem; line-height: 1; }

/* Preview author prefix "Denisa: …" */
.chat-last-message-author {
    font-weight: 600;
    color: var(--radim-text);
    margin-right: 4px;
}

/* Group header meta ("5 členů · 2 online · Rodina") */
.chat-group-header-meta {
    font-size: 0.85rem;
    color: var(--radim-text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.chat-group-header-meta > span { display: inline-flex; align-items: center; gap: 4px; }

.chat-group-header-meta .dot { opacity: 0.4; }

.chat-group-members-preview {
    display: inline-flex;
    align-items: center;
    gap: -4px;
    margin-left: 4px;
}

.chat-group-members-preview .chat-mini-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--radim-surface);
    font-size: 0.65rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--radim-primary);
    margin-left: -6px;
}

.chat-group-members-preview .chat-mini-avatar:first-child { margin-left: 0; }

/* ─── Create-group modal ─────────────────────────────────────── */
.chat-new-group-modal {
    position: fixed;
    inset: 0;
    background: rgba(31, 52, 46, 0.48);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: chat-overlay-in 0.18s ease-out;
}

.chat-group-form {
    background: var(--radim-surface);
    border-radius: var(--radim-radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--radim-shadow-lg);
    overflow: hidden;
    animation: chat-sheet-in 0.22s ease-out;
}

.chat-group-form-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--radim-border);
    background: var(--radim-panel);
}

.chat-group-form-header h3 {
    flex: 1;
    font-family: var(--radim-font-serif);
    font-size: 1.2rem;
    color: var(--radim-primary-deep);
    margin: 0;
}

.chat-group-form-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.chat-group-form-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--radim-border);
    background: var(--radim-panel);
}

/* Form fields */
.chat-group-field-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--radim-text-soft);
    margin-bottom: 6px;
    letter-spacing: 0.2px;
}

.chat-group-name-input,
.chat-group-desc-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--radim-border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--radim-surface-soft);
    color: var(--radim-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-sizing: border-box;
}

.chat-group-name-input:focus,
.chat-group-desc-input:focus {
    border-color: var(--radim-primary);
    background: var(--radim-surface);
    box-shadow: 0 0 0 3px var(--radim-primary-soft);
    outline: none;
}

.chat-group-desc-input {
    resize: vertical;
    min-height: 72px;
    max-height: 160px;
    font-size: 0.95rem;
}

/* Type selector */
.chat-group-type-select {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
    gap: 8px;
}

.chat-group-type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: 2px solid var(--radim-border);
    border-radius: 12px;
    background: var(--radim-surface);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    color: var(--radim-text);
    min-height: 82px;
}

.chat-group-type-option-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.chat-group-type-option-label {
    font-size: 0.85rem;
    font-weight: 600;
}

.chat-group-type-option:hover,
.chat-group-type-option:focus-visible {
    border-color: var(--radim-primary);
    background: var(--radim-primary-soft);
    outline: none;
}

.chat-group-type-option--active {
    border-color: var(--radim-primary);
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    box-shadow: var(--radim-shadow-sm);
}

/* Member picker */
.chat-group-member-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-group-member-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--radim-border);
    border-radius: 12px;
    padding: 6px;
    background: var(--radim-surface-soft);
    -webkit-overflow-scrolling: touch;
}

.chat-group-member-picker-item {
    display: grid;
    grid-template-columns: auto 40px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition-fast);
    font-family: inherit;
    color: var(--radim-text);
    user-select: none;
}

.chat-group-member-picker-item:hover {
    background: var(--radim-primary-soft);
}

.chat-group-member-picker-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--radim-primary);
    cursor: pointer;
}

.chat-group-member-picker-item .chat-avatar {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
}

.chat-group-member-picker-item-body {
    min-width: 0;
}

.chat-group-member-picker-item-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-group-member-picker-item-rel {
    font-size: 0.8rem;
    color: var(--radim-text-muted);
}

/* Selected member chips */
.chat-group-member-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 32px;
}

.chat-group-member-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 4px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.chat-group-member-chip .chat-mini-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--radim-primary);
    color: #fff;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.chat-group-member-chip-remove {
    cursor: pointer;
    opacity: 0.6;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 0.9rem;
    padding: 0 4px;
}
.chat-group-member-chip-remove:hover { opacity: 1; }

/* Include-Radim toggle */
.chat-group-include-radim {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 2px solid var(--radim-accent);
    background: var(--radim-accent-soft);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-group-include-radim:hover { background: #fbe8b7; }

.chat-group-include-radim input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--radim-accent);
}

.chat-group-include-radim-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--radim-accent);
    object-fit: cover;
    object-position: center 18%;
}

.chat-group-include-radim-text {
    flex: 1;
}

.chat-group-include-radim-text strong { color: var(--radim-accent-deep); font-size: 1rem; }
.chat-group-include-radim-text span { font-size: 0.85rem; color: var(--radim-text-soft); }

/* ─── Group chat header extras ───────────────────────────────── */
.chat-header--group {
    /* Slight accent */
}

.chat-header--group .chat-contact-status {
    font-size: 0.82rem;
}

.chat-header-subrow {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.chat-header-type-badge {
    padding: 1px 8px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.chat-header-type-badge--family { background: var(--radim-accent-soft); color: var(--radim-accent-deep); }
.chat-header-type-badge--medical { background: rgba(106, 167, 200, 0.18); color: #1f5d7f; }
.chat-header-type-badge--community { background: rgba(122, 184, 127, 0.2); color: #386b3c; }
.chat-header-type-badge--workshop { background: rgba(158, 125, 201, 0.2); color: #5f3f8b; }

/* ─── Author label on group incoming messages ────────────────── */
.chat-message-author {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
    padding: 0 2px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.2px;
}

/* Different hue per author (stable hash) */
.chat-message-author[data-hue="0"] { color: var(--radim-primary); }
.chat-message-author[data-hue="1"] { color: #8a4f8e; }
.chat-message-author[data-hue="2"] { color: #a07a1c; }
.chat-message-author[data-hue="3"] { color: #1f5d7f; }
.chat-message-author[data-hue="4"] { color: #386b3c; }
.chat-message-author[data-hue="5"] { color: #8a3b3b; }
.chat-message-author[data-hue="6"] { color: #5f3f8b; }

.chat-role-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    background: var(--radim-surface-soft);
    color: var(--radim-text-muted);
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    border: 1px solid var(--radim-border);
}

.chat-role-badge--ai       { background: var(--radim-accent-soft); color: var(--radim-accent-deep); border-color: var(--radim-accent); }
.chat-role-badge--admin    { background: var(--radim-primary-soft); color: var(--radim-primary-deep); border-color: var(--radim-primary); }
.chat-role-badge--senior   { background: rgba(244, 201, 93, 0.12); color: #8a5a10; }
.chat-role-badge--caregiver{ background: rgba(122, 184, 127, 0.15); color: #386b3c; }
.chat-role-badge--doctor   { background: rgba(106, 167, 200, 0.18); color: #1f5d7f; }

/* ─── System message (in group: "Marie byla přidána") ─────── */
.chat-message-row--system {
    align-self: center;
    max-width: 88%;
}

.chat-message-bubble--system {
    align-self: center;
    max-width: 100%;
    background: rgba(255, 255, 255, 0.75);
    border: 1px dashed var(--radim-border-strong);
    border-radius: 12px;
    padding: 7px 14px;
    font-size: 0.85rem;
    color: var(--radim-text-soft);
    font-style: italic;
    text-align: center;
    margin: 8px auto;
    box-shadow: none;
}

.chat-message-bubble--announcement {
    background: linear-gradient(135deg, var(--radim-accent-soft) 0%, #fbe8b7 100%);
    border: 1px solid var(--radim-accent);
    border-radius: 14px;
    color: #5a3f08;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-style: normal;
    max-width: 92%;
    text-align: left;
    box-shadow: var(--radim-shadow-sm);
}

.chat-message-bubble--announcement::before {
    content: '📢 ';
    font-weight: 700;
}

/* ─── Pinned messages strip (above messages area) ───────────── */
.chat-pinned-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: linear-gradient(to right, var(--radim-accent-soft), transparent 80%);
    border-bottom: 1px solid var(--radim-border);
    cursor: pointer;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.chat-pinned-message:hover { background: linear-gradient(to right, #fbe8b7, transparent 80%); }

.chat-pinned-message-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--radim-accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.chat-pinned-message-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-pinned-message-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--radim-accent-deep);
}

.chat-pinned-message-text {
    font-size: 0.92rem;
    color: var(--radim-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-pinned-message-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--radim-text-muted);
    cursor: pointer;
    border-radius: 50%;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.chat-pinned-message-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--radim-text);
}

/* ─── Group info panel (slides from right) ──────────────────── */
.chat-group-info-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 92vw);
    background: var(--radim-surface);
    box-shadow: -14px 0 40px rgba(31, 52, 46, 0.16);
    z-index: 9050;
    display: flex;
    flex-direction: column;
    animation: chat-info-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
    overflow: hidden;
}

@keyframes chat-info-in {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

.chat-group-info-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 52, 46, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 9040;
    animation: chat-overlay-in 0.18s ease-out;
}

.chat-group-info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid var(--radim-border);
    background: var(--radim-panel);
}

.chat-group-info-header .chat-avatar { width: 56px; height: 56px; font-size: 1.5rem; }

.chat-group-info-title {
    flex: 1;
    min-width: 0;
}

.chat-group-info-title strong {
    font-family: var(--radim-font-serif);
    font-size: 1.15rem;
    color: var(--radim-text);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-group-info-title span {
    font-size: 0.85rem;
    color: var(--radim-text-muted);
}

.chat-group-info-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.chat-group-section {
    padding: 14px 18px 6px;
    border-bottom: 1px solid var(--radim-border);
}

.chat-group-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--radim-text-muted);
    margin-bottom: 8px;
}

.chat-group-section-desc {
    font-size: 0.95rem;
    color: var(--radim-text);
    line-height: 1.5;
    margin: 0 0 10px;
}

.chat-group-settings-item {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: var(--radim-text);
    font-size: 0.98rem;
    border-radius: 8px;
    transition: background var(--transition-fast);
}

.chat-group-settings-item:hover { background: var(--radim-primary-soft); padding-left: 6px; padding-right: 6px; }
.chat-group-settings-item-icon { font-size: 1.1rem; text-align: center; }
.chat-group-settings-item-value { color: var(--radim-text-muted); font-size: 0.88rem; }
.chat-group-settings-item--danger { color: var(--radim-danger); }
.chat-group-settings-item--danger:hover { background: rgba(217, 107, 107, 0.08); }

.chat-group-members-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-group-members-item {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px 0;
    font-size: 0.95rem;
}

.chat-group-members-item .chat-avatar { width: 40px; height: 40px; font-size: 0.95rem; }

.chat-group-members-item-name {
    display: block;
    font-weight: 600;
    color: var(--radim-text);
}

.chat-group-members-item-role {
    font-size: 0.78rem;
    color: var(--radim-text-muted);
}

.chat-admin-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    background: var(--radim-primary-soft);
    color: var(--radim-primary-deep);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    margin-left: 4px;
}

/* ─── Pinned conversation badge + muted style ────────────────── */
.chat-conversation-card--pinned .chat-contact-name::after {
    content: ' 📌';
    font-size: 0.78rem;
    opacity: 0.6;
}

.chat-conversation-card--muted {
    opacity: 0.75;
}

.chat-conversation-card--muted .chat-unread-badge {
    background: var(--radim-text-muted);
    color: var(--radim-surface);
}

.chat-conversation-card--muted .chat-contact-name::after {
    content: ' 🔕';
    font-size: 0.75rem;
    opacity: 0.55;
    margin-left: 2px;
}

/* ─── Typing indicator in list card (small dots) ─────────────── */
.chat-conversation-card .chat-list-typing {
    color: var(--radim-primary);
    font-weight: 600;
    font-style: italic;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chat-conversation-card .chat-list-typing::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--radim-primary);
    margin-right: 2px;
    box-shadow: 8px 0 0 var(--radim-primary), 16px 0 0 var(--radim-primary);
    animation: chat-list-typing-bounce 1.2s infinite ease-in-out;
}

@keyframes chat-list-typing-bounce {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 1; }
}

/* ─── Dark mode toggle button ────────────────────────────────── */
.chat-darkmode-toggle {
    position: relative;
}

.chat-darkmode-toggle[aria-pressed="true"] {
    background: var(--radim-accent-soft);
    color: var(--radim-accent-deep);
}

/* ─── Responsive tweaks for groups ────────────────────────────── */
@media (max-width: 768px) {
    .chat-group-info-panel { width: 100vw; }
    .chat-group-type-select { grid-template-columns: repeat(3, 1fr); }
    .chat-group-form { max-height: 94vh; border-radius: 14px; }
    .chat-pinned-message { padding: 8px 12px; }
    .chat-pinned-message-label { display: none; }
}

@media (max-width: 560px) {
    .chat-group-type-select { grid-template-columns: repeat(2, 1fr); }
    .chat-group-type-option { min-height: 74px; }
    .chat-group-info-header { padding: 14px; }
    .chat-header-subrow { font-size: 0.78rem; }
}

/* ═══════════════════════════════════════════════════════════════════
   SPRINT V.8 — MOBILE COMPACT + ALWAYS-LIGHT COMPOSE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    /* Compose area always light on mobile */
    .chat-composer,
    .chat-input-area {
        background: #ffffff !important;
        border-top: 1px solid rgba(26, 37, 48, 0.1) !important;
    }
    .chat-input,
    .chat-compose-input {
        background: #ffffff !important;
        color: #1a2530 !important;
    }
    .chat-input::placeholder {
        color: #8090a0 !important;
    }
    /* Compact paddings */
    .chat-composer { padding: 8px 10px !important; }
}

/* Dark mode softened (if user opts in manually) */
[data-theme="dark"] {
    --radim-bg:      #141e2a;    /* was too dark #0c1318 */
    --radim-surface: #1f2a38;    /* was #1a2530 */
}

/* ═══════════════════════════════════════════════════════════════
   v3.0 — SIMPLIFIED LAYOUT (April 2026)
   Reduce header from 8 buttons to 3 (Call/Video/More).
   Composer: smart record↔send toggle, attach menu unified under +.
   Senior-friendly: bigger touch targets, less visual noise.
   ═══════════════════════════════════════════════════════════════ */

/* Simplified header — only 3 main actions visible */
.chat-header-actions--simple {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Action buttons in simple header — bigger, clearer for seniors */
.chat-action-call,
.chat-action-video,
.chat-action-more {
    width: 44px;
    height: 44px;
    font-size: 1.4em;
    border-radius: 12px;
    transition: all .18s ease;
}

.chat-action-call {
    background: color-mix(in srgb, var(--radim-success, #5BA8A0) 12%, transparent);
    color: var(--radim-success, #5BA8A0);
}

.chat-action-call:hover {
    background: var(--radim-success, #5BA8A0);
    color: white;
    transform: translateY(-1px);
}

.chat-action-video {
    background: color-mix(in srgb, var(--radim-primary, #2e5fa8) 12%, transparent);
    color: var(--radim-primary, #2e5fa8);
}

.chat-action-video:hover {
    background: var(--radim-primary, #2e5fa8);
    color: white;
    transform: translateY(-1px);
}

.chat-action-more {
    background: color-mix(in srgb, var(--radim-text, #1a2530) 6%, transparent);
    color: var(--radim-text, #1a2530);
}

.chat-action-more:hover {
    background: color-mix(in srgb, var(--radim-text, #1a2530) 12%, transparent);
}

/* ─── More menu (replaces 5 separate header buttons) ─────────── */
.chat-more-menu {
    position: absolute;
    top: 70px;
    right: 16px;
    z-index: 100;
    background: white;
    border: 1px solid color-mix(in srgb, var(--radim-text, #1a2530) 10%, transparent);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 240px;
    max-width: 320px;
    animation: slideInFromTop 0.18s ease-out;
}

@keyframes slideInFromTop {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-more-menu.hidden {
    display: none;
}

.chat-more-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1em;
    text-align: left;
    border-radius: 10px;
    color: var(--radim-text, #1a2530);
    transition: background 0.12s ease;
}

.chat-more-menu-item:hover {
    background: color-mix(in srgb, var(--radim-primary, #2e5fa8) 8%, transparent);
}

.chat-more-menu-item:focus-visible {
    outline: 2px solid var(--radim-primary, #2e5fa8);
    outline-offset: 2px;
}

.chat-more-menu-item.is-active {
    background: color-mix(in srgb, var(--radim-success, #5BA8A0) 12%, transparent);
    color: var(--radim-success, #5BA8A0);
    font-weight: 600;
}

.chat-more-menu-icon {
    font-size: 1.3em;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.chat-more-menu-label {
    flex: 1;
    line-height: 1.3;
}

/* ─── Simplified composer ──────────────────────────────────── */
.chat-composer--simple {
    position: relative; /* anchor for attach menu */
}

/* Bigger touch targets in composer for seniors */
.chat-composer--simple .chat-icon-button {
    width: 44px;
    height: 44px;
    font-size: 1.3em;
}

.chat-composer--simple .chat-send-button {
    width: 44px;
    height: 44px;
    font-size: 1.3em;
}

/* ─── Attach menu (slide up from + button) ────────────────── */
.chat-attach-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 16px;
    z-index: 50;
    background: white;
    border: 1px solid color-mix(in srgb, var(--radim-text, #1a2530) 10%, transparent);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.16), 0 -2px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 220px;
    animation: slideInFromBottom 0.18s ease-out;
}

@keyframes slideInFromBottom {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-attach-menu.hidden {
    display: none;
}

.chat-attach-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1em;
    text-align: left;
    border-radius: 10px;
    color: var(--radim-text, #1a2530);
    transition: background 0.12s ease;
}

.chat-attach-menu-item:hover {
    background: color-mix(in srgb, var(--radim-primary, #2e5fa8) 8%, transparent);
}

.chat-attach-menu-item:focus-visible {
    outline: 2px solid var(--radim-primary, #2e5fa8);
    outline-offset: 2px;
}

.chat-attach-menu-icon {
    font-size: 1.4em;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

/* Dark mode adjustments for menus */
[data-theme="dark"] .chat-more-menu,
[data-theme="dark"] .chat-attach-menu {
    background: var(--radim-surface);
    border-color: rgba(255,255,255,0.1);
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

[data-theme="dark"] .chat-more-menu-item,
[data-theme="dark"] .chat-attach-menu-item {
    color: #e8eef1;
}

[data-theme="dark"] .chat-more-menu-item:hover,
[data-theme="dark"] .chat-attach-menu-item:hover {
    background: rgba(255,255,255,0.06);
}

/* High-contrast mode — bigger borders, clearer focus */
[data-a11y-contrast="high"] .chat-more-menu,
[data-a11y-contrast="high"] .chat-attach-menu {
    border-width: 2px;
    border-color: var(--radim-text, #000);
}

[data-a11y-contrast="high"] .chat-more-menu-item:focus-visible,
[data-a11y-contrast="high"] .chat-attach-menu-item:focus-visible {
    outline-width: 3px;
}

/* Mobile — full-width menus on small screens */
@media (max-width: 768px) {
    .chat-more-menu {
        right: 8px;
        left: 8px;
        max-width: none;
    }
    .chat-attach-menu {
        left: 8px;
        right: 8px;
        max-width: none;
    }
}

/* Big buttons mode (a11y) — even bigger touch targets */
[data-a11y-bigbtn="1"] .chat-action-call,
[data-a11y-bigbtn="1"] .chat-action-video,
[data-a11y-bigbtn="1"] .chat-action-more,
[data-a11y-bigbtn="1"] .chat-composer--simple .chat-icon-button,
[data-a11y-bigbtn="1"] .chat-composer--simple .chat-send-button {
    width: 56px;
    height: 56px;
    font-size: 1.6em;
}

[data-a11y-bigbtn="1"] .chat-more-menu-item,
[data-a11y-bigbtn="1"] .chat-attach-menu-item {
    padding: 16px 18px;
    font-size: 1.15em;
}

/* ═══════════════════════════════════════════════════════════════
   v3.1 — EXTREME SIMPLIFICATION (April 2026)
   Labels under icons. Bigger. Senior-first.
   ═══════════════════════════════════════════════════════════════ */

.chat-header-actions--minimal {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Big labeled action buttons — icon ABOVE text label */
.chat-action-big {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 64px;
    height: 56px;
    padding: 6px 10px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: transparent;
    color: var(--radim-text, #1a2530);
    font-family: inherit;
    transition: all 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.chat-action-big:hover,
.chat-action-big:focus-visible {
    transform: translateY(-1px);
    outline: 2px solid var(--radim-primary, #2e5fa8);
    outline-offset: 2px;
}

.chat-action-big:active {
    transform: translateY(0);
}

.chat-action-big-icon {
    font-size: 1.5em;
    line-height: 1;
}

.chat-action-big-label {
    font-size: 0.72em;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
}

.chat-action-big--call {
    background: color-mix(in srgb, var(--radim-success, #5BA8A0) 12%, transparent);
    color: var(--radim-success, #5BA8A0);
}

.chat-action-big--call:hover {
    background: var(--radim-success, #5BA8A0);
    color: white;
}

.chat-action-big--video {
    background: color-mix(in srgb, var(--radim-primary, #2e5fa8) 12%, transparent);
    color: var(--radim-primary, #2e5fa8);
}

.chat-action-big--video:hover {
    background: var(--radim-primary, #2e5fa8);
    color: white;
}

.chat-action-big--more {
    background: color-mix(in srgb, var(--radim-text, #1a2530) 6%, transparent);
}

.chat-action-big--more:hover {
    background: color-mix(in srgb, var(--radim-text, #1a2530) 14%, transparent);
}

/* Bigger attach menu items — labels visible */
.chat-attach-menu-item--big {
    padding: 16px 18px;
    font-size: 1.05em;
    min-height: 56px;
}

.chat-attach-menu-item--big .chat-attach-menu-icon {
    font-size: 1.6em;
    width: 40px;
}

.chat-attach-menu-label {
    font-weight: 500;
}

/* Mobile: stack labels under icons more compactly */
@media (max-width: 768px) {
    .chat-action-big {
        min-width: 56px;
        height: 52px;
        padding: 4px 8px;
    }
    .chat-action-big-icon {
        font-size: 1.3em;
    }
    .chat-action-big-label {
        font-size: 0.68em;
    }
}

/* Big buttons mode (a11y) — even more massive */
[data-a11y-bigbtn="1"] .chat-action-big {
    min-width: 80px;
    height: 72px;
    padding: 8px 14px;
}

[data-a11y-bigbtn="1"] .chat-action-big-icon {
    font-size: 1.8em;
}

[data-a11y-bigbtn="1"] .chat-action-big-label {
    font-size: 0.85em;
}

/* Dark mode */
[data-theme="dark"] .chat-action-big {
    color: #e8eef1;
}

[data-theme="dark"] .chat-action-big--more {
    background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .chat-action-big--more:hover {
    background: rgba(255,255,255,0.12);
}

/* ═══════════════════════════════════════════════════════════════
   v3.2 — Simplified list panel header
   - Replaces 4 small icons with 1 primary button + overflow
   ═══════════════════════════════════════════════════════════════ */

.chat-list-header-actions--simple {
    gap: 8px;
}

/* Primary action — "Nová zpráva" — solid filled, stands out */
.chat-action-big--new {
    background: var(--radim-primary, #2e5fa8);
    color: white;
    box-shadow: 0 2px 8px rgba(46, 95, 168, 0.25);
}

.chat-action-big--new:hover,
.chat-action-big--new:focus-visible {
    background: var(--radim-primary-deep, #1f4378);
    color: white;
    box-shadow: 0 4px 12px rgba(46, 95, 168, 0.35);
}

[data-theme="dark"] .chat-action-big--new {
    background: var(--radim-primary, #4a7fc7);
    color: white;
}

[data-theme="dark"] .chat-action-big--new:hover {
    background: var(--radim-primary-deep, #2e5fa8);
}

/* Overflow menu anchored to list panel header (left side of layout) */
.chat-more-menu--list {
    top: 70px;
    left: 16px;
    right: auto;
    min-width: 220px;
}

@media (max-width: 768px) {
    .chat-more-menu--list {
        left: 8px;
        right: 8px;
        min-width: 0;
    }
}

[data-theme="dark"] .chat-more-menu--list {
    background: #1a2530;
    border-color: rgba(255,255,255,0.1);
    color: #e8eef1;
}

[data-theme="dark"] .chat-more-menu--list .chat-more-menu-item {
    color: #e8eef1;
}

[data-theme="dark"] .chat-more-menu--list .chat-more-menu-item:hover {
    background: rgba(74, 127, 199, 0.2);
}
