:root {
    --bg-dark: #1e1e24;
    --sidebar-bg: #15151a;
    --main-bg: #ffffff;
    --panel-bg: #f8f9fa;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e2e8f0;
}

body { 
    margin: 0; 
    padding: 0; 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    display: flex; 
    height: 100vh; 
    overflow: hidden; 
    background: var(--bg-dark); 
    color: var(--text-primary);
}

/* --- SIDEBAR --- */
.sidebar { 
    width: 70px; 
    background: var(--sidebar-bg); 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding-top: 20px; 
    color: white; 
    flex-shrink: 0; 
}

/* Logo "Sticker" Effect */
.sidebar-logo { 
    width: 42px; 
    height: auto; 
    margin-bottom: 40px; 
    border-radius: 10px;      
    background-color: white;  
    padding: 8px;             
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.header-logo { width: 36px; height: auto; border-radius: 6px; }

.nav-btn { 
    background: none; 
    border: none; 
    color: #888; 
    font-size: 1.2rem; 
    padding: 15px; 
    cursor: pointer; 
    position: relative; 
    width: 100%; 
    transition: 0.2s; 
}

.nav-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: var(--accent); border-left: 3px solid var(--accent); }
.nav-bottom { margin-top: auto; padding-bottom: 20px; }

.badge { 
    position: absolute; 
    top: 10px; 
    right: 15px; 
    background: #dc3545; 
    color: white; 
    font-size: 10px; 
    padding: 2px 5px; 
    border-radius: 10px; 
}

/* --- MAIN LAYOUT --- */
.main-content { 
    flex: 1; 
    background: var(--main-bg); 
    display: flex; 
    flex-direction: column; 
    position: relative; 
}

.view-section { height: 100%; display: flex; flex-direction: column; }

.view-header { 
    padding: 20px; 
    border-bottom: 1px solid var(--border); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: white;
}
.view-header h2 { margin: 0; font-size: 1.2rem; font-weight: 600; }

