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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #2c3e50, #3498db);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}

.nav-subtitle {
    font-size: 1rem;
    opacity: 0.8;
}

.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.nav-user span {
    opacity: 0.9;
}

.logout-link {
    color: white;
    opacity: 0.8;
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
}

.logout-link:hover {
    opacity: 1;
    background: rgba(255,255,255,0.1);
}

/* Main Content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

.page-header {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.75rem;
    color: #2c3e50;
}

.last-sync {
    font-size: 0.85rem;
    color: #888;
}

.btn-sync {
    margin-left: auto;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
}

.btn-sync:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sync.syncing {
    background: #3498db;
    color: white;
}

.back-link {
    display: inline-block;
    margin-bottom: 0.5rem;
    color: #3498db;
    text-decoration: none;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* Filter Panel */
.filter-panel {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
}

.filter-group input,
.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    min-width: 150px;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.filter-group-wide {
    flex: 1;
    min-width: 200px;
}

.filter-group-wide input {
    width: 100%;
}

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

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #ecf0f1;
    color: #333;
}

.btn-secondary:hover {
    background: #bdc3c7;
}

.btn-group {
    background: #fff;
    border: 1px solid #ddd;
    color: #666;
}

.btn-group:hover {
    background: #f5f5f5;
}

.btn-group.active {
    background: #3498db;
    border-color: #3498db;
    color: white;
}

/* Grouping Panel */
.grouping-panel {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.grouping-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
}

.grouping-buttons {
    display: flex;
    gap: 0.5rem;
}

.grouping-spacer {
    flex: 1;
}

/* AG Grid Container */
#messages-grid {
    height: calc(100vh - 350px);
    min-height: 400px;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Status Bar */
.status-bar {
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #666;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Direction Indicators */
.direction-inbound {
    color: #27ae60;
    font-weight: 600;
}

.direction-outbound {
    color: #3498db;
    font-weight: 600;
}

/* Conversation View */
.conversation-container {
    max-width: 800px;
}

.message-thread {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-bubble {
    background: white;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #ddd;
}

.message-bubble.inbound {
    border-left-color: #27ae60;
    margin-right: 3rem;
}

.message-bubble.outbound {
    border-left-color: #3498db;
    margin-left: 3rem;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.message-time {
    font-size: 0.8rem;
    color: #999;
}

.message-from,
.message-to {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.25rem;
}

.from-name {
    color: #999;
}

.message-content {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-status {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.status-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    background: #ecf0f1;
    color: #666;
    text-transform: uppercase;
}

.status-delivered {
    background: #d5f5e3;
    color: #27ae60;
}

.status-sent {
    background: #d6eaf8;
    color: #3498db;
}

.read-read {
    background: #e8e8e8;
    color: #666;
}

.read-unread {
    background: #fcf3cf;
    color: #f39c12;
}

.no-messages {
    text-align: center;
    padding: 3rem;
    color: #999;
}

/* AG Grid Custom Styles */
.ag-theme-alpine .conversation-link {
    color: #3498db;
    text-decoration: none;
    cursor: pointer;
}

.ag-theme-alpine .conversation-link:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .filter-row {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group input,
    .filter-group select {
        width: 100%;
    }

    .grouping-panel {
        flex-wrap: wrap;
    }

    .grouping-buttons {
        flex-wrap: wrap;
    }

    #messages-grid {
        height: calc(100vh - 450px);
    }

    .message-bubble.inbound,
    .message-bubble.outbound {
        margin-left: 0;
        margin-right: 0;
    }
}
