/* ===================================================================
   KEYWORD RULES PAGE STYLES
   Styles for the Keyword Rules Management page
   =================================================================== */

/* ========== BASE STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    width: 98%;
    max-width: 2400px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    text-align: center;
}

.header h1 {
    color: #4a5568;
    font-size: 2.5em;
    margin-bottom: 10px;
}

.header p {
    color: #718096;
    font-size: 1.1em;
}

.content-section {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

/* Search & Filter Styles */
.search-filters {
    background: linear-gradient(135deg, #f6f8fb 0%, #e9ecef 100%);
    padding: 18px;
    border-radius: 12px;
    margin-bottom: 25px;
    border: 1px solid #dee2e6;
}

.search-filters h3 {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.search-group {
    display: flex;
    flex-direction: column;
}

.search-group label {
    color: #4a5568;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95em;
}

.search-input-wrapper {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s ease;
    background: white;
}

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

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #a0aec0;
    font-size: 1.1em;
}

.filter-select {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s ease;
    background: white;
    cursor: pointer;
}

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

.search-buttons {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

.btn-orange {
    background: #f97316;
    color: white;
}

.btn-orange:hover {
    background: #ea580c;
    transform: translateY(-2px);
}

.search-help {
    font-size: 0.9em;
    color: #2a4365;
}

.search-help strong {
    color: #2c5282;
}

.search-results-info {
    background: #f0fff4;
    padding: 12px 20px;
    border-radius: 8px;
    border-left: 4px solid #48bb78;
    margin-top: 15px;
    margin-bottom: 20px;
    display: none;
    align-items: center;
    justify-content: space-between;
}

.search-results-info.show {
    display: flex;
}

.search-results-text {
    color: #22543d;
    font-weight: 600;
}

.clear-search {
    background: #e53e3e;
    color: white;
    padding: 5px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.3s ease;
}

.clear-search:hover {
    background: #c53030;
}

.highlight-match {
    background: #fef08a;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: bold;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s ease;
    margin-right: 8px;
    margin-bottom: 8px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
    transform: translateY(-2px);
}

.btn-primary:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #718096;
    color: white;
}

.btn-secondary:hover {
    background: #2d3748;
}

.btn-compact {
    padding: 5px 10px;
    font-size: 0.8em;
    margin: 0 2px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.data-table th {
    background: #4a5568;
    color: white;
    padding: 15px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9em;
}

.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9em;
}

.data-table tr:hover {
    background: #f7fafc;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stats-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
    border-left: 4px solid #667eea;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stats-card h3 {
    color: #4a5568;
    margin-bottom: 10px;
}

.stats-card .amount {
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
}

.alert {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid;
}

.alert-info {
    background: #ebf8ff;
    color: #2a4365;
    border-color: #4299e1;
}

/* Keyword Rules Specific Styles */
.keyword-highlight {
    background: #e6fffa;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #2c7a7b;
    font-size: 0.85em;
}

.group-name-highlight {
    background: #f0fff4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #22543d;
    font-size: 0.85em;
}

.source-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: bold;
}

.source-badge.manual {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

.source-badge.imported {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #fc8181;
}

.source-badge.csv-imported {
    background: #ddd6fe;
    color: #553c9a;
    border: 1px solid #a78bfa;
}

.source-badge.applied {
    background: #bee3f8;
    color: #2a4e7c;
    border: 1px solid #63b3ed;
}

.source-badge.sample {
    background: #fed7aa;
    color: #9a3412;
    border: 1px solid #fb923c;
}

.source-badge.unknown {
    background: #e2e8f0;
    color: #2d3748;
    border: 1px solid #cbd5e0;
}

.source-badge.archive {
    background: #c4f1f9;
    color: #086f83;
    border: 1px solid #76e4f7;
}

.keyword-rules-table {
    font-size: 0.8em;
}

.keyword-rules-table td {
    padding: 8px 6px;
    vertical-align: middle;
}

.keyword-rules-table th {
    padding: 10px 6px;
    font-size: 0.8em;
    white-space: nowrap;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    margin: 1% auto;
    padding: 0;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 96%;
    max-width: 1800px;
    max-height: 95vh;
    overflow-y: auto;
    border: 3px solid rgba(255,255,255,0.2);
}

/* Virtual scrolling styles - NEW ADDITION */
#virtualTableContainer {
    position: relative;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    height: 600px;
}