/* --- CHAT STYLING --- */
.chat-window { flex: 1; padding: 20px; overflow-y: auto; background: #fdfdfd; }

.message { 
    max-width: 80%; 
    padding: 12px 16px; 
    margin-bottom: 12px; 
    border-radius: 8px; 
    line-height: 1.5; 
    font-size: 0.95rem; 
}
.message.stephen { background: #f1f5f9; align-self: flex-start; border-bottom-left-radius: 2px; color: var(--text-primary); }
.message.user { background: var(--accent); color: white; align-self: flex-end; margin-left: auto; border-bottom-right-radius: 2px; }

.input-area { 
    padding: 20px; 
    background: white; 
    border-top: 1px solid var(--border); 
    display: flex; 
    gap: 10px; 
}
input { 
    flex: 1; 
    padding: 12px; 
    border: 1px solid #ddd; 
    border-radius: 6px; 
    font-size: 1rem; 
    outline: none; 
}
input:focus { border-color: var(--accent); }
button { 
    background: var(--accent); 
    color: white; 
    border: none; 
    padding: 0 20px; 
    border-radius: 6px; 
    cursor: pointer; 
}
button:hover { background: var(--accent-hover); }

/* --- MODERN PIPELINE TABLE --- */
.table-container { 
    background: white; 
    overflow-y: auto;
    flex: 1;
}

table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    font-size: 0.8rem; 
    color: var(--text-primary);
}

/* Sticky Header */
thead { 
    background: #f8fafc; 
    position: sticky; 
    top: 0; 
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

th { 
    text-align: left; 
    padding: 12px 8px; 
    font-weight: 600; 
    color: #64748b; 
    text-transform: uppercase; 
    font-size: 0.7rem; 
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

/* Two-Row Logic */
tbody tr { background: white; }

/* The Top Row (Primary Info) */
tr.row-top td { 
    padding-top: 10px; 
    padding-bottom: 2px; 
    padding-left: 8px;
    padding-right: 8px;
    border-top: 1px solid #f1f5f9; 
    vertical-align: middle;
}

/* The Bottom Row (Metadata) */
tr.row-bottom td { 
    padding-top: 2px; 
    padding-bottom: 10px; 
    padding-left: 8px;
    padding-right: 8px;
    color: var(--text-secondary); 
    font-size: 0.75rem;
    vertical-align: top;
}

/* Hover Effect on the "Pair" */
tbody tr:hover, 
tbody tr:hover + tr.row-bottom, 
tr.row-top:has(+ tr.row-bottom:hover) {
    background-color: #f8fafc;
    cursor: pointer;
}

/* Utility Classes */
.font-mono { font-family: 'SF Mono', 'Consolas', monospace; letter-spacing: -0.5px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-gray-400 { color: #9ca3af; }
.text-blue-600 { color: var(--accent); font-weight: 500; }

/* --- BADGES & STATUSES --- */
.status-badge { 
    display: inline-flex; 
    align-items: center; 
    padding: 2px 8px; 
    border-radius: 4px; 
    font-size: 0.7rem; 
    font-weight: 600; 
    text-transform: uppercase;
}

/* Contextual Colors */
.tag-green { background: #d1fae5; color: #065f46; } /* Approved/Clear */
.tag-blue  { background: #dbeafe; color: #1e40af; } /* Underwriting */
.tag-orange{ background: #ffedd5; color: #9a3412; } /* Conditions */
.tag-red   { background: #fee2e2; color: #991b1b; } /* Alerts */
.tag-gray  { background: #f3f4f6; color: #374151; } /* Default */

/* eConsent Pills */
.econsent-pill {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border: 1px solid #d1fae5;
    background: #ecfdf5;
    color: #059669;
    border-radius: 12px;
    margin-right: 4px;
    display: inline-block;
}

.econsent-pill.missing {
    border-color: #fee2e2;
    background: #fff1f2;
    color: #dc2626;
}

/* Table Footer */
tfoot tr td {
    background: #f8fafc;
    border-top: 2px solid var(--border);
    font-weight: 700;
    padding: 12px 8px;
    color: var(--text-primary);
}

/* --- CONTEXT PANEL (Right) --- */
.context-panel { 
    width: 300px; 
    background: var(--panel-bg); 
    border-left: 1px solid var(--border); 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 20px; 
    flex-shrink: 0; 
}

.panel-header { margin-bottom: 10px; }
.panel-header h3 { margin: 0; font-size: 1rem; }
.subtitle { font-size: 0.8rem; color: var(--text-secondary); }

.panel-section { 
    background: white; 
    padding: 15px; 
    border-radius: 8px; 
    border: 1px solid #e5e7eb; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.02); 
}

.panel-section h4 { 
    margin: 0 0 10px 0; 
    font-size: 0.9rem; 
    color: #444; 
    border-bottom: 1px solid #f3f4f6; 
    padding-bottom: 8px; 
}

.empty-state { font-size: 0.85rem; color: #999; font-style: italic; }

/* Contact Card */
.contact-detail-row { margin-bottom: 8px; font-size: 0.9rem; }
.label { font-weight: 600; color: #555; display: block; font-size: 0.75rem; }

/* Utility Color Classes for Dynamic JS Logic */
.text-danger { color: #dc2626; }
.text-orange-600 { color: #ea580c; }
.text-green-600 { color: #16a34a; }
.text-blue-600 { color: #2563eb; }
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.font-bold { font-weight: 700; }

/* --- LOAN DETAIL VIEW --- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
}

.card-header {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f1f5f9;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.detail-row .label {
    color: var(--text-secondary);
    font-weight: 600;
    margin-right: 10px;
    white-space: nowrap;
}

/* Contact Chips */
.contact-item {
    padding: 10px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}
.contact-role { font-size: 0.7rem; color: var(--accent); font-weight: 700; text-transform: uppercase; margin-bottom: 2px; }
.contact-name { font-weight: 600; font-size: 0.9rem; color: #333; }
.contact-email { font-size: 0.8rem; color: #666; display: block; overflow: hidden; text-overflow: ellipsis; }
.contact-phone { font-size: 0.8rem; color: #666; font-family: monospace; }

/* --- TASK WIDGET STYLING --- */
.task-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
    border: 1px solid #f0f0f0;
    border-left: 5px solid #ccc; /* Default Border */
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.task-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Urgency Colors */
.task-card.critical { border-left-color: #dc2626; background: #fef2f2; } /* Red */
.task-card.warning  { border-left-color: #ea580c; background: #fff7ed; } /* Orange */
.task-card.info     { border-left-color: #2563eb; background: #eff6ff; } /* Blue */
.task-card.success  { border-left-color: #16a34a; background: #f0fdf4; } /* Green */

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.task-borrower {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1f2937;
}

.task-role {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 12px;
    background: white;
    color: #555;
    border: 1px solid #e5e7eb;
}

.task-body {
    font-size: 0.9rem;
    color: #4b5563;
    line-height: 1.4;
    margin-bottom: 8px;
}

.task-footer {
    display: flex;
    justify-content: flex-end;
    font-size: 0.75rem;
    color: #9ca3af;
    font-weight: 500;
}

/* Alert Box in Detail View */
.file-alert-box {
    background: #fff1f2; 
    border: 1px solid #fecaca; 
    border-radius: 8px; 
    padding: 15px;
    margin-top: 20px;
}

.file-alert-item {
    display: flex; 
    align-items: flex-start; 
    gap: 10px; 
    font-size: 0.9rem; 
    color: #991b1b; 
    background: white; 
    padding: 10px; 
    border-radius: 6px; 
    border: 1px solid #fee2e2;
    margin-bottom: 6px;
}

/* --- SCROLL FIX FOR TASKS --- */
#tasksContainer {
    flex: 1;              /* Fill remaining space below header */
    overflow-y: auto;     /* Enable vertical scrolling */
    padding: 20px;        /* Add breathing room */
    min-height: 0;        /* Critical flexbox fix for Firefox/Safari */
}

/* --- SPLIT VIEW LAYOUT --- */
.tasks-split-container {
    display: flex;
    flex: 1;
    overflow: hidden; /* Parent doesn't scroll, columns do */
    background: #f8fafc;
    gap: 20px;
    padding: 20px;
}

.tasks-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
}

.column-title {
    font-size: 0.9rem;
    color: #64748b;
    margin: 0 0 10px 0;
    text-transform: uppercase;
    font-weight: 700;
    padding-bottom: 5px;
    border-bottom: 2px solid #e2e8f0;
}

/* Scrollable area inside columns */
#tasksByDate, #tasksByRole {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px; /* Space for scrollbar */
}

/* --- GROUP HEADERS --- */
.group-header {
    background: #e2e8f0;
    color: #334155;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 4px;
    margin-top: 15px;
    margin-bottom: 5px;
    position: sticky;
    top: 0;
}
#tasksByDate .group-header:first-child, 
#tasksByRole .group-header:first-child { margin-top: 0; }

/* --- COMPACT TASK ROW --- */
.task-row {
    display: flex;
    align-items: flex-start; /* Align top for multi-line text */
    gap: 10px;
    background: white;
    border-bottom: 1px solid #f1f5f9;
    padding: 8px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent; /* Severity Stripe */
}

.task-row:hover { background: #fff; transform: translateX(2px); }
.task-row:last-child { border-bottom: none; }

/* Severity Striping */
.task-row.critical { border-left-color: #dc2626; background: #fef2f2; }
.task-row.warning  { border-left-color: #ea580c; background: #ffffff; } /* Keep white bg for cleaner list look? Or faint orange? */
.task-row.info     { border-left-color: #2563eb; background: #ffffff; }
.task-row.success  { border-left-color: #16a34a; background: #f0fdf4; }

.row-borrower { font-weight: 700; color: #1e293b; white-space: nowrap; }
.row-msg { color: #475569; line-height: 1.3; }
.row-meta { font-size: 0.7rem; color: #94a3b8; white-space: nowrap; margin-left: auto; }

/* --- USER TASK ACTION BUTTONS --- */
.task-action-btn {
    background: none;
    border: none;
    color: #cbd5e1; /* Subtle gray */
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.85rem;
    transition: color 0.15s;
}
.task-action-btn:hover {
    color: #ef4444; /* Red on hover */
}

/* Typeahead Styles */
.typeahead-wrapper { position: relative; display: inline-block; width: 170px; text-align: left; }
.typeahead-input { width: 100%; padding: 8px; font-size: 0.8rem; border: 1px solid #cbd5e1; border-radius: 4px; box-sizing: border-box; color: #555; }
/* FIXED: z-index increased to 9999 to sit on top of the modal overlay */
.typeahead-dropdown { position: absolute; top: 100%; left: 0; width: 280px; background: white; border: 1px solid #ccc; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 9999; max-height: 250px; overflow-y: auto; display: none; border-radius: 4px; margin-top: 4px; text-align: left; }
.typeahead-item { padding: 8px 10px; font-size: 0.8rem; cursor: pointer; border-bottom: 1px solid #eee; line-height: 1.3; }
.typeahead-item:hover { background: #f1f5f9; }
.typeahead-clear { position: absolute; right: 8px; top: 9px; cursor: pointer; color: #94a3b8; font-size: 0.8rem; display: none; z-index: 10; }
.typeahead-clear:hover { color: #ef4444; }

/* Edit Modal Styles */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; display: none; align-items: center; justify-content: center; text-align: left; }
.modal-content { background: white; padding: 20px; border-radius: 8px; width: 400px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); overflow: visible !important; }
.modal-header { font-size: 1.1rem; font-weight: 600; margin-bottom: 15px; display: flex; justify-content: space-between; }
.modal-form-group { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.modal-form-group label { font-size: 0.8rem; font-weight: 600; color: #64748b; }
.modal-form-group input, .modal-form-group select { padding: 8px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 768px) {
    .tasks-split-container {
        flex-direction: column; /* Stack them */
        overflow-y: auto; /* Allow full page scroll */
    }
    .tasks-column {
        overflow: visible; /* Let content expand */
        margin-bottom: 30px;
    }
    #tasksByDate, #tasksByRole {
        overflow: visible;
    }
}

/* --- CONTACTS HUB STYLES --- */
.contact-hub-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}
.contact-hub-item:hover { 
    background: #f1f5f9; 
}
.contact-hub-item.active { 
    background: white; 
    border-left-color: var(--accent); 
    box-shadow: -2px 0 5px rgba(0,0,0,0.02); 
}