/* MEDICINES FOR CHILDREN - BRAND THEME v1.1 */
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');

:root {
    /* MfC Brand Palette */
    --brand-purple: #4A2868; /* Deep Purple */
    --brand-pink: #E92C81;   /* Vibrant Pink */
    --brand-blue: #00AEEF;   /* Bright Blue */
    --brand-grey: #565656;
    
    /* UI Variables */
    --bg-light: #f8f9fa;
    --white: #ffffff;
    --border: #dee2e6;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
    font-family: 'Open Sans', sans-serif; /* Cleaner font */
    margin: 0;
    background-color: var(--bg-light);
    color: var(--brand-grey);
    line-height: 1.6;
}

/* --- HEADER & BRANDING --- */
header {
    background: white;
    color: var(--brand-purple);
    padding: 10px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border-top: 5px solid var(--brand-pink); /* Brand accent */
}

.brand-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-img {
    height: 50px; /* Adjust based on your actual image aspect ratio */
    width: auto;
}

.project-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--brand-purple);
    border-left: 1px solid #ddd;
    padding-left: 15px;
    margin-left: 10px;
}

/* User Controls (Icons) */
.user-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--brand-grey);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: #f0f0f0;
    color: var(--brand-purple);
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--brand-purple);
    margin-right: 10px;
}

/* --- BUTTONS & INTERACTIVE --- */
.btn-primary {
    background-color: var(--brand-pink);
    color: white;
    border: none;
    padding: 8px 20px; /* Reduced vertical padding */
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.2; /* Fixes the "tall button" issue */
    transition: background 0.2s;
    box-shadow: 0 2px 4px rgba(233, 44, 129, 0.3);
}

.btn-primary:hover {
    background-color: #c91f6b;
    transform: translateY(-1px);
}

.btn-small {
    padding: 5px 12px;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    background-color: var(--brand-blue);
    transition: all 0.2s;
}

.btn-small:hover { filter: brightness(110%); }

/* --- LAYOUT UTILS --- */
.app-container { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; padding: 30px; max-width: 1200px; margin: 0 auto; width: 100%; box-sizing: border-box;}

/* --- TABLE & CARDS --- */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden; /* Keep this here for rounded table corners */
}

.card { 
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 25px; 
    margin-bottom: 20px; 
}

.card { padding: 25px; margin-bottom: 20px; }

table { width: 100%; border-collapse: collapse; }
th { background-color: #f8f5fa; color: var(--brand-purple); padding: 15px; text-align: left; font-weight: 700; border-bottom: 2px solid #eee; }
td { padding: 15px; border-bottom: 1px solid #eee; }
tr:hover { background-color: #fafafa; }

/* --- BADGES --- */
.badge { padding: 5px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.status-setup { background: #e9ecef; color: #495057; }
.status-review { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.status-published { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* --- MODAL --- */

.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--brand-purple); font-size: 0.9rem; }
.form-group input, .form-group select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; box-sizing: border-box; font-family: inherit; }

/* --- CUSTOM FILE UPLOAD BUTTON --- */
input[type="file"].form-control {
    padding: 8px 10px; /* Slight tweak to align the inner button */
    background: #f8f9fa;
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    background-color: var(--brand-purple);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    margin-right: 15px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(74, 40, 104, 0.2);
}

input[type="file"]::file-selector-button:hover {
    background-color: #351c4b;
    transform: translateY(-1px);
}
/* --- LOGIN PAGE STYLES --- */

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--brand-purple) 0%, var(--brand-pink) 100%);
}

.auth-box {
    background: white;
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-box h2 {
    color: var(--brand-purple);
    margin-top: 0;
}

.auth-box p {
    color: var(--brand-grey);
    margin-bottom: 2rem;
}

.auth-box input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 25px; /* Rounded inputs to match buttons */
    box-sizing: border-box;
    font-size: 1rem;
    transition: border 0.2s;
}

.auth-box input:focus {
    border-color: var(--brand-pink);
    outline: none;
}

.auth-box button {
    width: 100%;
    margin-top: 10px;
    padding: 12px; /* Bigger button for login */
}

.error-msg {
    color: #dc3545;
    background: #ffe6e6;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: none; /* Hidden by default */
    font-size: 0.9rem;
}

.login-subtitle {
    color: var(--brand-purple); /* Match the logo text */
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase; /* Makes it look like a system title */
    letter-spacing: 1.5px;     /* Adds elegant spacing */
    margin-top: 0;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--brand-pink); /* A little accent line */
    display: inline-block;
    padding-bottom: 5px;
}

