/* --- Elegant SaaS Dashboard Cards --- */
.chart-card {
    background: var(--dash-card);
    border: 1px solid var(--dash-border);
    border-radius: 24px; /* Highly rounded clean corners, matching modern references */
    padding: 2.25rem;
    box-shadow: var(--card-shadow);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.4s ease,
                border-color 0.4s ease;
    position: relative;
    overflow: hidden;
}

.chart-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow);
    border-color: rgba(124, 58, 237, 0.2);
}

/* Remove gradient border strips on cards for a cleaner, unified minimalist aesthetic */
.chart-card::before {
    display: none;
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Align center vertically for clean side-by-side layout */
    margin-bottom: 1rem;
    flex-wrap: wrap; /* Wrap elements gracefully to avoid overlap */
    gap: 1rem;
}

.card-title-section {
    display: flex;
    flex-direction: column;
    flex: 1; /* Allow title to shrink/wrap internally */
    min-width: 0;
}

.card-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-title-icon {
    color: var(--accent-purple);
    font-size: 1.25rem;
    display: flex;
    align-items: center;
}

.card-main-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.2px;
    margin: 0;
}

.card-subtitle {
    color: var(--text-sub);
    font-size: 0.8rem;
    font-weight: 500;
    margin: 0.25rem 0 0 0;
}

/* --- Unified Command KPI Cards & Tooltips --- */
.command-cards-row-container {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap; /* Forces cards on a single row on desktop */
    gap: 1.15rem; /* Cozy desktop gap to prevent horizontal overflow */
    width: 100%;
    margin-bottom: 2.25rem;
    box-sizing: border-box;
}

.command-card {
    background: var(--dash-card);
    border: 1px solid var(--dash-border);
    border-radius: 20px;
    padding: 1.25rem 1.15rem; /* Elegant padding to give longer text labels breathing space */
    flex: 1 1 0px; /* Equal widths, scales organically */
    min-width: 140px; /* Secure shrinking boundary */
    box-shadow: var(--card-shadow);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s ease;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 135px; /* Increased from 120px for ample text height spacing */
    position: relative; /* Absolutely required for top-right info tooltip icon */
}

.command-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px -10px rgba(15, 23, 42, 0.08);
}

.command-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.command-card-label {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-sub);
}

.command-card-icon-wrapper {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}

/* Icon theme colors */
.wrapper-indigo { background: rgba(99, 102, 241, 0.08); color: var(--accent-indigo); }
.wrapper-teal { background: rgba(16, 185, 129, 0.08); color: var(--accent-teal); }
.wrapper-orange { background: rgba(249, 115, 22, 0.08); color: var(--accent-orange); }
.wrapper-purple { background: rgba(124, 58, 237, 0.08); color: var(--accent-purple); }
.wrapper-coral { background: rgba(244, 63, 94, 0.08); color: var(--accent-coral); }

.command-card-value {
    font-family: 'Outfit', 'Plus Jakarta Sans', sans-serif;
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin-top: 0.75rem;
    transition: opacity 0.3s ease,
                filter 0.3s ease,
                transform 0.3s ease;
    font-variant-numeric: tabular-nums;
}

/* Micro-animation for KPI cards loading state */
.command-card-value[data-dash-is-loading="true"] {
    opacity: 0.4;
    filter: blur(1.5px);
    transform: scale(0.97);
    animation: kpiPulseShimmer 1.5s infinite ease-in-out;
    transition: all 0.15s ease-in-out;
}

@keyframes kpiPulseShimmer {
    0% { opacity: 0.4; }
    50% { opacity: 0.75; }
    100% { opacity: 0.4; }
}

/* Responsive adaptations for KPI Command Cards */
@media (max-width: 1100px) {
    .command-cards-row-container {
        flex-wrap: wrap !important;
        gap: 1rem !important;
    }
    .command-card {
        flex: 1 1 calc(33.33% - 0.75rem) !important;
        min-width: 160px !important;
    }
}

