@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root { 
    --bg-chat: #EFEAE2; 
    --bubble-user: #D9FDD3; 
    --bubble-grandma: #FFFFFF; 
    
    /* SilverKey Brand Palette */
    --text-main: #3D4658; /* Dark Gray */
    --accent: #FF6F15;    /* Orange */
    --header-bg: #F7F7F5; /* Light Gray */
    --border: #c3c6cb;    /* Gray 100 */
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Cairo', sans-serif; -webkit-tap-highlight-color: transparent; }

body { 
    background: #e1e1df; 
    display: flex; 
    flex-direction: column; 
    /* Fallback for older browsers */
    min-height: 100vh; 
    /* Modern mobile browsers */
    min-height: 100dvh; 
    padding-bottom: 54px; /* Space for the sk-bottom-nav */
}

.main-wrapper { 
    flex: 1 1 auto; 
    width: 100%; 
    display: flex; 
    flex-direction: column; /* Stacks header and chat */
    justify-content: center; 
    align-items: center; 
    padding: 40px 20px; 
    /* CRITICAL FIX: Prevents flex children from expanding infinitely on mobile */
    min-height: 0; 
}

/* --- New Header Styles --- */
header { text-align: center; margin-bottom: 24px; max-width: 500px; width: 100%; flex-shrink: 0; }
header h1 { font-size: clamp(28px, 5vw, 36px); margin-bottom: 8px; font-weight: 800; color: var(--accent); }
header p { color: var(--text-main); font-size: clamp(14px, 3vw, 16px); font-weight: 500; opacity: 0.8; }

.chat-layout { 
    width: 100%; 
    /* Strict height ensures the internal scrollbar always works */
    height: 75vh; 
    min-height: 500px; 
    max-height: 850px; 
    max-width: 500px; 
    background: var(--bg-chat); 
    display: flex; flex-direction: column; 
    position: relative; 
    box-shadow: 0 10px 30px rgba(61,70,88,0.1); 
    border-radius: 20px; 
    overflow: hidden;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-header { background: var(--header-bg); padding: 10px 16px; display: flex; align-items: center; gap: 12px; z-index: 10; border-bottom: 1px solid var(--border); }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); transition: 0.3s; }
.status-info h2 { font-size: 17px; color: var(--text-main); font-weight: 700; }
.status-info p { font-size: 13px; font-weight: 600; }
.online { color: #10B981; }
.typing { color: var(--accent); font-weight: 700; }

.chat-messages { 
    flex: 1 1 auto; 
    padding: 16px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    scroll-behavior: smooth; 
    /* CRITICAL FIX: Enables buttery smooth hardware-accelerated scrolling on iOS Safari */
    -webkit-overflow-scrolling: touch; 
}

.message { display: flex; flex-direction: column; max-width: 85%; animation: slideUp 0.3s ease-out; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.grandma { align-self: flex-start; align-items: flex-start; }

.bubble { padding: 8px 12px; border-radius: 16px; font-size: 15px; font-weight: 500; line-height: 1.4; color: var(--text-main); box-shadow: 0 1px 2px rgba(0,0,0,0.1); position: relative; }
.message.user .bubble { background: var(--bubble-user); border-bottom-right-radius: 4px; }
.message.grandma .bubble { background: var(--bubble-grandma); border-top-left-radius: 4px; }
.bubble.image { padding: 4px; background: transparent; box-shadow: none; border-radius: 16px; }
.bubble.image img { width: 100%; max-width: 280px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.15); display: block; }

.chat-input-area { background: var(--header-bg); padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border); }
.text-input { flex: 1; padding: 12px 16px; border-radius: 24px; border: 1px solid var(--border); outline: none; background: #fff; font-size: 15px; font-weight: 500; }
.text-input:disabled { background: #fff; color: #888; }
.icon-btn { background: transparent; border: none; color: var(--text-main); cursor: pointer; padding: 8px; display: flex; align-items: center; justify-content: center; transition: 0.2s; border-radius: 50%; }
.icon-btn:active { background: var(--border); transform: scale(0.9); }
.disabled-look { opacity: 0.5; }

.typing-dots { display: flex; gap: 5px; padding: 12px 16px; background: var(--bubble-grandma); border-radius: 16px; border-top-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.dot { width: 7px; height: 7px; background: #888; border-radius: 50%; animation: bounce 1.4s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

/* Grid styles inside the new attachment modal */
.upload-btn { background: var(--header-bg); text-align: center; padding: 16px; border-radius: 16px; cursor: pointer; font-weight: 700; color: var(--accent); display: block; border: 2px dashed var(--border); font-size: 16px; margin-bottom: 16px; }
.upload-btn:active { background: #e0e6e4; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
.card { border-radius: 12px; overflow: hidden; cursor: pointer; position: relative; border: 2px solid transparent; background: #eee; aspect-ratio: 1; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card:active { border-color: var(--accent); opacity: 0.8; }

@keyframes slideUp { from { opacity: 0; transform: translateY(15px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); } }

/* --- Mobile Responsiveness --- */
@media (max-width: 600px) {
    .main-wrapper { 
        padding: 16px; 
        justify-content: flex-start; /* Prevents header from being cut off on tiny screens */
    }
    header { 
        margin-bottom: 16px; 
    }
    .chat-layout { 
        /* Adjusted the negative offset from 180px to 260px to leave room for the new header */
        height: calc(100dvh - 260px); 
        min-height: 400px; 
        max-height: none; 
        max-width: 100%; 
        border-radius: 16px; 
    }
    .chat-header { padding-top: calc(10px + env(safe-area-inset-top)); }
}
