/* Audiences Section Styles - Modern & Cool Design */
#audiences-section {
    position: relative;
    z-index: 2;
    display: none;
    padding-top: 90px;
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}

#audiences-section.active {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#audiences-section main {
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

.audiences-container {
    width: 100%;
    padding: 0 24px;
    box-sizing: border-box;
}

/* Header */
.audiences-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    gap: 24px;
}

.audiences-header h2 {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0 0 8px 0;
    letter-spacing: -0.02em;
}

.audiences-header p {
    font-size: 15px;
    color: #6b7280;
    margin: 0;
    line-height: 1.6;
}

/* Add Audience button in global header */
.section-buttons .add-audience-button {
    background: transparent;
    color: #6c757d;
    border: 0.5px solid #c1c1c1;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    box-shadow: none;
}

.section-buttons .add-audience-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.section-buttons .add-audience-button i {
    font-size: 16px;
}

/* Audiences Grid */
.audiences-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
    align-items: stretch;
}

/* Audience Card */
.audience-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 
        0 4px 24px rgba(0, 0, 0, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.audience-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea, #764ba2, #f093fb);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.audience-card:hover {
    transform: translateY(-4px);
    box-shadow: 
        0 12px 40px rgba(102, 126, 234, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.08);
}

.audience-card:hover::before {
    opacity: 1;
}

.audience-card-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
    position: relative;
    padding-right: 90px; /* Make room for badges in top-right */
}

.audience-avatar {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    font-size: 0; /* Hide any text content */
    line-height: 0;
}

.audience-avatar i {
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-style: normal;
    font-weight: normal;
    speak: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    color: white !important;
}

.audience-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 14px;
    display: block;
}

.audience-info {
    flex: 1;
    min-width: 0;
    padding-right: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 80px; /* Ensure consistent height for title + description area */
}

.audience-name {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0 0 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.audience-name .primary-badge {
    padding: 2px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.primary-badge.standalone {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 8px;
}

.audience-description {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 39px; /* 2 lines * 1.5 line-height * 13px = ~39px */
    max-height: 39px;
}

.audience-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.audience-meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
}

.audience-meta-item i {
    font-size: 14px;
    opacity: 0.7;
}

.audience-badges-container {
    position: absolute;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
    z-index: 1;
}

.audience-status-badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.audience-status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.audience-status-badge.inactive {
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
}

.audience-actions {
    position: absolute;
    top: 24px;
    right: 24px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 3;
}

.audience-card:hover .audience-actions {
    opacity: 1;
}

.audience-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.audience-action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.audience-action-btn.edit {
    color: #667eea;
}

.audience-action-btn.delete {
    color: #ef4444;
}

/* Empty State */
.audiences-empty-state {
    text-align: center;
    padding: 80px 24px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 2px dashed rgba(102, 126, 234, 0.2);
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 40px;
}

.audiences-empty-state h3 {
    font-size: 24px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0 0 8px 0;
}

.audiences-empty-state p {
    font-size: 15px;
    color: #6b7280;
    margin: 0 0 24px 0;
}

.add-audience-btn-empty {
    padding: 14px 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.35);
    white-space: nowrap;
    margin: 0 auto;
}

.add-audience-btn-empty:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.45);
}

.add-audience-btn-empty:active {
    transform: translateY(0);
}

/* Modal */
.audience-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    overflow-y: auto;
}

.audience-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.modal-header h3 {
    font-size: 24px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
}

.close-modal {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: rgba(0, 0, 0, 0.04);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: #6b7280;
}

.close-modal:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #1a1a2e;
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 4px;
    padding: 0 28px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    overflow-x: auto;
}

.modal-tab {
    padding: 14px 20px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.modal-tab:hover {
    color: #667eea;
}

.modal-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.modal-tab i {
    font-size: 18px;
}

/* Tab Content */
.modal-tab-content {
    padding: 28px;
    overflow-y: auto;
    flex: 1;
}

.tab-panel {
    display: none;
}

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

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    background: white;
    transition: all 0.3s ease;
    font-family: inherit;
}

.form-input:hover,
.form-select:hover {
    border-color: #667eea;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    cursor: pointer;
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

/* Avatar Upload */
.avatar-upload-container {
    margin-top: 8px;
}

.avatar-preview-container {
    width: 120px;
    height: 120px;
    border-radius: 16px;
    border: 2px dashed rgba(102, 126, 234, 0.3);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.03) 0%, rgba(118, 75, 162, 0.03) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    position: relative;
    transition: all 0.3s ease;
}

.avatar-preview-container:hover {
    border-color: rgba(102, 126, 234, 0.6);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.06) 0%, rgba(118, 75, 162, 0.06) 100%);
}

.avatar-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 14px;
}

.avatar-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 12px;
    gap: 8px;
    text-align: center;
}

.avatar-placeholder i {
    font-size: 32px;
    color: #667eea;
    opacity: 0.5;
}