@media (max-width: 768px) {
    .command-card {
        flex: 1 1 calc(50% - 0.5rem) !important;
        height: 130px !important;
    }
}

@media (max-width: 480px) {
    .command-card {
        flex: 1 1 100% !important;
    }

    .command-card-value {
        font-size: 1.7rem !important;
    }
}

/* --- Responsive Flex and Grid Utilities --- */
.responsive-flex-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1rem 0;
    width: 100%;
    box-sizing: border-box;
}

.card-half-width {
    flex: 1 1 calc(50% - 0.75rem);
    min-width: 450px;
    height: 500px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.card-full-width {
    flex: 1 1 100%;
    min-width: 100%;
    height: 650px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin-top: 1.5rem;
}

@media (max-width: 768px) {
    .card-half-width {
        min-width: 100% !important;
        height: auto !important;
        min-height: 480px;
    }
    
    .card-full-width {
        height: auto !important;
        min-height: 400px;
        margin-top: 1rem !important;
    }
    
    .chart-card {
        padding: 1.5rem !important;
        border-radius: 18px !important;
    }

    .card-main-title {
        font-size: 1rem !important;
    }

    .card-subtitle {
        font-size: 0.72rem !important;
    }
}

.clickable-card {
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s ease !important;
}

.clickable-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 15px 30px -10px rgba(124, 58, 237, 0.15), 0 0 0 1px rgba(124, 58, 237, 0.2) !important;
}

.clickable-card:active {
    transform: translateY(-1px) scale(0.99);
}

/* Absolute Positioning for KPI Hover Info Tooltip Wrapper Badge */
.command-card-tooltip-wrapper {
    position: absolute;
    bottom: 20px;
    right: 23px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10 !important;
    background: #E2E8F0; /* Slate-200 — very light, unobtrusive */
    border: 1px solid #CBD5E1; /* Slate-300 border */
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10);
}

/* Child Bootstrap Icon Styling Centered Inside Circular Badge */
.command-card-tooltip-wrapper .command-card-info-icon {
    font-size: 0.78rem;
    color: #64748B !important; /* Slate-500 — balanced contrast on light badge */
    transition: color 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.command-card-tooltip-wrapper:hover {
    background: var(--accent-purple) !important; /* Reactive solid purple hover state */
    border-color: var(--accent-purple) !important;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(124, 58, 237, 0.2);
    z-index: 99999 !important; /* Elevate hovered tooltip above other stacking contexts */
}

.command-card-tooltip-wrapper:hover .command-card-info-icon {
    color: #FFFFFF !important;
}

/* CSS-Based Custom Tooltip Popover (Appears above the bottom-right badge) */
.command-card-tooltip-wrapper::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 10px); /* Positioned above the badge */
    right: -10px;
    width: 220px;
    padding: 10px 14px;
    border-radius: 12px;
    background: #0F172A; /* Slate 900 midnight theme */
    color: #FFFFFF;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.5;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif !important;
    text-align: left;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.25), 0 8px 16px -6px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.95);
    transition: opacity 0.25s ease,
                transform 0.25s ease;
    white-space: normal;
    z-index: 999 !important;
}

/* Custom Tooltip Pointer Arrow (pointing downward toward the badge) */
.command-card-tooltip-wrapper::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    right: 6px;
    border-width: 6px;
    border-style: solid;
    border-color: #0F172A transparent transparent transparent;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.95);
    transition: opacity 0.25s ease,
                transform 0.25s ease;
    z-index: 999 !important;
}

/* Active Hover Transitions */
.command-card-tooltip-wrapper:hover::before,
.command-card-tooltip-wrapper:hover::after {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.command-card-info-icon::before {
    font-family: 'bootstrap-icons' !important;
}

/* --- Profile Metric Card Tooltip Styling --- */
.profile-metric-item {
    position: relative; /* Absolutely required for bottom-right info tooltip icon */
}

/* Absolute Positioning for Profile Metric Hover Info Tooltip Wrapper Badge */
.profile-metric-tooltip-wrapper {
    position: absolute;
    bottom: 12px;
    right: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10 !important;
    background: #E2E8F0; /* Slate-200 — very light, unobtrusive */
    border: 1px solid #CBD5E1; /* Slate-300 border */
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10);
}

