/* ============================================
   CORPCHAT - Design System
   Mensageria Corporativa
   ============================================ */

:root {
    --wine: #7B1E2B;
    --wine-dark: #5C1320;
    --wine-light: #A52A3A;
    --wine-10: rgba(123,30,43,.1);
    --wine-20: rgba(123,30,43,.2);
    
    --bg-light: #F8F5F6;
    --bg-chat: #EDE8EA;
    --bg-sidebar: #FFFFFF;
    --white: #FFFFFF;
    --border: #E5E1E3;
    --border-light: #F0ECED;
    
    --text-dark: #2A1A1F;
    --text-body: #4A3A40;
    --text-muted: #8A7A80;
    --text-light: #B0A5AA;
    
    --bubble-sent: #7B1E2B;
    --bubble-sent-text: #FFFFFF;
    --bubble-received: #FFFFFF;
    --bubble-received-text: #2A1A1F;
    
    --online: #22C55E;
    --away: #F59E0B;
    --busy: #EF4444;
    --offline: #9CA3AF;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: .2s ease;
}

/* Dark Mode */
[data-theme="dark"] {
    --bg-light: #1A1214;
    --bg-chat: #221A1D;
    --bg-sidebar: #2A1E22;
    --white: #2A1E22;
    --border: #3D3035;
    --border-light: #352A2E;
    --text-dark: #F0E8EB;
    --text-body: #D0C5CA;
    --text-muted: #8A7A80;
    --bubble-received: #352A2E;
    --bubble-received-text: #F0E8EB;
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background: var(--bg-light);
    color: var(--text-body);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
input, textarea, select { font-family: inherit; }

/* ============================================
   APP LAYOUT
   ============================================ */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 100%;
    max-width: 100%;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
    transition: transform var(--transition);
}
.sidebar.hidden-mobile {
    transform: translateX(-100%);
    position: absolute;
    height: 100%;
}

/* Sidebar Header */
.sidebar-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--wine);
    color: #fff;
    min-height: 64px;
}
.sidebar-header .user-info {
    display: flex;
    align-items: center;
    gap: .75rem;
}
.sidebar-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid rgba(255,255,255,.3);
}
.sidebar-header .user-name {
    font-weight: 700;
    font-size: .95rem;
}
.sidebar-header .actions {
    display: flex;
    gap: .5rem;
}
.sidebar-header .actions button {
    background: rgba(255,255,255,.15);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    color: #fff;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.sidebar-header .actions button:hover {
    background: rgba(255,255,255,.25);
}

/* Search */
.sidebar-search {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-search input {
    width: 100%;
    padding: .7rem 1rem .7rem 2.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-light);
    font-size: .9rem;
    color: var(--text-dark);
    transition: border-color var(--transition);
}
.sidebar-search input:focus {
    border-color: var(--wine);
    outline: none;
}
.sidebar-search .wrap {
    position: relative;
}
.sidebar-search .icon {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: .9rem;
}

/* Chat List */
.chat-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.chat-item {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .85rem 1rem;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border-light);
    position: relative;
}
.chat-item:hover { background: var(--wine-10); }
.chat-item.active { background: var(--wine-10); border-left: 3px solid var(--wine); }
.chat-item.pinned { background: rgba(245,158,11,.05); }
.chat-item .avatar-wrap {
    position: relative;
    flex-shrink: 0;
}
.chat-item .avatar {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--border);
}
.chat-item .presence-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    border: 2px solid var(--bg-sidebar);
}
.chat-item .presence-dot.online { background: var(--online); }
.chat-item .presence-dot.away { background: var(--away); }
.chat-item .presence-dot.busy { background: var(--busy); }
.chat-item .presence-dot.offline { background: var(--offline); }
.chat-item .chat-info {
    flex: 1;
    min-width: 0;
}
.chat-item .chat-name {
    font-weight: 600;
    font-size: .95rem;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-item .chat-preview {
    font-size: .85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-item .chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.chat-item .chat-time {
    font-size: .75rem;
    color: var(--text-muted);
}
.chat-item .unread-badge {
    background: var(--wine);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   CHAT AREA
   ============================================ */
.chat-area {
    flex: 1;
    display: none;
    flex-direction: column;
    background: var(--bg-chat);
    position: relative;
}
.chat-area.active {
    display: flex;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    min-height: 64px;
    box-shadow: var(--shadow-sm);
}
.chat-header .btn-back {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--wine);
    padding: .25rem;
    display: flex;
}
.chat-header .avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    object-fit: cover;
}
.chat-header .info {
    flex: 1;
    min-width: 0;
}
.chat-header .name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-dark);
}
.chat-header .status {
    font-size: .8rem;
    color: var(--online);
}
.chat-header .actions button {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    padding: .5rem;
    transition: color var(--transition);
}
.chat-header .actions button:hover {
    color: var(--wine);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    -webkit-overflow-scrolling: touch;
}