/* 2. Restore the Side-by-Side Grid */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr; /* Main (Left) vs Sidebar (Right) */
    gap: 30px;
    align-items: start;
}

@media (max-width: 900px) {
    .content-grid {
        grid-template-columns: 1fr; /* Stack on tablet/mobile */
    }
}

/* 3. Modal Close Button (Bigger & Better) */
.close-btn {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 2rem; /* Much bigger */
    line-height: 1;
    cursor: pointer;
    color: #aaa;
    transition: color 0.2s;
    background: none;
    border: none;
    padding: 0 10px;
}
.close-btn:hover { color: var(--brand-pink); }

/* --- Triage Layout Improvements (v1.3) --- */

/* Force the decision cell to be a horizontal row */
.decision-cell {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Pushes Undo button to far right */
    gap: 15px;
    width: 100%;
}

.decision-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.decision-meta {
    font-size: 0.8rem;
    color: #888;
    display: flex;
    align-items: center;
    gap: 5px;
}

.decision-reason {
    font-style: italic;
    color: #444;
    font-weight: 500;
    margin-right: 5px;
    border-right: 1px solid #ccc;
    padding-right: 10px;
}

/* Make the Undo button subtle until hovered */
.undo-btn {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 1rem;
    transition: color 0.2s;
}
.undo-btn:hover { color: var(--brand-pink); }

/* --- v1.6 Header Layout Fix --- */
.leaflet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Aligns items to the top if the title wraps */
    gap: 30px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap; /* Prevents the right box from dropping to a new line */
}

.header-left {
    display: flex;
    align-items: center;
    flex: 1; /* Tells the title area to take up all remaining space */
    min-width: 0; /* CRITICAL: Allows text inside to wrap instead of pushing boundaries */
}

.header-left h1 { 
    margin: 0; 
    font-size: 1.8rem; 
    color: var(--brand-purple); 
    line-height: 1.3;
    word-wrap: break-word; /* Forces long medical words to wrap neatly */
}

.header-right {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    flex-shrink: 0; /* CRITICAL: Stops the meta box from getting squished by a long title */
}

/* Mobile Fallback: If the screen is super small, let it wrap cleanly */
@media (max-width: 850px) {
    .leaflet-header { flex-wrap: wrap; }
    .header-right { width: 100%; justify-content: center; }
}

.meta-box {
    display: flex;
    flex-direction: column;
    text-align: right;
}

.meta-label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.meta-value { font-size: 1.1rem; font-weight: 700; color: var(--brand-grey); }

.meta-divider {
    width: 1px;
    height: 30px;
    background: #ddd;
    margin: 0 20px;
}

/* 2. Triage Comment Cards (Replaces Table) */
.triage-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    transition: transform 0.2s;
    position: relative;
    border-left: 4px solid var(--brand-purple); /* Accent line */
}

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

/* Top Row: Section & Meta */
.tc-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}
.tc-section { font-weight: 700; color: var(--brand-purple); font-size: 0.95rem; }
.tc-reviewer { font-size: 0.8rem; color: #999; }

/* Middle Row: The actual comment */
.tc-comment {
    font-size: 1rem;
    color: #333;
    margin-bottom: 15px;
    line-height: 1.5;
}

/* Bottom Row: Actions or Decision Info */
.tc-footer {
    padding-top: 15px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tc-decision-info {
    font-size: 0.85rem;
    color: #555;
    background: #f8f9fa;
    padding: 8px 12px;
    border-radius: 6px;
    width: 100%;
}

/* --- v1.5 Layout Refinements --- */

/* Align the action button to the right, under the progress bar */
.workflow-actions {
    display: flex;
    justify-content: flex-end; /* Pushes button to right */
    margin-bottom: 30px;      /* Space before the grid starts */
    padding: 0 5px;
}

/* Tidy up the history list */
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Ensure the grid columns fill the height if needed */
.left-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Review Page Specific Override */
/* We want 50% PDF and 50% Form for reviewing */
body:has(#review-form) .content-grid {
    grid-template-columns: 1fr 1fr; 
}

/* --- v1.6 Review Page Fixes --- */

.review-input {
    width: 100%;
    box-sizing: border-box; /* This fixes the "hitting the edge" issue */
    padding: 12px;           /* Comfortable internal spacing */
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;    /* Uses Open Sans */
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;        /* Allows resizing height only */
    transition: border-color 0.2s;
}

.review-input:focus {
    border-color: var(--brand-pink);
    outline: none;
    box-shadow: 0 0 0 3px rgba(233, 44, 129, 0.1);
}

/* --- Standard Navigation Link --- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #6c757d;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 15px; /* Space between link and title */
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--brand-purple); /* Hover color */
    transform: translateX(-3px); /* Little nudge animation */
}