#virtualTableBody {
    position: relative;
}

.virtual-row {
    position: absolute;
    width: 100%;
    border-bottom: 1px solid #e2e8f0;
    background: white;
}

.virtual-row:hover {
    background: #f7fafc;
}

.virtual-row-content {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.virtual-row-content > div {
    display: table-cell;
    padding: 8px;
    vertical-align: middle;
}

.virtual-row table {
    width: 100%;
    table-layout: fixed;
}

.virtual-row td {
    padding: 8px 6px;
    vertical-align: middle;
}

/* Performance indicator animation */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.performance-indicator.show {
    display: block !important;
    animation: slideIn 0.3s ease;
}

/* Loading spinner */
.loading-spinner {
    width: 50px;
    height: 50px;
    margin: 20px auto;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Modal-specific styles */
.import-modal-content {
    background: white;
    margin: 50px auto;
    padding: 0;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 800px;
    max-height: calc(100vh - 100px);
    overflow: hidden;
    border: 3px solid rgba(255,255,255,0.2);
}

.view-modal-content {
    background: white;
    margin: 50px auto;
    padding: 0;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 800px;
    max-height: calc(100vh - 100px);
    overflow: hidden;
    border: 3px solid rgba(255,255,255,0.2);
}

.view-modal-body {
    padding: 30px;
    max-height: calc(100vh - 250px);
    overflow-y: auto;
}

.detail-row {
    display: flex;
    padding: 12px 0;
    border-bottom: 1px solid #e2e8f0;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    flex: 0 0 180px;
    font-weight: 600;
    color: #4a5568;
}

.detail-value {
    flex: 1;
    color: #2d3748;
}

.detail-value.empty {
    color: #a0aec0;
    font-style: italic;
}

.view-modal-footer {
    padding: 20px 30px;
    background: #f7fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #5a67d8 100%);
    padding: 25px 30px;
    border-radius: 20px 20px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: white;
    font-size: 1.4em;
    font-weight: 600;
    margin: 0;
}

.modal-footer {
    background: #f7fafc;
    padding: 20px 30px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.close {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: transform 0.3s ease;
}

.close:hover {
    transform: rotate(90deg);
}

.form-section {
    background: rgba(255,255,255,0.7);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 25px;
}

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

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

.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
    font-size: 16px;
}

.form-group input, 
.form-group select, 
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.3s ease;
}

/* Ensure consistent font in edit modal */
#editModal .form-group input,
#editModal .form-group select,
#editModal .form-group textarea {
    font-size: 16px;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.drop-zone.dragover {
    background: #f0f4f8;
    border-color: #667eea;
}

.file-selected.show {
    display: block !important;
}

.file-preview.show {
    display: block !important;
}

/* Inline View Details button styling */
.btn-view-details-inline {
    padding: 6px 14px;
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    white-space: nowrap;
}

.btn-view-details-inline:hover {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* Contact details modal divider styling */
.detail-row.with-divider {
    border-bottom: 2px solid #4a5568;
    padding-bottom: 16px;
    margin-bottom: 16px;
}

/* ==================== DARK THEME SUPPORT ==================== */
body.theme-dark {
    background: linear-gradient(135deg, #1a1f2e 0%, #2d3748 50%, #1e293b 100%);
    color: #e2e8f0;
}

body.theme-dark .container {
    color: #e2e8f0;
}

body.theme-dark .header {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(51, 65, 85, 0.9) 100%);
    color: #e2e8f0;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

body.theme-dark .header h1 {
    color: #f1f5f9;
}

body.theme-dark .header p {
    color: #cbd5e1;
}

/* Page title "Keyword Rules" and all headings */
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3,
body.theme-dark h4 {
    color: #f1f5f9 !important;
}

/* Content sections */
body.theme-dark .content-section {
    color: #e2e8f0;
}

body.theme-dark .content-section h2 {
    color: #f1f5f9 !important;
}

body.theme-dark .card,
body.theme-dark .search-section,
body.theme-dark .search-filters,
body.theme-dark .rules-container {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.95) 0%, rgba(71, 85, 105, 0.9) 100%);
    border-color: rgba(148, 163, 184, 0.3);
    color: #e2e8f0;
}

body.theme-dark .search-section h2,
body.theme-dark .search-filters h3,
body.theme-dark .card h3 {
    color: #f1f5f9 !important;
}

/* Form labels - FIX FOR VISIBILITY */
body.theme-dark label,
body.theme-dark .form-label,
body.theme-dark .search-section label,
body.theme-dark .search-filters label,
body.theme-dark .search-group label,
body.theme-dark .filter-label {
    color: #e2e8f0 !important;
}

/* Search Tips box with inline styles */
body.theme-dark .search-filters > div[style*="background: #ebf8ff"],
body.theme-dark div[style*="background: #ebf8ff"] {
    background: rgba(59, 130, 246, 0.2) !important;
    border-left-color: #60a5fa !important;
    color: #e2e8f0 !important;
}

body.theme-dark .search-filters > div[style*="background: #ebf8ff"] strong,
body.theme-dark div[style*="background: #ebf8ff"] strong {
    color: #93c5fd !important;
}

/* Search results info box */
body.theme-dark .search-results-info,
body.theme-dark div[style*="background: #f0fff4"] {
    background: rgba(34, 197, 94, 0.2) !important;
    border-left-color: #4ade80 !important;
    color: #e2e8f0 !important;
}

body.theme-dark .search-results-text {
    color: #86efac !important;
}

body.theme-dark .search-tips {
    background: rgba(59, 130, 246, 0.15);
    border-left-color: #60a5fa;
    color: #cbd5e1;
}

body.theme-dark input[type="text"],
body.theme-dark input[type="search"],
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark .search-input,
body.theme-dark .filter-select {
    background: rgba(15, 23, 42, 0.6) !important;
    border-color: rgba(148, 163, 184, 0.3) !important;
    color: #e2e8f0 !important;
}

body.theme-dark input[type="text"]:focus,
body.theme-dark input[type="search"]:focus,
body.theme-dark select:focus,
body.theme-dark textarea:focus {
    background: rgba(15, 23, 42, 0.8) !important;
    border-color: #60a5fa !important;
    color: #f1f5f9 !important;
}

body.theme-dark input::placeholder {
    color: #94a3b8 !important;
}

body.theme-dark select option {
    background: #1e293b;
    color: #e2e8f0;
}

/* Stats cards - FIX FOR VISIBILITY */
body.theme-dark .stats-card {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.95) 0%, rgba(71, 85, 105, 0.9) 100%);
    border-color: rgba(148, 163, 184, 0.3);
    border-left-color: #60a5fa;
}

