/* chat/chat.css */

:root {
    /* --- Light Theme Variables --- */
    --text-light: #000000;
    --text-dark: #000000;
    --text-on-primary: #ffffff;
    --text-secondary: #8e8e93;
    --background-main: #f2f2f7;
    --card-background: #ffffff;
    --border-color: #e5e5ea;
    --theme-red: #FF4D4D; /* Coral - Fixed Color */
    
    /* Bubble Colors */
    --bubble-partner-bg: #f2f2f7;
    --bubble-my-bg: #FF4D4D;
    
    /* VIP Gradient */
    --vip-gradient: linear-gradient(135deg, #FF4D4D, #FFA1A1);
    --pin-color: #f97316; /* Orange for pinned state */
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
}

body {
    background: var(--theme-red); /* Page background is now Coral */
    color: var(--text-light);
    font-family: -apple-system, BlinkMacSystemFont, "San Francisco Pro", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

/* --- Стили для chat/list.html (iOS 26 Style) --- */

.chat-list-main {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
    padding-top: 100px;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: none; 
    background: var(--background-main); /* List page keeps grey bg */
}
.chat-list-main::-webkit-scrollbar { display: none; }

.chat-list-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #000;
    padding-left: 0.5rem;
}

.chat-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-list-container .loader {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 22px;
    text-decoration: none;
    color: var(--text-light);
    background-color: var(--card-background);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04); 
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
    position: relative;
    overflow: hidden;
}
.chat-list-item:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Pinned Chat Style */
.chat-list-item.pinned {
    background-color: #fffbf0; /* Light orange tint */
    border: 1px solid rgba(249, 115, 22, 0.2);
}

.chat-item-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    background-color: #e0e0e0;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Main content column */
.chat-item-content {
    flex-grow: 1;
    min-width: 0; /* Critical for truncation */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Top Row: Name --- Badge Pin */
.chat-item-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1.2;
}

.chat-item-name {
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #000;
    margin-right: 8px;
}

/* Meta Container (Badge + Pin) */
.chat-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Bottom Row: Message --- Time */
.chat-item-row-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1.3;
}

.chat-item-last-message {
    font-size: 0.95rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    margin: 0;
    margin-right: 8px; /* Space between message and time */
}

.chat-item-time {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Status/Badge */
.unread-badge {
    background-color: var(--theme-red);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 50px;
    padding: 0 6px;
    min-width: 22px; /* Diameter reference */
    height: 22px;    /* Diameter reference */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Pin Button (Icon Style) */
.pin-chat-btn {
    width: 30px;   /* FIXED: 30px as requested */
    height: 30px;  /* FIXED: 30px as requested */
    border: none;
    background-color: transparent;
    cursor: pointer;
    /* Masking for SVG icon */
    -webkit-mask-image: url('/components/svg/svg_ui/chat_izbrannoe.svg');
    mask-image: url('/components/svg/svg_ui/chat_izbrannoe.svg');
    -webkit-mask-size: contain; mask-size: contain;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-position: center; mask-position: center;
    /* Icon Color */
    background-color: #c7c7cc; /* Default Gray */
    padding: 0;
    transition: background-color 0.2s;
    display: block;
}

.pin-chat-btn:hover {
    background-color: #aeaeb2;
}

.pin-chat-btn.pinned {
    background-color: var(--pin-color); /* Orange when pinned */
}

/* --- Header Styling Override for Chat List (Redesigned in List) --- */
#header-placeholder header {
    background: rgba(255, 77, 77, 0.95) !important; /* Brand Red */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: none !important;
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
}
#header-placeholder #header-back-btn {
    background-color: #ffffff !important;
    color: var(--theme-red) !important; /* Red Icon */
    border-radius: 50% !important;
    box-shadow: none !important;
    width: 40px !important;
    height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 1 !important;
}
#header-placeholder #header-back-btn:hover {
    background-color: #f2f2f2 !important;
}


/* --- Стили для chat/view.html (New Card Design) --- */

.chat-view-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--theme-red); /* Coral Background */
    position: relative;
}

.chat-view-header {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Space between Profile group and Back button */
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    background: transparent; /* Transparent to show Coral bg */
    flex-shrink: 0;
    z-index: 20; 
    border: none;
    color: white;
}

.header-profile-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

/* Avatar in Header */
.partner-avatar {
    width: 48px; height: 48px; border-radius: 50%;
    background-size: cover; background-position: center;
    background-color: #e0e0e0; flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.3);
    transition: border-color 0.3s;
}
/* Online status border */
.partner-avatar.online {
    border-color: #34c759; /* Green border */
    box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.2);
}

