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

:root {
    --lilac: #9b59b6;
    --lilac-light: #d2b4de;
    --lilac-dark: #7d3c98;
    --bg: #f5f3f7;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #e8e0ed;
    --inbound-bg: #e8e0ed;
    --outbound-bg: #9b59b6;
    --outbound-text: #ffffff;
    --success: #27ae60;
    --warning: #e67e22;
    --danger: #e74c3c;
}

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

/* Header */
header {
    background: var(--lilac);
    color: white;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

header h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Badges */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.available {
    background: var(--success);
    color: white;
}

.badge.away {
    background: var(--warning);
    color: white;
}

/* Buttons */
.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-sm {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Tab navigation */
.tab-nav {
    display: flex;
    gap: 0;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 12px 20px 0;
}

.tab-btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--bg);
    color: var(--text-light);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    transition: all 0.15s;
}

.tab-btn.active {
    background: var(--card-bg);
    color: var(--lilac-dark);
    border-color: var(--lilac-light);
}

.tab-btn:hover:not(.active) {
    background: var(--lilac-light);
    color: var(--lilac-dark);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.stat {
    flex: 1;
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--lilac);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Content area */
.content-area {
    display: flex;
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 0 20px 20px;
    gap: 16px;
    min-height: 0;
}

/* Conversation list */
.conversation-list {
    width: 340px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
}

.list-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.list-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
}

#conversations {
    overflow-y: auto;
    flex: 1;
}

.conv-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

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

.conv-item.active {
    background: var(--lilac-light);
    border-left: 3px solid var(--lilac);
}

.conv-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.conv-preview {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.7rem;
    color: var(--text-light);
}

.conv-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--lilac-light);
    color: var(--lilac-dark);
}

/* Message thread */
.message-thread {
    flex: 1;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
}

.thread-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.thread-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
}

.thread-header .customer-info {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 2px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-bubble.inbound {
    align-self: flex-start;
    background: var(--inbound-bg);
    border-bottom-left-radius: 4px;
}

.message-bubble.outbound {
    align-self: flex-end;
    background: var(--outbound-bg);
    color: var(--outbound-text);
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-light);
    margin-top: 2px;
}

.message-bubble.outbound .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.message-status {
    font-size: 0.65rem;
    opacity: 0.7;
}

/* Context panel */
.thread-context {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-light);
    background: var(--bg);
    border-radius: 0 0 10px 10px;
}

/* Footer */
footer {
    padding: 8px 20px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-light);
}

.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.connection-status::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

.connection-status.connected::before {
    background: var(--success);
}

.connection-status.disconnected::before {
    background: var(--danger);
}

/* Tester program styles */
.tester-list {
    width: 400px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 260px);
    overflow-y: auto;
}

.tester-detail-panel {
    flex: 1;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 260px);
    overflow-y: auto;
}