body.theme-dark .stats-card h3,
body.theme-dark .stats-card .stat-label {
    color: #cbd5e1 !important;
}

body.theme-dark .stats-card .amount,
body.theme-dark .stats-card .stat-value {
    color: #60a5fa !important;
}

/* Data table - FIX FOR VISIBILITY */
body.theme-dark .data-table {
    background: rgba(30, 41, 59, 0.9);
}

body.theme-dark .data-table th {
    background: linear-gradient(135deg, #334155 0%, #475569 100%);
    color: #f1f5f9;
}

body.theme-dark .data-table td {
    background: rgba(30, 41, 59, 0.6);
    color: #e2e8f0;
    border-bottom-color: rgba(148, 163, 184, 0.2);
}

body.theme-dark .data-table tr:hover td {
    background: rgba(51, 65, 85, 0.8);
}

body.theme-dark .data-table tr:nth-child(even) td {
    background: rgba(51, 65, 85, 0.4);
}

/* Blue info/alert box - with stronger selectors */
body.theme-dark .alert,
body.theme-dark .info-box,
body.theme-dark .alert-info {
    background: rgba(59, 130, 246, 0.2) !important;
    color: #e2e8f0 !important;
    border-left-color: #60a5fa !important;
}

body.theme-dark .alert strong,
body.theme-dark .alert-info strong {
    color: #93c5fd !important;
}

body.theme-dark .alert-success {
    background: rgba(16, 185, 129, 0.2) !important;
    color: #e2e8f0 !important;
    border-left-color: #34d399 !important;
}

body.theme-dark .alert-warning {
    background: rgba(245, 158, 11, 0.2) !important;
    color: #e2e8f0 !important;
    border-left-color: #fbbf24 !important;
}

/* Modal styles */
body.theme-dark .modal-content,
body.theme-dark .view-modal-content {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #e2e8f0;
}

body.theme-dark .modal-header {
    background: linear-gradient(135deg, #334155 0%, #475569 100%);
    border-bottom-color: rgba(148, 163, 184, 0.3);
}

body.theme-dark .modal-header h3 {
    color: #f1f5f9 !important;
}

body.theme-dark .modal-body,
body.theme-dark .view-modal-body {
    color: #e2e8f0;
}

body.theme-dark .form-group label {
    color: #e2e8f0 !important;
}

/* View toggle buttons */
body.theme-dark .view-toggle-btn {
    background: rgba(51, 65, 85, 0.8);
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.3);
}

body.theme-dark .view-toggle-btn.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

/* Detail rows in modals */
body.theme-dark .detail-label {
    color: #94a3b8 !important;
}

body.theme-dark .detail-value {
    color: #f1f5f9 !important;
}

body.theme-dark .source-badge {
    opacity: 0.9;
}

/* Generic text elements */
body.theme-dark p,
body.theme-dark span,
body.theme-dark div {
    color: inherit;
}

/* Ensure all text in dark containers is visible */
body.theme-dark .search-section *,
body.theme-dark .search-filters *,
body.theme-dark .card * {
    color: inherit;
}

body.theme-dark .search-section label,
body.theme-dark .search-filters label,
body.theme-dark .card label {
    color: #e2e8f0 !important;
}

/* Override inline styles for stats card amounts */
body.theme-dark .stats-card .amount {
    filter: brightness(1.3);
}

body.theme-dark .stats-card small {
    color: #94a3b8 !important;
}

/* Form sections in modals */
body.theme-dark .form-section {
    background: rgba(30, 41, 59, 0.8) !important;
}

body.theme-dark .form-section h4 {
    color: #60a5fa !important;
}

/* Tip boxes in forms - override inline styles */
body.theme-dark .form-section > div[style*="background"],
body.theme-dark div[style*="background: linear-gradient(135deg, #e0f2fe"] {
    background: rgba(59, 130, 246, 0.2) !important;
}

body.theme-dark .form-section > div[style*="background"] *,
body.theme-dark div[style*="background: linear-gradient(135deg, #e0f2fe"] * {
    color: #e2e8f0 !important;
}

body.theme-dark .form-section > div[style*="background"] a {
    color: #60a5fa !important;
}

/* View toggle container and stats */
body.theme-dark .view-controls,
body.theme-dark .rules-header {
    color: #e2e8f0;
}

body.theme-dark .total-count,
body.theme-dark .phone-count,
body.theme-dark [class*="count"] {
    color: #e2e8f0 !important;
}

/* Cellular view specific */
body.theme-dark .cellular-container,
body.theme-dark .cellular-card {
    background: rgba(51, 65, 85, 0.9);
    border-color: rgba(148, 163, 184, 0.3);
    color: #e2e8f0;
}

body.theme-dark .cellular-card * {
    color: inherit;
}

/* Fix any remaining white backgrounds */
body.theme-dark .rules-container,
body.theme-dark .keyword-rules-container,
body.theme-dark .table-container {
    background: rgba(30, 41, 59, 0.9) !important;
}

/* Fix close button in modals */
body.theme-dark .close {
    color: #e2e8f0;
}

body.theme-dark .close:hover {
    color: #f1f5f9;
}

/* Search input wrapper icon */
body.theme-dark .search-icon {
    color: #94a3b8;
}

/* Additional filters section */
body.theme-dark .additional-filters label {
    color: #e2e8f0 !important;
}

/* Keyword highlight in table */
body.theme-dark .keyword-highlight {
    background: rgba(45, 212, 191, 0.25);
    color: #5eead4 !important;
    border: 1px solid rgba(45, 212, 191, 0.4);
}

/* Group name highlight */
body.theme-dark .group-name-highlight {
    background: rgba(34, 197, 94, 0.25);
    color: #86efac !important;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

/* Source badges in table */
body.theme-dark .source-badge {
    filter: brightness(1.1);
}