#partner-name {
    font-size: 1.2rem; font-weight: 700; color: #ffffff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Back Button (Right Aligned) */
.back-button {
    color: var(--theme-red);
    background-color: white;
    text-decoration: none;
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.back-button:active {
    transform: scale(0.95);
}
.back-button svg { width: 24px; height: 24px; fill: currentColor; }


/* --- WHITE CARD WRAPPER --- */
.chat-card-wrapper {
    flex-grow: 1;
    background: #ffffff; /* White Card Background */
    border-top-left-radius: 32px;
    border-top-right-radius: 32px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    margin-top: 10px; /* Small gap from header */
}

.chat-messages-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem;
    padding-bottom: 80px; /* Space for footer */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
    transition: padding-bottom 0.3s ease; 
}

.chat-messages-container > :first-child { margin-top: auto; }

/* DATE SEPARATOR */
.chat-date-separator {
    text-align: center;
    font-size: 0.8rem;
    color: #8e8e93;
    margin: 12px 0;
    width: 100%;
    font-weight: 500;
    user-select: none;
}

.message-item {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    width: fit-content;
    transition: transform 0.2s ease, opacity 0.2s ease;
    position: relative;
}

.message-bubble {
    padding: 0.6rem 0.8rem 0.4rem 0.8rem;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    word-break: break-word;
    line-height: 1.4;
    font-size: 1rem;
    position: relative;
    min-width: 80px; 
}

.message-text-content { margin-right: 4px; display: inline-block; }

.message-meta {
    float: right;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    margin-top: 4px;
    margin-left: 8px;
    opacity: 0.7;
    user-select: none;
}

.message-item .message-bubble { background: var(--bubble-partner-bg); color: #000; }
.message-item.my-message { align-self: flex-end; flex-direction: row-reverse; }
.message-item.my-message .message-bubble { 
    background: var(--bubble-my-bg); 
    color: var(--text-on-primary); 
    border-bottom-left-radius: 18px; 
    border-bottom-right-radius: 4px; 
}

.status-point {
    width: 6px; height: 6px;
    -webkit-mask-image: url('/components/svg/svg_ui/point.svg');
    mask-image: url('/components/svg/svg_ui/point.svg');
    -webkit-mask-size: contain; mask-size: contain;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    background-color: currentColor;
}
.status-gray { background-color: #d1d1d6; }
.status-orange { background-color: #ff9f0a; }
.status-green { background-color: #32d74b; }

.message-item.my-message .message-meta { color: rgba(255, 255, 255, 0.8); }
.message-item:not(.my-message) .message-meta { color: #8e8e93; }
.message-item.optimistic { opacity: 0.7; }

/* --- TYPING INDICATOR (NEW LAYOUT-BASED APPROACH) --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.8rem 1rem;
    background: transparent;
    
    /* Self-alignment within the flex container */
    align-self: flex-start;
    margin-left: 0.5rem; /* Align with bubbles, not edge */
    
    /* Visibility animation */
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
}

.typing-indicator.visible {
    opacity: 1;
    max-height: 50px;
    margin-bottom: 0.5rem;
    padding-top: 0.8rem;
    padding-bottom: 0.8rem;
    pointer-events: auto;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #8e8e93;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}


/* Footer inside Card - CHANGED TO TRANSPARENT */
.chat-view-footer {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 0 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    
    background: transparent; /* Transparent background */
    backdrop-filter: none;   /* No global blur */
    -webkit-backdrop-filter: none;
    
    border-top: none; /* No border */
    flex-shrink: 0;
    z-index: 20;
    pointer-events: none; /* Allow clicks through empty area */
}

.message-form {
    pointer-events: auto; /* Re-enable interactions */
    display: flex;
    align-items: center;
    gap: 0.5rem;
    
    /* Frosted Glass Effect on the Input Pill itself */
    background: rgba(242, 242, 247, 0.8); 
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    
    border-radius: 26px;
    padding: 6px 6px 6px 16px;
    border: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1); /* Shadow for float effect */
}

#message-input {
    flex-grow: 1;
    background-color: transparent;
    border: none;
    padding: 0.5rem 0;
    font-size: 1rem;
    color: #000;
    max-height: 100px;
    min-height: 40px;
    width: 100%;
}
#message-input::placeholder { color: #8e8e93; }
#message-input:focus { outline: none; }

#send-button {
    width: 40px; height: 40px;
    background: var(--theme-red);
    border: none; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: transform 0.1s ease, opacity 0.2s;
}
#send-button:active { transform: scale(0.95); }
#send-button:disabled { background-color: #d1d1d6; cursor: default; opacity: 0.7; }
#send-button img { width: 20px; height: 20px; filter: brightness(0) invert(1); margin-left: 2px; }