/* ============================================
   ONWASH - Chat Feature Styles
   ============================================ */

/* ---- SCREEN: CHAT ---- */
/* NOTE: display is controlled by .screen / .screen.active in app.css */
/* ID selector must NOT set display or it overrides .screen { display:none } */
#screen-chat {
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
}

#screen-chat.active {
    display: flex !important;
    margin-top: 0 !important;
}

/* ---- Chat Header ---- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
    padding-top: calc(16px + var(--safe-top, 0px));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-header-back {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid var(--border-brand);
}

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

.chat-header-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-since {
    font-size: 11px;
    color: var(--text-second);
    margin-top: 1px;
}

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

.chat-action-btn {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-block-btn {
    background: rgba(255, 77, 109, 0.15);
    color: #ff4d6d;
    border: 1px solid rgba(255, 77, 109, 0.3);
}
.chat-block-btn:hover {
    background: rgba(255, 77, 109, 0.25);
}

.chat-unblock-btn {
    background: rgba(0, 229, 160, 0.15);
    color: var(--success);
    border: 1px solid rgba(0, 229, 160, 0.3);
}
.chat-unblock-btn:hover {
    background: rgba(0, 229, 160, 0.25);
}

/* ---- Messages Container ---- */
.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar */
.chat-messages-container::-webkit-scrollbar {
    width: 4px;
}
.chat-messages-container::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ---- Messages List ---- */
#chat-messages-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 100%;
    justify-content: flex-end;
}

/* ---- Date Divider ---- */
.chat-date-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0 6px;
    text-align: center;
}

.chat-date-divider::before,
.chat-date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.chat-date-divider span {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 500;
}

/* ---- Message Wrapper ---- */
.chat-msg-wrap {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    position: relative;
    max-width: 85%;
}

.chat-msg-wrap:hover .chat-msg-delete {
    opacity: 1;
}

.chat-msg-mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-theirs {
    align-self: flex-start;
}

/* ---- Bubble ---- */
.chat-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    max-width: 100%;
    word-break: break-word;
    position: relative;
}

.chat-bubble-mine {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 166, 255, 0.2);
}

.chat-bubble-theirs {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.chat-bubble-text {
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

.chat-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.chat-time {
    font-size: 10px;
    opacity: 0.75;
}

.chat-ticks {
    display: flex;
    align-items: center;
}

/* ---- Delete Message Button ---- */
.chat-msg-delete {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.chat-msg-delete:hover {
    background: rgba(255, 77, 109, 0.15);
    color: #ff4d6d;
    border-color: rgba(255, 77, 109, 0.3);
}

/* ---- Empty State ---- */
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    flex: 1;
}

.chat-empty-state svg {
    color: var(--text-muted);
}

.chat-empty-state p {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* ---- Block Overlay ---- */
.chat-block-overlay {
    display: none;
    position: absolute;
    bottom: 70px;
    left: 0; right: 0;
    background: rgba(255, 77, 109, 0.12);
    border-top: 1px solid rgba(255, 77, 109, 0.3);
    padding: 12px 16px;
    z-index: 20;
    align-items: center;
    gap: 8px;
}

.chat-block-overlay svg {
    color: #ff4d6d;
    flex-shrink: 0;
}

.chat-block-msg {
    font-size: 13px;
    color: #ff4d6d;
    flex: 1;
}

/* ---- Input Area ---- */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    padding-bottom: calc(10px + var(--safe-bottom, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-wrap {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 22px;
    display: flex;
    align-items: flex-end;
    padding: 8px 14px;
    transition: border-color 0.2s;
}

.chat-input-wrap:focus-within {
    border-color: var(--brand);
}

#chat-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    min-height: 20px;
    padding: 0;
}

#chat-input::placeholder {
    color: var(--text-muted);
}

#chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 166, 255, 0.3);
}

#chat-send-btn:hover {
    background: linear-gradient(135deg, var(--brand-light), var(--brand));
    transform: scale(1.05);
}

#chat-send-btn:disabled {
    opacity: 0.5;
    transform: none;
    cursor: not-allowed;
}

/* ---- SCREEN: CHAT HISTORY ---- */

.chat-history-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    padding-top: calc(16px + var(--safe-top, 0px));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-history-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

#chat-history-list {
    padding: 8px 16px;
}

/* ---- History Item ---- */
.chat-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    position: relative;
    transition: background 0.15s ease;
    border-radius: 12px;
}

.chat-history-item:hover {
    background: rgba(255,255,255,0.03);
}

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

.chat-history-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid var(--border-brand);
}

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

.chat-history-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
}

.chat-history-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chat-history-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-history-preview {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-second);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-preview-unread {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-unread-badge {
    background: var(--brand);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-blocked-label {
    font-size: 11px;
    color: #ff4d6d;
    background: rgba(255, 77, 109, 0.12);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
    display: inline-block;
}

.chat-history-delete {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: all 0.2s ease;
}

.chat-history-delete:hover {
    background: rgba(255, 77, 109, 0.12);
    border-color: rgba(255, 77, 109, 0.3);
    color: #ff4d6d;
}

/* ---- Loading State ---- */
.chat-history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-muted);
}

.chat-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.chat-history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.chat-history-empty svg {
    color: var(--text-muted);
    opacity: 0.6;
}

.chat-history-empty p {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--text-second);
}

.chat-history-empty span {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ---- Confirm Modal ---- */
#chat-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: flex-end;
    padding: 20px;
    backdrop-filter: blur(4px);
}

#chat-confirm-modal.open {
    display: flex;
}

.chat-confirm-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 24px;
    width: 100%;
    max-width: 430px;
    margin: 0 auto;
}

