:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #4f46e5; /* Indigo */
    --accent-hover: #4338ca;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --input-bg: #fdfdfd;
    --header-bg: #f8fafc;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.4;
    padding: 1rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

header {
    margin-bottom: 0.75rem;
    text-align: center;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    overflow: hidden; /* Ensure header/footer stay within radius */
}

/* Unified Card Header */
.card-header {
    background: var(--header-bg);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.header-icon {
    font-size: 1.1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.action-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Card Content / Scrollable Sections */
.card-content {
    padding: 0; /* Let tables and lists handle their own padding/margins if needed */
}

.scroll-section {
    max-height: 250px;
    overflow-y: auto;
    padding: 0 1rem;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Tables */
table { 
    width: 100%; 
    border-collapse: collapse; 
    table-layout: fixed; /* Prevent overflow */
}

th {
    position: sticky; 
    top: 0; 
    background: #ffffff; 
    z-index: 10;
    text-align: left; 
    padding: 0.75rem 0.5rem;
    color: var(--text-secondary); 
    font-size: 0.7rem; 
    font-weight: 700;
    text-transform: uppercase; 
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

td { 
    padding: 0.6rem 0.5rem; 
    border-bottom: 1px solid #f8fafc; 
    font-size: 0.85rem; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upn { font-weight: 600; color: var(--text-primary); }
.name { font-size: 0.8rem; color: var(--text-secondary); }

/* Switches */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e2e8f0; transition: .3s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 20px;
}
.slider:before {
    position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
    background-color: white; transition: .3s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(16px); }

/* Rule Line */
.rule-line {
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s;
    background: #ffffff;
}
.rule-line:hover { background: #f8fafc; }

.rule-info { display: flex; align-items: center; gap: 1rem; flex: 1; }
.rule-type { font-size: 0.95rem; font-weight: 500; color: var(--text-secondary); }

#keyword-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-color);
    width: 160px;
    background: var(--input-bg);
    transition: all 0.2s;
}
#keyword-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-reclassify {
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-reclassify:hover { background: var(--accent-hover); box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2); }
.btn-reclassify:active { transform: translateY(1px); }

.rule-meta { display: flex; align-items: center; gap: 1rem; }
.badge {
    background: var(--accent-color); color: white;
    padding: 0.2rem 0.6rem; border-radius: 20px;
    font-size: 0.75rem; font-weight: 700;
}

#classification-rule-icon { transition: transform 0.3s; color: var(--text-secondary); }

.rule-details { 
    border-top: 1px solid var(--border-color); 
    padding: 0.5rem 0;
    background: #fdfdfd;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.modal-overlay.hidden { display: none; }

.modal-content {
    background: white;
    width: 90%; max-width: 850px; max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    background: #ffffff;
}
.modal-header h3 {
    margin: 0; color: var(--text-primary);
    font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em;
}
.close-btn {
    background: #f1f5f9; border: none; width: 32px; height: 32px;
    border-radius: 50%; font-size: 1.2rem; color: var(--text-secondary);
    cursor: pointer; display: flex; justify-content: center; align-items: center;
    transition: all 0.2s;
}
.close-btn:hover { background: #e2e8f0; color: var(--text-primary); }

.modal-body { padding: 2rem; overflow-y: auto; flex: 1; }

.modal-meta {
    margin-bottom: 2rem; background: #f8fafc;
    padding: 1.25rem; border-radius: 12px;
    display: flex; flex-direction: column; gap: 0.75rem;
    border: 1px solid var(--border-color);
}
.meta-row { display: flex; font-size: 0.9rem; align-items: center; }
.meta-row .label { width: 90px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
.meta-row .value { color: var(--text-primary); font-weight: 500; }

.email-body-container {
    font-size: 1rem; line-height: 1.7; color: #334155;
}
.email-body-container img { max-width: 100%; height: auto; border-radius: 8px; margin: 1rem 0; }

/* Table specific overrides */
.email-table td:nth-child(2) { font-weight: 600; color: var(--text-primary); }
.email-table tr:hover td { background: #f8fafc; }
.email-table tr:active td { background: #f1f5f9; }

.hidden { display: none; }