.tester-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.tester-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tester-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.tester-status-badge {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.tester-status-badge.contacted { background: #f0e6f6; color: #7d3c98; }
.tester-status-badge.confirmed { background: #e8f5e9; color: #2e7d32; }
.tester-status-badge.draft_order_created { background: #fff3e0; color: #e65100; }
.tester-status-badge.shipped { background: #e3f2fd; color: #1565c0; }
.tester-status-badge.delivered { background: #e0f7fa; color: #00695c; }
.tester-status-badge.ranking_submitted { background: #fce4ec; color: #ad1457; }
.tester-status-badge.video_received { background: #f3e5f5; color: #6a1b9a; }
.tester-status-badge.complete { background: #e8f5e9; color: #1b5e20; }
.tester-status-badge.declined { background: #ffebee; color: #b71c1c; }

.tester-meta {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
}

.tester-indicators {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.tester-indicator {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg);
}

.tester-actions {
    margin-top: 6px;
}

.btn-followup {
    padding: 4px 10px;
    font-size: 0.7rem;
    border: 1px solid var(--lilac);
    background: white;
    color: var(--lilac);
    border-radius: 4px;
    cursor: pointer;
}

.btn-followup:hover {
    background: var(--lilac);
    color: white;
}

/* Rankings table */
.rankings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    padding: 12px;
}

.rankings-table th,
.rankings-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.rankings-table th {
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    font-size: 0.7rem;
}

.rankings-table .rank-bar {
    height: 6px;
    background: var(--lilac-light);
    border-radius: 3px;
    display: inline-block;
}

.rankings-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* Order Tracking styles */
.tracking-filters {
    display: flex;
    gap: 6px;
    padding: 0 20px 12px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.filter-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-light);
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.15s;
}

.filter-btn.active {
    background: var(--lilac);
    color: white;
    border-color: var(--lilac);
}

.filter-btn:hover:not(.active) {
    border-color: var(--lilac-light);
    color: var(--lilac-dark);
}

.shipment-list {
    width: 420px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

.timeline-panel {
    flex: 1;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

.shipment-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

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

.shipment-item.active {
    background: var(--lilac-light);
    border-left: 3px solid var(--lilac);
}

.shipment-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shipment-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.shipment-tracking {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 2px;
    font-family: monospace;
}

.shipment-meta {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 2px;
}

.tester-tag {
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--lilac-light);
    color: var(--lilac-dark);
    font-weight: 600;
}

/* Tracking status badges */
.tracking-status-badge {
    font-size: 0.6rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.tracking-status-badge.pending { background: #f5f5f5; color: #757575; }
.tracking-status-badge.pre_transit { background: #fff3e0; color: #e65100; }
.tracking-status-badge.in_transit { background: #e3f2fd; color: #1565c0; }
.tracking-status-badge.out_for_delivery { background: #e8f5e9; color: #2e7d32; }
.tracking-status-badge.delivered { background: #e0f7fa; color: #00695c; }
.tracking-status-badge.return_to_sender { background: #ffebee; color: #b71c1c; }
.tracking-status-badge.failure { background: #ffebee; color: #b71c1c; }
.tracking-status-badge.error { background: #ffebee; color: #b71c1c; }
.tracking-status-badge.unknown { background: #f5f5f5; color: #757575; }

/* Refresh button */
.btn-refresh {
    padding: 4px 12px;
    font-size: 0.75rem;
    border: 1px solid var(--lilac);
    background: white;
    color: var(--lilac);
    border-radius: 4px;
    cursor: pointer;
}

.btn-refresh:hover {
    background: var(--lilac);
    color: white;
}

/* Timeline */
.timeline {
    padding: 16px;
}

.timeline-event {
    display: flex;
    gap: 12px;
    padding-bottom: 20px;
    position: relative;
}

.timeline-event:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 18px;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
    background: var(--border);
    border: 2px solid var(--card-bg);
    box-shadow: 0 0 0 2px var(--border);
}

.timeline-event.latest .timeline-dot {
    box-shadow: 0 0 0 2px var(--lilac);
}

.timeline-dot.order_placed { background: var(--lilac); box-shadow: 0 0 0 2px var(--lilac); }
.timeline-dot.delivered { background: #00695c; box-shadow: 0 0 0 2px #00695c; }
.timeline-dot.out_for_delivery { background: #2e7d32; box-shadow: 0 0 0 2px #2e7d32; }
.timeline-dot.in_transit { background: #1565c0; box-shadow: 0 0 0 2px #1565c0; }
.timeline-dot.pre_transit { background: #e65100; box-shadow: 0 0 0 2px #e65100; }

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-status {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: capitalize;
}

.timeline-message {
    font-size: 0.8rem;
    color: var(--text);
    margin-top: 2px;
}

.timeline-location {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 1px;
}

.timeline-time {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 2px;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .content-area {
        flex-direction: column;
        padding: 0 10px 10px;
    }

    .conversation-list {
        width: 100%;
        max-height: 35vh;
    }

    .message-thread {
        max-height: 50vh;
    }

    .stats-bar {
        padding: 10px;
        gap: 8px;
    }

    .stat {
        padding: 8px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

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

    header {
        padding: 10px 14px;
    }

    .tester-list {
        width: 100%;
        max-height: 40vh;
    }

    .tester-detail-panel {
        max-height: 45vh;
    }

    .shipment-list {
        width: 100%;
        max-height: 40vh;
    }

    .timeline-panel {
        max-height: 45vh;
    }

    .tracking-filters {
        padding: 0 10px 8px;
        flex-wrap: wrap;
    }

    .tab-nav {
        padding: 8px 10px 0;
    }
}
