/* =========================================
   1. CORE VARIABLES & RESET
   ========================================= */
:root {
    /* Brand & Functional Colors */
    --primary: #0d6efd;
    --secondary: #6c757d;
    --success: #198754;
    --info: #0dcaf0;
    --warning: #ffc107;
    --danger: #dc3545;
    --light: #f8f9fa;
    --dark: #212529;

    /* Theme Colors */
    --bg-body: #f4f7f6;
    --bg-card: #ffffff;
    --border-color: #e0e5eb;
    --text-main: #495057;
    --text-muted: #6c757d;

    /* Spacing & Shapes */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.09);
    --shadow-hover: 0 4px 10px rgba(0, 0, 0, 0.08);
}

body {
    padding-top: 0px;
    background-color: var(--bg-body);
    font-family: 'Segoe UI', Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-main);
}

/* =========================================
   2. LAYOUT & CONTAINERS
   ========================================= */
.container-replies-list {
    background-color: var(--bg-card);
    padding: 10px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin: 0 auto;
    position: relative;
    min-height: 80vh; /* Better than fixed 1000px */
}

h1.page-title {
    color: #2c3e50;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 30px;
    font-weight: 600;
    font-size: 1.75rem;
}

/* =========================================
   3. COMPONENTS: FILTERS & FORMS
   ========================================= */
