/* Chat na webu (stránka /Messages) – mobile first. Vzhled odpovídá chatu v mobilní aplikaci:
   plné bubliny (moje v primární barvě s bílým textem, cizí světle šedé), čas a fajfky vpravo dole
   v bublině, akce v plovoucí liště nad bublinou, vstupní lišta 📎 / emoji / pole / kulaté Odeslat. */

:root {
    --chat-mine-bg: var(--primary-color);
    --chat-mine-text: #fff;
    --chat-theirs-bg: #eceef2;
    --chat-theirs-text: #1f1f1f;
    --chat-canvas: #f6f7fa;
    --chat-radius: 18px;
    /* Výška seznamu zpráv = výška okna minus hlavička webu, hlavička karty a vstupní lišta. */
    --chat-messages-height: max(300px, calc(100dvh - 250px));
}

/* ---------- Rozvržení stránky ---------- */

.message-page-container {
    display: flex;
    flex-direction: column;
}

/* Telefon: buď seznam konverzací, nebo otevřená konverzace (jako v appce). */
.message-conversation-section {
    display: none;
}

.message-page-container.has-open .message-conversation-section {
    display: block;
}

.message-page-container.has-open .message-friends-section {
    display: none;
}

@media (min-width: 768px) {
    .message-page-container {
        flex-direction: row;
    }

    .message-friends-section,
    .message-page-container.has-open .message-friends-section {
        display: block;
        padding-right: 10px;
    }

    .message-conversation-section {
        display: block;
    }

    :root {
        --chat-messages-height: clamp(360px, calc(100dvh - 300px), 760px);
    }
}

/* ---------- Seznam konverzací ---------- */

.chat-list-card .card-header h5 {
    min-width: 0;
}

.chat-new-btn {
    flex-shrink: 0;
    height: auto;
    min-height: 32px;
    white-space: nowrap;
}

.chat-list-card .list-group-item {
    padding: 0.55rem 0.9rem;
}

.chat-list-name {
    min-width: 0;
}

.selected-friend {
    border-left: 3px solid var(--primary-color) !important;
    background-color: var(--light-primary-color-ultra-light);
}

.chat-avatar-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

/* Tečka přítomnosti v pravém dolním rohu avatara; offline = nenápadná šedá. */
.chat-avatar-wrap .presence-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background-color: #c4c4c4;
    border: 2px solid #fff;
}

.chat-avatar-wrap .presence-dot.online {
    background-color: #2ecc71;
}

.chat-group-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--secondary-color);
    color: var(--primary-color);
    font-size: 1.05rem;
}

/* ---------- Karta konverzace ---------- */

.chat-conv-card {
    position: relative;
    overflow: hidden;
}

.chat-conv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0.5rem 0.75rem;
    background: #fff;
}

.chat-conv-title {
    min-width: 0;
    flex: 1 1 auto;
}

.chat-conv-title h5 {
    font-size: 1.1rem;
    min-width: 0;
}

.chat-conv-tools {
    flex-shrink: 0;
}

.chat-conv-tools .btn {
    height: auto;
    min-height: 32px;
}

.chat-body {
    padding: 0;
    background: var(--chat-canvas);
}

.messages-container {
    height: var(--chat-messages-height);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    /* Nahoře víc místa – plovoucí lišta akcí první zprávy nesmí vyjet mimo kontejner. */
    padding: 1.6rem 0.75rem 0.75rem;
}

@media (min-width: 768px) {
    .messages-container {
        padding: 1.6rem 1.25rem 1rem;
    }
}

/* Systémová zpráva skupiny – šedý štítek uprostřed. */
.chat-system-row {
    text-align: center;
    margin: 0.4rem 0 0.9rem;
    font-size: 0.8rem;
    color: #6c757d;
}

.chat-system-row span {
    display: inline-block;
    max-width: 90%;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    padding: 3px 10px;
    overflow-wrap: anywhere;
}

/* ---------- Zpráva ---------- */

/* Řádek = bublina + lišta akcí + reakce/panely. Zarovnání vlevo (cizí) / vpravo (moje). */
.message-row {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 100%;
    margin-bottom: 0.9rem;
}

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

.message {
    position: relative;
    max-width: min(82%, 560px);
    min-width: 0;
    padding: 0.5rem 0.75rem 0.35rem;
    border-radius: var(--chat-radius);
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
    cursor: default;
}

@media (min-width: 992px) {
    .message {
        max-width: min(70%, 560px);
    }
}

.message-received {
    background-color: var(--chat-theirs-bg);
    color: var(--chat-theirs-text);
    border-bottom-left-radius: 6px;
}

.message-sent {
    background-color: var(--chat-mine-bg);
    color: var(--chat-mine-text);
    border-bottom-right-radius: 6px;
}

/* Odkazy v textu bubliny – na primární barvě bílé a podtržené. */
.message-sent .message-content a {
    color: #fff;
    text-decoration: underline;
}

.message-content {
    white-space: pre-wrap; /* zachovává odřádkování */
}

.message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}