/* --- v1.3 Editor's Checklist --- */

/* The "Actioned" (Done) State */
.triage-card.actioned {
    opacity: 0.6;           /* Fade it out slightly */
    background: #fdfdfd;
    border-left-color: #6c757d !important; /* Force Grey border */
}

.triage-card.actioned:hover {
    opacity: 1;             /* Brighten if you hover over it */
}

/* The "Mark as Actioned" Button */
.btn-action {
    background-color: var(--brand-purple);
    color: white;
    border: none;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(74, 40, 104, 0.2);
}

.btn-action:hover {
    background-color: #351c4b;
    transform: translateY(-1px);
}

/* --- v1.4 Dashboard Toolbar (Fixed) --- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    flex-wrap: wrap; 
    gap: 15px; /* Ensures vertical spacing if it wraps */
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 15px; /* Adds space between Search and Filter */
    flex: 1;
    flex-wrap: wrap; /* Allows search and filter to stack on mobile */
}

.search-box {
    position: relative;
    max-width: 300px; /* Limits width so it doesn't eat the dropdown */
    min-width: 200px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
    pointer-events: none; /* Click goes through to input */
}

.search-box input {
    width: 100%;
    padding: 10px 10px 10px 35px; /* More padding for icon */
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
    box-sizing: border-box; /* Critical for layout */
    transition: border-color 0.2s;
}

.search-box input:focus { border-color: var(--brand-purple); }

#status-filter, #indication-filter {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    background: #f8f9fa;
    cursor: pointer;
    color: var(--brand-grey);
    font-size: 0.9rem;
}

/* --- Delete Button Styling --- */
.btn-delete {
    background: transparent;
    border: 1px solid transparent;
    color: #999;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 15px; /* Push it away from Manage button */
}

.btn-delete:hover {
    background-color: #ffe6e6; /* Light red background */
    color: #dc3545;            /* Red Icon */
    border-color: #f5c6cb;
    transform: scale(1.1);
}

/* --- v1.4.1 Modal & Form Fixes --- */

/* --- Master Modal Layout (Fixed) --- */

.modal {
    display: none; /* Hidden by default */
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0, 0, 0, 0.6); /* Slightly darker for better contrast */
    
    /* THE MAGIC: The dark background handles the scrolling, not the box! */
    overflow-y: auto; 
    padding: 40px 20px; /* Gives a nice gap at the top and bottom of the screen */
    box-sizing: border-box;
}

.modal-content {
    background-color: #fff;
    /* Centers the box horizontally, and uses the padding from .modal for vertical spacing */
    margin: 0 auto; 
    padding: 30px;
    width: 90%;
    max-width: 600px;
    border-radius: 12px; /* Perfect curved corners on ALL sides */
    box-shadow: 0 10px 30px rgba(0,0,0,0.2); /* Adds a nice floating drop-shadow */
    position: relative;
    
    /* REMOVE the old max-height and overflow-y rules so it grows naturally */
}

/* Close Button (Just making sure it stays pinned to the top right) */
.close {
    color: #aaa;
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: var(--brand-pink);
    text-decoration: none;
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box; /* Ensures padding doesn't push it out of bounds */
}

textarea.form-control {
    resize: vertical; /* Allows you to drag the box taller, but not wider */
    line-height: 1.5;
}

.form-control:focus {
    border-color: var(--brand-purple);
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 40, 104, 0.1);
}