/* Child Bootstrap Icon Styling Centered Inside Circular Badge */
.profile-metric-tooltip-wrapper .profile-metric-info-icon {
    font-size: 0.72rem;
    color: #64748B !important; /* Slate-500 — balanced contrast */
    transition: color 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.profile-metric-tooltip-wrapper:hover {
    background: var(--accent-purple) !important; /* Reactive solid purple hover state */
    border-color: var(--accent-purple) !important;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(124, 58, 237, 0.2);
    z-index: 99999 !important; /* Elevate hovered tooltip above other stacking contexts */
}

.profile-metric-tooltip-wrapper:hover .profile-metric-info-icon {
    color: #FFFFFF !important;
}

/* CSS-Based Custom Tooltip Popover (Appears above the bottom-right badge) */
.profile-metric-tooltip-wrapper::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 10px); /* Positioned above the badge */
    right: -10px;
    width: 220px;
    padding: 10px 14px;
    border-radius: 12px;
    background: #0F172A; /* Slate 900 midnight theme */
    color: #FFFFFF;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.5;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif !important;
    text-align: left;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.25), 0 8px 16px -6px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: normal;
    z-index: 999 !important;
}

/* Custom Tooltip Pointer Arrow (pointing downward toward the badge) */
.profile-metric-tooltip-wrapper::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    right: 4px;
    border-width: 6px;
    border-style: solid;
    border-color: #0F172A transparent transparent transparent;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 999 !important;
}

/* Active Hover Transitions */
.profile-metric-tooltip-wrapper:hover::before,
.profile-metric-tooltip-wrapper:hover::after {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.profile-metric-info-icon::before {
    font-family: 'bootstrap-icons' !important;
}


/* --- Card Third Width Layout Column --- */
.card-third-width {
    flex: 1 1 calc(33.333% - 1rem);
    min-width: 320px;
    height: 450px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* --- Responsive Custom Donut Legends --- */
.donut-legend-wrapper {
    display: flex;
    flex-direction: column; /* stacked vertically below the chart */
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem; /* compact gap */
    width: 100%;
}

.donut-legend-container {
    display: flex;
    flex-direction: row; /* Horizontal flow for pills on desktop/tablet */
    flex-wrap: wrap; /* wraps to next row */
    justify-content: center; /* centered items */
    gap: 0.5rem;
    width: 100%;
    max-width: 340px; /* comfortably fits 2 columns with full labels */
    margin-top: -0.25rem; /* pulls closer to graph */
}

.donut-legend-pill {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.4rem 0.85rem;
    border-radius: 99px; /* Premium capsule layout */
    background: #F8FAFC;
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    width: auto; /* Fits content width naturally on desktop */
    flex: 0 1 auto;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.donut-legend-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.04);
}

.donut-legend-left {
    display: flex;
    align-items: center;
    min-width: 0;
}

.donut-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.donut-legend-icon {
    font-size: 1rem;
    margin-right: 0.65rem;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.donut-legend-label {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 600;
    color: #475569;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.donut-legend-value {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: #0F172A;
    font-size: 1rem;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

/* --- 3-Device Responsive Structure for Donut Legends & Cards --- */

/* Desktop (Default Layout) */
@media (min-width: 1101px) {
    /* Styles are defined in core */
}

/* Tablet / Laptop (Mid-screen sizes) */
@media (max-width: 1100px) and (min-width: 769px) {
    .card-third-width {
        flex: 1 1 calc(50% - 0.75rem) !important;
        min-width: 440px !important;
        height: 440px !important;
    }
    
    .donut-legend-pill {
        padding: 0.45rem 0.75rem !important;
    }
    
    .donut-legend-label {
        font-size: 0.8rem !important;
    }
    
    .donut-legend-value {
        font-size: 0.92rem !important;
    }
    
    .donut-legend-dot {
        width: 8px !important;
        height: 8px !important;
        margin-right: 0.6rem !important;
    }
}

/* Mobile (Small-screen viewports) */
@media (max-width: 768px) {
    .card-third-width {
        flex: 1 1 100% !important;
        min-width: 100% !important;
        height: auto !important;
        min-height: 330px !important;
    }
    
    .card-half-width {
        min-width: 100% !important;
        height: auto !important;
        min-height: 340px !important;
    }
    
    .donut-legend-container {
        flex-direction: column !important;
        width: 100% !important;
        max-width: 280px !important;
        max-height: none !important;
        gap: 0.4rem !important;
        margin-top: -0.25rem !important; /* pull legends closer to the chart on mobile */
    }
    
    .donut-legend-pill {
        flex: 1 1 100% !important;
        width: 100% !important;
        padding: 0.45rem 0.75rem !important;
    }
    
    .donut-legend-label {
        font-size: 0.75rem !important;
    }
    
    .donut-legend-value {
        font-size: 0.85rem !important;
    }
    
    .donut-legend-icon {
        font-size: 0.9rem !important;
        margin-right: 0.5rem !important;
    }
    
    .donut-legend-dot {
        width: 8px !important;
        height: 8px !important;
        margin-right: 0.5rem !important;
    }

    /* Compact responsive table rules for mobile viewports */
    #dietitian-recent-non-compliant-table-wrapper .premium-table th {
        font-size: 0.65rem !important;
        padding: 0.4rem 0.6rem !important;
    }
    #dietitian-recent-non-compliant-table-wrapper .premium-table td {
        font-size: 0.72rem !important;
        padding: 0.6rem 0.6rem !important;
    }
    #dietitian-recent-non-compliant-table-wrapper .premium-table td span {
        font-size: 0.68rem !important;
    }
}