/* Bublina jen s přílohou – tenký rámeček kolem náhledu. */
.message-media-only {
    padding: 4px 4px 0.3rem;
}

.message-media-only .message-meta {
    padding: 0 0.5rem;
}

/* Anketa má vlastní bílou kartu – bublina kolem ní jen úzký lem. */
.message-poll {
    padding: 4px 4px 0.3rem;
}

.message-poll .message-meta {
    padding: 0 0.5rem;
}

/* Karta ankety vyplní bublinu pevné šířky – na telefonu nesmí přetéct přes její okraj. */
.message.message-poll {
    width: min(360px, 82%);
}

.message-poll .poll-card {
    min-width: 0;
    width: 100%;
}

.message-sender {
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.message-sender a {
    color: inherit;
    text-decoration: none;
}

/* Čas, příznaky a fajfky – vpravo dole, při nedostatku místa se zalomí (nic nepřeteče z bubliny). */
.message-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    column-gap: 6px;
    row-gap: 0;
    margin-top: 2px;
    font-size: 0.7rem;
    line-height: 1.5;
    opacity: 0.75;
    white-space: nowrap;
}

.message-time {
    font-size: inherit;
}

.message-flag {
    font-size: inherit;
    font-style: italic;
}

.message-flag-btn {
    border: none;
    background: none;
    padding: 0;
    color: inherit;
    cursor: pointer;
    text-decoration: underline dotted;
}

.message-status {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.message-status i {
    font-size: 0.95rem;
}

/* Přečteno – zvýrazněné fajfky (na primární barvě světle tyrkysové, jako v appce). */
.message-status.is-read {
    color: #9ff0ff;
    opacity: 1;
}

/* ---------- Citace (reply) ---------- */

.message-reply-quote {
    border-left: 3px solid var(--primary-color);
    padding: 3px 8px;
    margin: 2px 0 5px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.25;
    max-width: 100%;
    overflow: hidden;
}

.message-sent .message-reply-quote {
    border-left-color: rgba(255, 255, 255, 0.85);
    background-color: rgba(255, 255, 255, 0.16);
}

.message-reply-quote .reply-quote-author {
    display: block;
    font-weight: 600;
    color: var(--primary-color);
}

.message-sent .message-reply-quote .reply-quote-author {
    color: #fff;
}

.message-reply-quote .reply-quote-text {
    display: block;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-reply-quote.unavailable {
    font-style: italic;
    opacity: 0.7;
}

/* ---------- Přílohy ---------- */

.message-media {
    margin-bottom: 2px;
}

/* Náhled fotky a videa: rozumná velikost na počítači, na telefonu do šířky bubliny. */
.chat-media-image,
.chat-media-video {
    display: block;
    width: auto;
    max-width: min(320px, 64vw);
    max-height: 340px;
    border-radius: 14px;
    background: #1a1a24;
}

.chat-media-image {
    cursor: zoom-in;
    object-fit: cover;
}

.chat-media-video {
    width: min(320px, 64vw);
}

.chat-media-audio {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-media-audio audio {
    max-width: min(240px, 58vw);
    height: 36px;
}

/* Karta souboru: ikona podle přípony, název (ořez), ikona stažení. */
.chat-file {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    max-width: min(300px, 64vw);
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.75);
    color: inherit;
    text-decoration: none;
}

.message-sent .chat-file {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.chat-file:hover {
    color: inherit;
    filter: brightness(0.97);
}

.chat-file-icon {
    font-size: 1.7rem;
    flex-shrink: 0;
}

.chat-file-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.chat-file-download {
    flex-shrink: 0;
    opacity: 0.7;
}

.chat-media-expired {
    padding: 10px;
    border: 1px dashed currentColor;
    border-radius: 10px;
    font-size: 0.85rem;
    opacity: 0.7;
}

.chat-media-expiry {
    font-style: normal;
    margin-right: auto; /* platnost vlevo, čas a fajfky vpravo */
}

/* ---------- Plovoucí lišta akcí ---------- */

.message-toolbar {
    position: absolute;
    top: -1.35rem;
    left: 0.25rem;
    z-index: 2;
    display: none;
    align-items: center;
    gap: 1px;
    padding: 2px 4px;
    background: #fff;
    border: 1px solid #e1e4ea;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.message-row.mine .message-toolbar {
    left: auto;
    right: 0.25rem;
}

/* Dotykový displej: lišta po klepnutí na bublinu. Počítač: i při najetí myší. */
.message-row.is-active .message-toolbar {
    display: inline-flex;
}

@media (hover: hover) {
    .message-row:hover .message-toolbar {
        display: inline-flex;
    }
}

.message-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: #5f6570;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
}

.message-action-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1f1f1f;
}

.message-action-btn i {
    font-size: 0.95rem;
}

.message-delete-btn:hover {
    color: #dc3545;
}

/* ---------- Reakce ---------- */

/* Pilulky reakcí přesahují spodní okraj bubliny (jako v appce). */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: -8px;
    padding: 0 10px;
    position: relative;
    z-index: 1;
}