/* --- Table Wrapping Fixes --- */
/* Force the Status (4th) and Date (5th) columns to stay on one line */
#leaflet-list-body td:nth-child(4),
#leaflet-list-body td:nth-child(5) {
    white-space: nowrap;
}

/* Ensure the FontAwesome icon and date text don't split */
#leaflet-list-body td {
    vertical-align: middle;
}

/* --- Unified Status Badges --- */
.badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap; 
    border: 1px solid transparent; /* Keeps sizing consistent */
}

/* The 9 Stages (Clean, soft backgrounds with dark text) */
.status-overview { background: #f0f0f0; color: #555; }
.status-v0 { background: #fff3cd; color: #856404; border-color: #ffeeba; } /* Yellow */
.status-v1 { background: #cce5ff; color: #004085; } /* Blue */
.status-v2 { background: #d1ecf1; color: #0c5460; } /* Cyan */
.status-v3 { background: #e8d5f0; color: #4a2868; } /* Purple */
.status-v4 { background: #f8d7da; color: #721c24; } /* Red */
.status-v5 { background: #e2e3e5; color: #383d41; } /* Dark Grey */
.status-v6 { background: #ffe8a1; color: #856404; } /* Orange */
.status-published { background: #d4edda; color: #155724; } /* Green */

/* --- Dashboard Analytics Cards --- */
/* --- Upgraded Dashboard Analytics Cards (Modern SaaS Style) --- */
.stat-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
    border: 1px solid var(--border);
    border-left: 5px solid #ccc; /* Default left border, overridden by HTML inline style */
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.08);
}

.stat-content {
    display: flex;
    flex-direction: column;
    gap: 4px; /* Keeps the title and number grouped tightly together */
}

.stat-title {
    font-size: 0.75rem; 
    color: #888;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.stat-value {
    font-size: 2.2rem; 
    font-weight: 800;  
    line-height: 1;
}

.stat-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0; /* Prevents the icon box from squishing on small screens */
}

/* Responsive Design: Fix for smaller laptops & tablets */
@media (max-width: 950px) {
    .dashboard-top-wrapper {
        grid-template-columns: 1fr; /* Stack the wrapper vertically */
    }
    
    .dashboard-stats {
        flex-direction: row; /* Put stats back into a horizontal row */
        flex-wrap: wrap;
    }
    
    .stat-card {
        min-width: 200px; /* Allow them to wrap neatly */
    }
}

/* --- WORKFLOW PROGRESS BAR --- */
.workflow-track {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    min-width: 750px; 
}

/* The horizontal connecting line - Now perfectly centered! */
.workflow-track::before {
    content: '';
    position: absolute;
    top: 17px; /* Mathematically centered behind the 34px circles */
    left: 40px;
    right: 40px;
    height: 3px;
    background: #e9ecef;
    z-index: 1;
}

.step {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    text-align: center;
}

/* Base State: Not Started (Grey) */
.step .step-dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #ffffff;
    color: #adb5bd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
    border: 3px solid #e9ecef;
    transition: all 0.3s ease;
}

.step label {
    font-size: 0.75rem;
    color: #adb5bd;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

/* State: Completed (Solid Dark Purple) */
.step.completed .step-dot {
    background: var(--brand-purple);
    border-color: var(--brand-purple);
    color: white;
}
.step.completed label {
    color: var(--brand-purple);
}

/* State: Active (Clean Pink Ring, No Blobs) */
.step.active .step-dot {
    background: #ffffff;
    border-color: var(--brand-pink);
    color: var(--brand-pink);
    border-width: 3px;
    box-shadow: none; /* No more glowing blobs */
}
.step.active label {
    color: var(--brand-pink);
    font-weight: 800;
}

/* --- HISTORY FEED SCROLL & STYLING --- */
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 600px; /* Roughly matches the height of your PDF viewer */
    overflow-y: auto;  /* Turns on vertical scrolling when it gets too tall */
    padding-right: 10px; /* Gives the text some breathing room away from the scrollbar */
}

/* Custom Sleek Scrollbar */
.history-list::-webkit-scrollbar {
    width: 6px;
}
.history-list::-webkit-scrollbar-track {
    background: #f8f9fa; 
    border-radius: 4px;
}
.history-list::-webkit-scrollbar-thumb {
    background: #d1d5db; 
    border-radius: 4px;
}
.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--brand-pink); /* Little pop of brand color when grabbing it! */
}

/* --- CHART CONTAINER STRICT LIMITS --- */
.chart-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative; /* CRITICAL: Stops Chart.js from escaping */
    height: 320px; /* CRITICAL: Fixed height stops the infinite stretch */
    box-sizing: border-box;
}

.chart-container canvas {
    max-height: 220px !important; 
    width: 100% !important;
}

/* Ensure the list headers stay neat and save vertical space */
.chart-container h3 {
    font-size: 0.95rem;
    color: var(--brand-grey);
    margin-top: 0;
    margin-bottom: 8px; /* Reduced from 15px */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 100%;
    text-align: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px; /* Reduced from 10px */
}

/* --- USER PROFILE CHIP (Clickable) --- */
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--brand-purple);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.user-chip i { font-size: 0.85rem; color: var(--brand-pink); }

.user-chip:hover { 
    color: var(--brand-pink); 
    text-decoration: underline; 
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

/* Hide the popover entirely by default to save mobile layouts */
.user-chip .user-popover {
    display: none; 
}

/* Inside the Card Styles (Ready for whenever we build the mobile version) */
.user-popover-title {
    color: var(--brand-purple);
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.user-popover-detail {
    font-size: 0.85rem;
    margin-bottom: 5px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.3;
}

.user-popover-detail i { color: #aaa; margin-top: 2px; }

/* ==========================================================================
   DESKTOP ONLY HOVER LOGIC
   Only activates if the device has a physical mouse (hover: hover) 
   and is wider than a tablet.
   ========================================================================== */
@media (hover: hover) and (min-width: 800px) {
    .user-chip .user-popover {
        display: block; /* Turn it back on for desktop */
        visibility: hidden;
        opacity: 0;
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%) translateY(10px);
        background: white;
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 15px;
        width: 240px;
        box-shadow: 0 10px 25px rgba(0,0,0,0.15);
        z-index: 9999;
        transition: all 0.2s ease;
        cursor: default;
        text-align: left;
        color: var(--brand-grey);
        font-weight: normal;
        text-decoration: none;
        margin-bottom: 10px; /* Space for the triangle */
    }

    /* The little triangle pointing down */
    .user-chip .user-popover::after {
        content: '';
        position: absolute;
        top: 100%;
        left: 50%;
        margin-left: -8px;
        border-width: 8px;
        border-style: solid;
        border-color: white transparent transparent transparent;
    }

    .user-chip:hover .user-popover {
        visibility: visible;
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    /* ANTI-CUTOFF FIX: 
      If the chip is inside the narrow History list or Triage cards, 
      force the popover to hang to the LEFT so it doesn't hit the scrollbar edge.
    */
    .history-list .user-chip .user-popover,
    .triage-card .user-chip .user-popover {
        left: auto;
        right: -10px; 
        transform: translateY(10px);
    }

    .history-list .user-chip:hover .user-popover,
    .triage-card .user-chip:hover .user-popover {
        transform: translateY(0);
    }

    /* Move the little triangle so it still points at the name */
    .history-list .user-chip .user-popover::after,
    .triage-card .user-chip .user-popover::after {
        left: auto;
        right: 20px; 
    }
}

/* --- TABLE ACTION MENU (Kebab Menu) --- */
.action-menu {
    position: relative;
    display: inline-block;
}

.action-menu-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 4px;
    transition: all 0.2s;
}

.action-menu-btn:hover {
    background-color: #f0f0f0;
    color: var(--brand-purple);
}

.action-menu-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background-color: white;
    min-width: 160px;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 100; /* Keeps it above table rows */
    overflow: hidden;
}

.action-menu-content.show {
    display: block;
}

.action-menu-content button {
    color: var(--brand-grey);
    padding: 12px 15px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    border-bottom: 1px solid #f8f9fa;
    transition: background 0.2s;
}

.action-menu-content button:last-child {
    border-bottom: none;
}

.action-menu-content button:hover {
    background-color: #f8f9fa;
    color: var(--brand-purple);
}

.action-menu-content button.menu-delete:hover {
    background-color: #ffe6e6;
    color: #dc3545;
}