/**
 * Customer Messages Page Styles
 * Veranda Market - Customer Inbox
 */

/* ===================================
   CSS Variables
   =================================== */
:root {
    --primary-color: #2ecc71;
    --primary-dark: #27ae60;
    --primary-light: #a8e6cf;
    --secondary-color: #3498db;
    --accent-color: #f39c12;
    --danger-color: #e74c3c;

    --text-primary: #1a1a2e;
    --text-secondary: #666;
    --text-muted: #999;
    --text-light: #fff;

    --bg-primary: #f8f9fa;
    --bg-white: #fff;
    --bg-dark: #1a1a2e;

    --border-color: #e0e0e0;
    --border-light: #f0f0f0;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;

    --header-height: 60px;

    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
}

/* ===================================
   Reset & Base
   =================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===================================
   Header
   =================================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
}

.header .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.back-link:hover {
    color: var(--primary-color);
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.logo-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.logo-accent {
    color: var(--primary-color);
}

.header-spacer {
    width: 80px;
}

/* ===================================
   Main Content
   =================================== */
.messages-main {
    flex: 1;
    padding-top: var(--header-height);
}

.messages-main .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
}

/* Page Header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===================================
   Messages Wrapper
   =================================== */
.messages-wrapper {
    flex: 1;
    display: grid;
    grid-template-columns: 350px 1fr;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    min-height: 0;
}

/* ===================================
   Conversations Sidebar
   =================================== */
.conversations-sidebar {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.conversations-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conversations-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.unread-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-light);
    position: relative;
}

.conversation-item:hover {
    background: var(--bg-primary);
}

.conversation-item.active {
    background: rgba(46, 204, 113, 0.1);
}

.conversation-item.unread {
    background: rgba(52, 152, 219, 0.05);
}

.conversation-item.unread .provider-name {
    font-weight: 600;
}

.conversation-item.unread .last-message {
    font-weight: 500;
    color: var(--text-primary);
}

.conversation-avatar {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.conversation-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border: 2px solid var(--bg-white);
    border-radius: var(--radius-full);
}

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

.conversation-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.15rem;
}

.provider-name {
    font-size: 0.95rem;
}

.conversation-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.provider-profession {
    display: block;
    font-size: 0.8rem;
    color: var(--primary-color);
    margin-bottom: 0.35rem;
}

.last-message {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===================================
   Chat Section
   =================================== */
.chat-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.back-to-list {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
}

.provider-info-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    flex: 1;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-provider-info {
    display: flex;
    flex-direction: column;
}

.chat-provider-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.chat-provider-profession {
    font-size: 0.8rem;
    color: var(--primary-color);
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-action {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--bg-primary);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.chat-action:hover {
    background: var(--primary-color);
    color: white;
}

.chat-action.whatsapp:hover {
    background: #25d366;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.date-divider {
    text-align: center;
    padding: 0.5rem 0;
}

.date-divider span {
    background: var(--bg-primary);
    padding: 0.35rem 1rem;
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.message {
    max-width: 75%;
}

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

.message-content {
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-lg);
}

.message.sent .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received .message-content {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-content p {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    line-height: 1.5;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    display: block;
    text-align: right;
}

/* Chat Input */
.chat-input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-light);
    background: var(--bg-white);
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-primary);
    border-radius: 30px;
    padding: 0.5rem;
}

.attach-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    transition: color var(--transition-fast);
}

.attach-btn:hover {
    color: var(--text-primary);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    padding: 0.5rem;
    outline: none;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.send-btn:hover {
    background: var(--primary-dark);
}

/* ===================================
   Empty States
   =================================== */
.chat-empty,
.no-conversations {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.empty-content {
    text-align: center;
    color: var(--text-muted);
}

.empty-content i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.empty-content h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.empty-content p {
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* ===================================
   Access Modal
   =================================== */
.access-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.access-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.access-modal-content {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.access-icon {
    width: 80px;
    height: 80px;
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1.5rem;
}

.access-modal-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.access-modal-content > p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.access-form {
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.phone-input-wrapper {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.country-code {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.flag-icon {
    width: 20px;
    height: 14px;
    object-fit: cover;
    border-radius: 2px;
}

.phone-input-wrapper input {
    flex: 1;
    border: none;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    outline: none;
}

.field-error {
    display: block;
    font-size: 0.8rem;
    color: var(--danger-color);
    text-align: left;
    margin-top: 0.5rem;
}

.access-note {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===================================
   Buttons
   =================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-full {
    width: 100%;
}

/* ===================================
   Toast
   =================================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-dark);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    z-index: 3000;
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
}

.toast i {
    color: var(--primary-color);
    font-size: 1.25rem;
}

.toast.error i {
    color: var(--danger-color);
}

/* ===================================
   Responsive Styles
   =================================== */
@media (max-width: 992px) {
    .messages-wrapper {
        grid-template-columns: 1fr;
    }

    .conversations-sidebar {
        border-right: none;
    }

    .chat-section {
        display: none;
        position: fixed;
        inset: 0;
        top: 0;
        background: var(--bg-white);
        z-index: 500;
    }

    .chat-section.active {
        display: flex;
    }

    .back-to-list {
        display: block;
    }

    .chat-empty {
        display: none;
    }
}

@media (max-width: 768px) {
    .messages-main .container {
        padding: 1rem;
    }

    .page-header {
        margin-bottom: 1rem;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

    .messages-wrapper {
        border-radius: var(--radius-md);
    }

    .conversations-header {
        padding: 1rem;
    }

    .conversation-item {
        padding: 0.875rem 1rem;
    }

    .conversation-avatar {
        width: 48px;
        height: 48px;
    }

    .chat-header {
        padding: 0.875rem 1rem;
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-input-area {
        padding: 0.75rem 1rem;
    }

    .message {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .header .container {
        padding: 0 1rem;
    }

    .back-link span {
        display: none;
    }

    .header-spacer {
        width: 40px;
    }

    .chat-actions {
        gap: 0.25rem;
    }

    .chat-action {
        width: 36px;
        height: 36px;
    }

    .access-modal-content {
        padding: 1.5rem;
    }
}