.chat-confirm-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.chat-confirm-body {
    font-size: 14px;
    color: var(--text-second);
    margin-bottom: 24px;
    line-height: 1.5;
}

.chat-confirm-actions {
    display: flex;
    gap: 10px;
}

.chat-confirm-cancel {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-confirm-cancel:hover {
    background: var(--bg-card);
}

.chat-confirm-ok {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-md);
    background: #ff4d6d;
    border: none;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-confirm-ok:hover {
    opacity: 0.9;
}

/* ---- Start Chat Button (in provider profile) ---- */
.pp-start-chat-section {
    margin: 16px 0 0;
}

.pp-start-chat-btn {
    width: 100%;
    padding: 16px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    border: none;
    color: white;
    font-size: 16px;
    font-weight: 700;
    font-family: var(--font-body);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 166, 255, 0.3);
    letter-spacing: 0.3px;
}

.pp-start-chat-btn:hover {
    background: linear-gradient(135deg, var(--brand-light), var(--brand));
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 166, 255, 0.4);
}

.pp-start-chat-btn:active {
    transform: translateY(0);
}

.pp-start-chat-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ---- More Screen Chat History Item ---- */
.menu-item-badge {
    background: var(--brand);
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

/* ============================================
   UNREAD MESSAGE BADGES
   Add these styles to your CSS file (app.css or chat.css)
   ============================================ */

/* Badge on bottom navigation Chat icon */
.nav-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    min-width: 18px;
    height: 18px;
    background: #ff3b30;
    color: #fff;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
    border: 2px solid #fff;
}

/* Badge in More section on Chat History item */
.more-item-badge {
    min-width: 22px;
    height: 22px;
    background: #ff3b30;
    color: #fff;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    margin-left: auto;
    margin-right: 8px;
}

/* Badge on Chat History screen title */
.screen-title-badge {
    min-width: 24px;
    height: 24px;
    background: #ff3b30;
    color: #fff;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    margin-left: 8px;
    vertical-align: middle;
}

/* Badge animation when count changes */
@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.nav-badge.pulse,
.more-item-badge.pulse,
.screen-title-badge.pulse {
    animation: badgePulse 0.4s ease;
}

/* Ensure nav item has relative positioning for badge */
.nav-item {
    position: relative;
}

/* Adjust more-item flex layout to accommodate badge */
.more-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    position: relative;
}

.more-item-icon {
    width: 24px;
    height: 24px;
    margin-right: 16px;
    flex-shrink: 0;
}

.more-item-text {
    flex: 1;
    font-size: 16px;
    color: #2c3e50;
}

.more-item-arrow {
    width: 20px;
    height: 20px;
    color: #8a9cc2;
    flex-shrink: 0;
}

/* Existing unread badge in chat history items (already in your CSS) */
.chat-unread-badge {
    min-width: 20px;
    height: 20px;
    background: #ff3b30;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    margin-left: 8px;
    flex-shrink: 0;
}

/* Make unread message preview text bold */
.chat-preview-unread {
    font-weight: 600;
    color: #2c3e50;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .nav-badge {
        min-width: 16px;
        height: 16px;
        font-size: 10px;
        top: 6px;
        right: 6px;
    }
    
    .more-item-badge {
        min-width: 20px;
        height: 20px;
        font-size: 11px;
    }
    
    .screen-title-badge {
        min-width: 22px;
        height: 22px;
        font-size: 12px;
    }
}

/* ============================================
   CARE CENTER CHAT SCREEN
   ============================================ */

/* Screen layout — same as #screen-chat */
#screen-care-chat {
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
}

#screen-care-chat.active {
    display: flex !important;
    margin-top: 0 !important;
}

/* Messages list — same structure as #chat-messages-list */
#care-chat-messages-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 100%;
    justify-content: flex-end;
}

/* Also add more breathing room to regular chat */
#chat-messages-list {
    gap: 10px;
}

/* ---- Care Send Button (polished green) ---- */
#care-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.45);
}

#care-chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(16, 185, 129, 0.60);
}

#care-chat-send-btn:active {
    transform: scale(0.93);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

#care-chat-send-btn:disabled {
    opacity: 0.5;
    transform: none;
    cursor: not-allowed;
    box-shadow: none;
}

/* ---- Upgrade regular send button too ---- */
#chat-send-btn {
    width: 44px;
    height: 44px;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 4px 16px rgba(0, 166, 255, 0.40);
}

#chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(0, 166, 255, 0.55);
}

#chat-send-btn:active {
    transform: scale(0.93);
}

/* ---- Care chat textarea input ---- */
#care-chat-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    min-height: 20px;
    padding: 0;
}

#care-chat-input::placeholder {
    color: var(--text-muted);
}

/* ---- Care chat avatar green ring ---- */
#care-chat-partner-avatar {
    border: 2px solid rgba(16, 185, 129, 0.45);
}

/* ---- Input area — more padding & gap ---- */
.chat-input-area {
    padding: 10px 14px;
    padding-bottom: calc(10px + var(--safe-bottom, 0px));
    gap: 10px;
}

/* ---- Input wrap — slightly taller, rounder ---- */
.chat-input-wrap {
    padding: 9px 16px;
    border-radius: 24px;
}

/* ---- Message bubbles — more breathing room ---- */
.chat-bubble {
    padding: 10px 14px 7px;
}

.chat-bubble-meta {
    margin-top: 4px;
    gap: 4px;
}

/* ---- Mine bubble — stronger glow ---- */
.chat-bubble-mine {
    box-shadow: 0 3px 12px rgba(0, 166, 255, 0.22);
}

/* Care mine bubble green glow applied inline via JS — shadow upgrade */
#care-chat-messages-list .chat-bubble-mine {
    box-shadow: 0 3px 12px rgba(16, 185, 129, 0.25);
}