.reaction-pill {
    background: #fff;
    border: 1px solid #d9dce2;
    border-radius: 12px;
    padding: 0 7px;
    font-size: 0.9rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.reaction-pill.mine {
    border-color: var(--primary-color);
    background: var(--light-primary-color-ultra-light);
}

/* Výběr rychlých emoji a panel nahlášení jsou záměrně v NORMÁLNÍM TOKU (ne position:absolute):
   absolutně pozicované by je .messages-container (overflow:auto) u vysokých bublin ořízl. */
.reaction-picker {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-top: 6px;
    max-width: 100%;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 4px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.reaction-emoji-btn {
    border: none;
    background: none;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 50%;
}

.reaction-emoji-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.message-report-panel {
    width: 100%;
    max-width: 320px;
    margin-top: 6px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 6px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

/* ---------- Indikátor „píše…" ---------- */

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    margin: 0 0 8px 0.75rem;
    background-color: var(--chat-theirs-bg);
    border-radius: 14px;
    width: fit-content;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #8a8a8e;
    opacity: 0.4;
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ---------- Vstupní lišta ---------- */

.chat-composer {
    padding: 0.5rem 0.6rem;
    background: #fff;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.chat-icon-btn,
.chat-input-row .emoji-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--primary-color);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}

.chat-icon-btn:hover,
.chat-icon-btn.active,
.chat-input-row .emoji-toggle-btn:hover {
    background: var(--secondary-color);
}

/* Pole zprávy roste s textem (kde to prohlížeč umí) až do stropu, pak se posouvá. */
.chat-textarea {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    max-height: 160px;
    field-sizing: content;
    resize: none;
    padding: 8px 14px;
    border: 1px solid #d5d9e0;
    border-radius: 20px;
    background: #f6f7fa;
    font-size: 1rem;
    line-height: 1.4;
    outline: none;
}

.chat-textarea:focus {
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(58, 124, 213, 0.15);
}

.chat-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-color-hover);
}

.chat-send-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* Výběr emoji ve vstupní liště: panel jako vyskakovací okno nad lištou. */
.chat-input-row .emoji-picker-wrapper {
    position: static;
}

.chat-composer {
    position: relative;
}

.chat-input-row .emoji-list-panel {
    position: absolute;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(100% - 0.25rem);
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
    background: #fff;
    border: 1px solid #e1e4ea;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.chat-input-row .emoji-list-panel .emoji {
    font-size: 1.35rem;
    padding: 3px 4px;
    border-radius: 8px;
    cursor: pointer;
}

.chat-input-row .emoji-list-panel .emoji:hover {
    background: rgba(0, 0, 0, 0.07);
}

/* Nabídka 📎 – vyskakovací seznam nad tlačítkem. */
.chat-attach-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-attach-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 6px);
    z-index: 6;
    display: flex;
    flex-direction: column;
    min-width: 230px;
    max-width: calc(100vw - 40px);
    padding: 6px;
    background: #fff;
    border: 1px solid #e1e4ea;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.chat-attach-item {
    display: block;
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    border: none;
    border-radius: 10px;
    background: none;
    text-align: left;
    font-size: 0.95rem;
    color: #1f1f1f;
    white-space: nowrap;
    cursor: pointer;
}

.chat-attach-item:hover {
    background: var(--light-primary-color-ultra-light);
    color: var(--primary-color);
}

/* Rozpracované přílohy nad polem: název, stav a průběh. */
.chat-upload {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 10px;
    background: var(--light-primary-color-ultra-light);
    border: 1px solid var(--secondary-color);
}

.chat-upload > i {
    font-size: 1.3rem;
    color: var(--primary-color);
}

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

.chat-upload-name {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.85rem;
}

.chat-upload-state {
    flex-shrink: 0;
    color: #6c757d;
}

.chat-upload-progress {
    height: 4px;
    margin-top: 4px;
    border-radius: 2px;
    background: #dde5f2;
    overflow: hidden;
}

.chat-upload-progress span {
    display: block;
    height: 100%;
    background: var(--primary-color);
    transition: width 0.2s ease;
}

/* Lišta nad polem: náhled odpovědi / režim úpravy + zavření (×). */
.compose-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    margin-bottom: 6px;
    background-color: var(--light-primary-color-ultra-light);
    border-left: 3px solid var(--primary-color);
    border-radius: 8px;
}

.compose-bar-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.compose-bar-title {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--primary-color);
}

.compose-bar-snippet {
    font-size: 0.8rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compose-bar-close {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}

.compose-bar-close:hover {
    color: #333;
}

/* ---------- Přetažení souborů ---------- */

.chat-drop-zone {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(58, 124, 213, 0.12);
    border: 3px dashed var(--primary-color);
    border-radius: inherit;
}

.chat-drop-zone.active {
    display: block;
}

.chat-drop-hint {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
    pointer-events: none;
}

.chat-drop-hint i {
    font-size: 2.6rem;
}

/* Průhledný výběr souborů přes celou plochu – upuštění na něj předá soubory Blazoru. */
.chat-drop-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: copy;
}