/* --- Sticky Patient Name Layout for Alerts Table --- */
#dietitian-recent-non-compliant-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

#dietitian-recent-non-compliant-table-wrapper .premium-table th:first-child,
#dietitian-recent-non-compliant-table-wrapper .premium-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--dash-card);
    z-index: 2;
    border-right: 1px solid var(--dash-border);
}

/* --- Per-chart Filter Dropdown --- */
.chart-filter-dropdown {
    flex-shrink: 0;
    min-width: 140px;
}

.dash-dropdown-xs .Select-control {
    min-height: 28px !important;
    height: 28px !important;
    border-radius: 8px !important;
    font-size: 0.72rem !important;
}

.dash-dropdown-xs .Select-placeholder,
.dash-dropdown-xs .Select-input,
.dash-dropdown-xs .Select-value-label {
    line-height: 28px !important;
    height: 28px !important;
    font-size: 0.72rem !important;
}

.dash-dropdown-xs .Select-arrow {
    margin-top: 2px !important;
}

/* --- Heatmap Table Styles --- */
.heatmap-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.82rem;
}

.heatmap-table th {
    padding: 0.75rem 1rem;
    text-align: center;
    font-weight: 700;
    color: var(--text-main);
    background: var(--dash-bg);
    border-bottom: 2px solid var(--dash-border);
    white-space: nowrap;
}

.heatmap-table td {
    padding: 0.65rem 1rem;
    text-align: center;
    font-weight: 600;
    border-bottom: 1px solid var(--dash-border);
    white-space: nowrap;
}

.heatmap-table tr:hover td {
    background: rgba(59, 130, 246, 0.04);
}

.heatmap-cell {
    display: inline-block;
    min-width: 48px;
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    font-weight: 700;
}

/* --- Focus Visible States --- */
.chart-card:focus-visible,
.command-card:focus-visible,
.clickable-card:focus-visible {
    outline: 2px solid var(--accent-purple, #7C3AED);
    outline-offset: 2px;
}

.command-card-tooltip-wrapper:focus-visible {
    outline: 2px solid var(--accent-purple, #7C3AED);
    outline-offset: 2px;
}