.avatar-upload-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.avatar-upload-btn,
.avatar-remove-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    border: none;
}

.avatar-upload-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.avatar-upload-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.avatar-remove-btn {
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.avatar-remove-btn:hover {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}

/* Tags */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    min-height: 32px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 8px;
    font-size: 13px;
    color: #667eea;
    font-weight: 500;
}

.tag-remove {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: none;
    background: rgba(102, 126, 234, 0.2);
    color: #667eea;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 12px;
    padding: 0;
}

.tag-remove:hover {
    background: #667eea;
    color: white;
}

.tag-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    background: white;
    transition: all 0.3s ease;
}

.tag-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

/* Modal Actions */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 28px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.cancel-btn {
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.04);
    color: #374151;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.modal-actions .save-btn {
    padding: 12px 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.35);
}

.modal-actions .save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.45);
}

.modal-actions .save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Status Messages */
.audiences-status-message {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 16px 24px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 500;
    display: none;
    z-index: 1001;
    animation: slideInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.audiences-status-message.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    display: block;
}

.audiences-status-message.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    #audiences-section {
        padding: 70px 0 0 0;
    }
    
    #audiences-section main {
        padding: 0;
    }
    
    .audiences-container {
        padding: 0 16px;
    }

    .audiences-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        max-width: 100%;
        border-radius: 0;
        max-height: 100vh;
    }

    .modal-tabs {
        padding: 0 16px;
        overflow-x: auto;
    }

    .modal-tab {
        padding: 12px 16px;
        font-size: 13px;
    }

    .modal-tab-content {
        padding: 20px 16px;
    }

    .form-group-row {
        grid-template-columns: 1fr;
    }

    .modal-actions {
        flex-direction: column;
        padding: 16px;
    }

    .modal-actions .save-btn,
    .cancel-btn {
        width: 100%;
    }
}

/* ==========================================
   Dark Mode Support
   ========================================== */

body.dark-mode #audiences-section {
    background: #0a0a0a;
}


body.dark-mode .audience-card {
    background: #171717;
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

body.dark-mode .audience-card:hover {
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.2);
}

body.dark-mode .audience-name {
    color: #f1f1f1;
}

body.dark-mode .primary-badge.standalone {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

body.dark-mode .audience-description {
    color: #a1a1aa;
}

body.dark-mode .audience-meta {
    border-top-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .audience-meta-item {
    color: #a1a1aa;
}

body.dark-mode .audience-action-btn {
    background: #262626;
    color: #e5e5e5;
}

body.dark-mode .audiences-empty-state {
    background: rgba(23, 23, 23, 0.5);
    border-color: rgba(102, 126, 234, 0.3);
}

body.dark-mode .audiences-empty-state h3 {
    color: #f1f1f1;
}

body.dark-mode .audiences-empty-state p {
    color: #a1a1aa;
}

body.dark-mode .modal-content {
    background: #171717;
}

body.dark-mode .modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

body.dark-mode .modal-header h3 {
    color: #f1f1f1;
}

body.dark-mode .close-modal {
    background: rgba(255, 255, 255, 0.06);
    color: #a1a1aa;
}

body.dark-mode .close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #f1f1f1;
}

body.dark-mode .modal-tabs {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

body.dark-mode .modal-tab {
    color: #a1a1aa;
}

body.dark-mode .modal-tab:hover,
body.dark-mode .modal-tab.active {
    color: #667eea;
}

body.dark-mode .form-group label {
    color: #d4d4d8;
}

body.dark-mode .form-input,
body.dark-mode .form-select,
body.dark-mode .tag-input {
    background: #262626;
    border-color: rgba(255, 255, 255, 0.1);
    color: #f1f1f1;
}

body.dark-mode .form-input:hover,
body.dark-mode .form-select:hover,
body.dark-mode .tag-input:hover {
    border-color: rgba(102, 126, 234, 0.5);
}

body.dark-mode .form-input:focus,
body.dark-mode .form-select:focus,
body.dark-mode .tag-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
}

body.dark-mode .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

body.dark-mode .avatar-preview-container {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-color: rgba(102, 126, 234, 0.3);
}

body.dark-mode .avatar-preview-container:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.12) 100%);
    border-color: rgba(102, 126, 234, 0.5);
}

body.dark-mode .avatar-placeholder {
    color: #71717a;
}

body.dark-mode .tag {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
    border-color: rgba(102, 126, 234, 0.3);
    color: #a78bfa;
}

body.dark-mode .tag-remove {
    background: rgba(102, 126, 234, 0.3);
    color: #a78bfa;
}

body.dark-mode .tag-remove:hover {
    background: #667eea;
    color: white;
}

body.dark-mode .modal-actions {
    border-top-color: rgba(255, 255, 255, 0.06);
}

body.dark-mode .cancel-btn {
    background: rgba(255, 255, 255, 0.06);
    color: #d4d4d8;
}

body.dark-mode .cancel-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}