.filter-form {
    background-color: var(--light);
    padding: 20px 25px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.filter-form .form-select,
.filter-form .form-control,
.filter-form .btn {
    font-size: 0.875rem;
    height: 38px; /* Consistent height */
}

.filter-form .form-select { min-width: 180px; }
.filter-form .form-control { min-width: 200px; }
.filter-form .btn i { margin-right: 5px; }

/* =========================================
   4. DATA TABLE STYLES
   ========================================= */
.table-responsive {
    /* Modern scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
    min-height: 400px;
}

.table {
    border-collapse: separate;
    border-spacing: 0 8px; /* Row spacing */
    width: 100%;
    margin-bottom: 20px;
}

/* Header Styling */
.table thead th {
    background-color: #e9ecef;
    color: #343a40;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 18px;
    border: none;
    border-top: 1px solid #dee2e6;
}
.table thead th:first-child { border-top-left-radius: var(--radius-md); padding-left: 25px; }
.table thead th:last-child { border-top-right-radius: var(--radius-md); padding-right: 25px; }

/* Row Styling */
.table tbody tr.main-row {
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.table tbody tr.main-row:hover {
    background-color: #fafbfc;
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
    z-index: 2;
    position: relative;
}

/* Cell Styling */
.table tbody tr.main-row td {
    padding: 12px 18px;
    vertical-align: middle;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

/* Rounded corners for the row appearance */
.table tbody tr.main-row td:first-child {
    border-left: 1px solid var(--border-color);
    border-top-left-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-md);
    padding-left: 25px;
}
.table tbody tr.main-row td:last-child {
    border-right: 1px solid var(--border-color);
    border-top-right-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    padding-right: 25px;
    text-align: right;
}

/* Subject Line Link */
.subject-snippet {
    cursor: pointer;
    max-width: 350px;
}
.subject-snippet strong {
    display: block;
    color: var(--primary);
    margin-bottom: 2px;
}
.subject-snippet:hover strong {
    text-decoration: underline;
    color: #0a58ca;
}

/* =========================================
   5. BADGES & SENTIMENT SYSTEM
   ========================================= */
.badge {
    padding: 0.45em 0.8em;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.75em;
    letter-spacing: 0.3px;
    text-transform: capitalize;
    vertical-align: middle;
    color: #fff; /* Default text color */
}

/* --- Optimized Grouping for Background Colors --- */

/* Greens (Success/Positive) */
.badge.bg-interested, .badge.bg-new_lead, .badge.bg-converted, .badge.bg-won,
.badge.bg-replied_to, .badge.bg-dm_reached_awaiting_quote, .badge.bg-customer {
    background-color: var(--success) !important;
}

/* Reds (Danger/Negative) */
.badge.bg-not_interested, .badge.bg-lost, .badge.bg-bounced, .badge.bg-spam,
.badge.bg-do_not_contact, .badge.bg-bad_credit, .badge.bg-ai_reply_failed,
.badge.bg-deleted, .badge[class*="bg-lost_"] {
    background-color: var(--danger) !important;
}

/* Oranges/Yellows (Warning/Pending) */
.badge.bg-needs_review, .badge.bg-warm, .badge.bg-warm_lead,
.badge.bg-has_freight_dm_not_reached {
    background-color: #fd7e14 !important; /* Orange */
}
.badge.bg-ai_reply_pending, .badge.bg-paperwork_received,
.badge.bg-unsubscribe, .badge.bg-our_rates_are_to_high_every_time {
    background-color: var(--warning) !important;
    color: #000 !important; /* Dark text for readability */
}

/* Blues/Cyans (Info/Neutral) */
.badge.bg-new, .badge.bg-follow_up, .badge.bg-in_progress, .badge.bg-small_parcel {
    background-color: var(--primary) !important;
}
.badge.bg-question, .badge.bg-auto_reply, .badge.bg-currently_quoting_awaiting_business,
.badge.bg-replied_to, .badge[class*="bg-auto_fwd_"] {
    background-color: var(--info) !important;
    color: #000 !important;
}

/* Greys/Purples (Other) */
.badge.bg-cold, .badge.bg-cold_lead, .badge.bg-reviewed { background-color: #607d8b !important; }
.badge.bg-archived, .badge.bg-unknown, .badge.bg-null { background-color: #adb5bd !important; }
.badge.bg-ai_reply, .badge.bg-replied_to_ai { background-color: #6f42c1 !important; } /* Purple */

/* Special Styles */
.badge.sentiment-unsubscribe { text-decoration: line-through; }

/* AI Indicator */
.ai-indicator {
    font-size: 0.75em;
    font-style: italic;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.ai-indicator-replied { color: #6f42c1; }
.ai-indicator-pending { color: #d39e00; }
.ai-indicator-failed { color: var(--danger); }

/* =========================================
   6. INTERACTIVE ELEMENTS (Dropdowns & Buttons)
   ========================================= */

/* Clickable Cell Logic */
.clickable-dropdown-cell { position: relative; }
.dropdown-toggle-content {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}
.dropdown-toggle-content:hover { background-color: #e9ecef; }
.dropdown-toggle-content .fa-caret-down { margin-left: 8px; opacity: 0.6; }

/* Custom Dropdown Menu */
.dropdown-menu {
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-md);
    padding: 6px 0;
    max-height: 300px;
    overflow-y: auto;
}
.dropdown-menu-sm .dropdown-item {
    font-size: 0.85rem;
    padding: 6px 16px;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.dropdown-item:hover, .dropdown-item:focus {
    background-color: #e9ecef; /* Light grey instead of harsh blue */
    color: var(--primary);
}
.dropdown-item.active {
    background-color: var(--primary);
    color: #fff;
}

/* Color Circle in Dropdown */
.color-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Action Buttons */
.action-buttons { display: flex; gap: 6px; justify-content: flex-end; }
.btn-icon-only { padding-left: 0.6rem; padding-right: 0.6rem; }

/* Inverted Hover Effects */
.btn-success:hover { color: var(--success); background: transparent; border-color: var(--success); }
.btn-info:hover { color: var(--info); background: transparent; border-color: var(--info); }
.btn-danger:hover { color: var(--danger); background: transparent; border-color: var(--danger); }

/* =========================================
   7. MODAL & EMAIL THREAD STYLING
   ========================================= */
.modal-content {
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.modal-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

.modal-body { padding: 1.5rem; }
.modal-body textarea {
    border-radius: var(--radius-md);
    border: 1px solid #ced4da;
    padding: 12px;
    transition: all 0.2s;
    min-height: 150px;
}
.modal-body textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.modal-footer {
    background: #f8f9fa;
    border-top: 1px solid var(--border-color);
}

/* Email Thread Layout */
.email-thread-container {
    background-color: #f9fafb;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message-bubble {
    padding: 15px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    max-width: 92%;
    font-size: 0.95rem;
    line-height: 1.5;
}

.message-bubble.received {
    background-color: #e7f1ff; /* Very light blue */
    border-color: #cce5ff;
    align-self: flex-start;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Quoted Text */
.reply-snippet-bubble {
    background-color: rgba(0,0,0,0.03);
    border-left: 3px solid var(--border-color);
    padding: 8px 12px;
    margin-top: 10px;
    font-size: 0.9em;
    color: var(--text-muted);
}