/* Message Bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeInUp .2s ease;
}
.message.sent {
    align-self: flex-end;
}
.message.received {
    align-self: flex-start;
}
.message .bubble {
    padding: .65rem .9rem;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    line-height: 1.45;
    font-size: .95rem;
}
.message.sent .bubble {
    background: var(--bubble-sent);
    color: var(--bubble-sent-text);
    border-bottom-right-radius: 4px;
}
.message.received .bubble {
    background: var(--bubble-received);
    color: var(--bubble-received-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}
.message .bubble .msg-time {
    font-size: .7rem;
    opacity: .7;
    margin-left: .5rem;
    float: right;
    margin-top: .3rem;
}
.message .bubble .msg-status {
    font-size: .65rem;
    margin-left: .2rem;
}
.message .sender-name {
    font-size: .75rem;
    font-weight: 600;
    color: var(--wine);
    margin-bottom: 2px;
}

/* Reply Preview */
.message .reply-preview {
    background: rgba(0,0,0,.08);
    border-left: 3px solid var(--wine-light);
    padding: .35rem .65rem;
    border-radius: 6px;
    margin-bottom: .35rem;
    font-size: .8rem;
}

/* Attachment */
.message .attachment {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem;
    background: rgba(0,0,0,.05);
    border-radius: var(--radius-sm);
    margin-top: .3rem;
    cursor: pointer;
}
.message .attachment .file-icon {
    font-size: 1.5rem;
}
.message .attachment .file-info .file-name {
    font-size: .85rem;
    font-weight: 600;
}
.message .attachment .file-info .file-size {
    font-size: .75rem;
    opacity: .7;
}
.message .attachment img.preview {
    max-width: 250px;
    border-radius: var(--radius-sm);
}

/* ============================================
   MESSAGE INPUT
   ============================================ */
.message-input-area {
    padding: .75rem 1rem;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: .5rem;
}
.message-input-area .attach-btn,
.message-input-area .emoji-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    padding: .5rem;
    flex-shrink: 0;
    transition: color var(--transition);
}
.message-input-area .attach-btn:hover,
.message-input-area .emoji-btn:hover {
    color: var(--wine);
}
.message-input-area .input-wrap {
    flex: 1;
    position: relative;
}
.message-input-area textarea {
    width: 100%;
    padding: .7rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--bg-light);
    resize: none;
    font-size: .95rem;
    color: var(--text-dark);
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
    transition: border-color var(--transition);
}
.message-input-area textarea:focus {
    border-color: var(--wine);
    outline: none;
}
.message-input-area .send-btn {
    width: 46px;
    height: 46px;
    background: var(--wine);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), transform .1s;
}
.message-input-area .send-btn:hover {
    background: var(--wine-dark);
}
.message-input-area .send-btn:active {
    transform: scale(.9);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.typing-indicator {
    display: none;
    padding: .35rem 1rem;
    font-size: .8rem;
    color: var(--text-muted);
    font-style: italic;
}
.typing-indicator.visible { display: block; }
.typing-dots span {
    animation: blink 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}
.empty-chat .icon { font-size: 4rem; margin-bottom: 1rem; opacity: .5; }
.empty-chat h3 { font-size: 1.25rem; color: var(--text-dark); margin-bottom: .5rem; }

/* ============================================
   UPLOAD PROGRESS
   ============================================ */
.upload-progress {
    display: none;
    padding: .5rem 1rem;
    background: var(--bg-sidebar);
}
.upload-progress.visible { display: block; }
.upload-progress .bar-bg {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.upload-progress .bar-fill {
    height: 100%;
    background: var(--wine);
    border-radius: 2px;
    transition: width .3s;
    width: 0%;
}
.upload-progress .info {
    display: flex;
    justify-content: space-between;
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

/* ============================================
   DATE SEPARATOR
   ============================================ */
.date-separator {
    text-align: center;
    margin: 1rem 0;
}
.date-separator span {
    background: var(--wine-20);
    color: var(--text-body);
    font-size: .75rem;
    padding: .3rem .8rem;
    border-radius: var(--radius-full);
    font-weight: 600;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ============================================
   DESKTOP (768px+)
   ============================================ */
@media (min-width: 768px) {
    .sidebar {
        width: 380px;
        max-width: 380px;
        min-width: 320px;
    }
    .sidebar.hidden-mobile {
        transform: none;
        position: relative;
    }
    .chat-area {
        display: flex;
    }
    .chat-header .btn-back {
        display: none;
    }
    .message {
        max-width: 60%;
    }
}
