/* --- 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;
}

/* --- Grid Auto-Fit KPI Container (global utility) --- */
.grid-autofit-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    width: 100%;
    margin-bottom: 2rem;
    box-sizing: border-box;
}

/* --- Unified Command KPI Cards & Tooltips --- */
.command-cards-row-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    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);
    transition: all 0.15s ease-in-out;
}

/* Responsive adaptations for KPI Command Cards */
@media (max-width: 1023px) {
    .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: 767px) {
    .command-card {
        flex: 1 1 calc(50% - 0.5rem) !important;
        height: 130px !important;
    }

    .command-card-value {
        font-size: 1.8rem !important;
    }
    .command-card-label {
        font-size: 0.75rem !important;
    }
    .command-card-icon-wrapper {
        font-size: 0.85rem !important;
    }
}

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

    .command-card-value {
        font-size: 1.55rem !important;
    }
    .command-card-label {
        font-size: 0.7rem !important;
    }
    .command-card-icon-wrapper {
        font-size: 0.78rem !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: 767px) {
    .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;
    }

    .card-title-icon {
        font-size: 1rem !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: 1024px) {
    /* Styles are defined in core */
}

/* Tablet / Laptop (Mid-screen sizes) */
@media (max-width: 1023px) and (min-width: 768px) {
    .card-third-width {
        flex: 1 1 calc(50% - 0.75rem) !important;
        min-width: 300px !important;
        height: auto !important;
        min-height: 360px !important;
    }
    
    .donut-legend-wrapper {
        flex-direction: row !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .donut-legend-wrapper > div:first-child {
        flex: 0 0 160px !important;
        max-width: 160px !important;
    }

    .donut-legend-container {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: none !important;
        flex-direction: column !important;
        gap: 0.35rem !important;
        margin-top: 0 !important;
    }

    .donut-legend-pill {
        padding: 0.35rem 0.7rem !important;
        width: 100% !important;
    }
    
    .donut-legend-label {
        font-size: 0.78rem !important;
        max-width: 130px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .donut-legend-value {
        font-size: 0.88rem !important;
        margin-left: auto !important;
    }
    
    .donut-legend-dot {
        width: 8px !important;
        height: 8px !important;
        margin-right: 0.5rem !important;
    }
}

/* Mobile (Small-screen viewports) */
@media (max-width: 767px) {
    .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-wrapper {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .donut-legend-wrapper > div:first-child {
        flex: 0 0 140px !important;
        max-width: 140px !important;
    }

    .donut-legend-container {
        flex: 1 1 auto !important;
        flex-direction: column !important;
        width: auto !important;
        max-width: none !important;
        max-height: none !important;
        gap: 0.3rem !important;
        margin-top: 0 !important;
        min-width: 0 !important;
    }
    
    .donut-legend-pill {
        flex: 0 0 auto !important;
        width: 100% !important;
        padding: 0.35rem 0.65rem !important;
        min-width: 0 !important;
    }
    
    .donut-legend-label {
        font-size: 0.72rem !important;
        max-width: 100px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    .donut-legend-value {
        font-size: 0.82rem !important;
        margin-left: auto !important;
    }
    
    .donut-legend-icon {
        font-size: 0.8rem !important;
        margin-right: 0.35rem !important;
    }
    
    .donut-legend-dot {
        width: 7px !important;
        height: 7px !important;
        margin-right: 0.4rem !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;
    }
}

/* Very small mobile: tighter donut layout */
@media (max-width: 480px) {
    .donut-legend-wrapper {
        gap: 0.5rem !important;
    }
    .donut-legend-wrapper > div:first-child {
        flex: 0 0 110px !important;
        max-width: 110px !important;
    }
    .donut-legend-pill {
        padding: 0.25rem 0.5rem !important;
    }
    .donut-legend-label {
        font-size: 0.65rem !important;
        max-width: 80px !important;
    }
    .donut-legend-value {
        font-size: 0.75rem !important;
    }
    .donut-legend-dot {
        width: 6px !important;
        height: 6px !important;
        margin-right: 0.3rem !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);
}

/* --- Responsive Chart Height Overrides --- */
/* These override fixed inline heights set by Python layouts.
   The selector targets Plotly graph containers inside chart cards. */

@media (max-width: 767px) {
    .chart-card dcc-graph,
    .chart-card .dash-graph {
        min-height: 180px !important;
    }

    /* Override inline fixed heights for common chart sizes */
    .chart-card [style*="height: 380px"] {
        height: 280px !important;
        min-height: 240px !important;
    }

    .chart-card [style*="height: 320px"] {
        height: 240px !important;
        min-height: 200px !important;
    }

    .chart-card [style*="height: 280px"] {
        height: 220px !important;
        min-height: 180px !important;
    }

    .chart-card [style*="height: 240px"] {
        height: 180px !important;
    }

    .chart-card [style*="height: 200px"] {
        height: 160px !important;
    }

    .chart-card [style*="height: 370px"],
    .chart-card [style*="height: 400px"] {
        height: 300px !important;
    }

    .chart-card [style*="height: 480px"],
    .chart-card [style*="height: 500px"],
    .chart-card [style*="height: 520px"],
    .chart-card [style*="height: 530px"] {
        height: 340px !important;
        min-height: 280px !important;
    }

    .chart-card .donut-legend-wrapper [style*="height: 200px"],
    .chart-card .donut-legend-wrapper [style*="height: 240px"] {
        height: 160px !important;
    }

    /* Missing overrides for uncovered heights */
    .chart-card [style*="height: 250px"] {
        height: 190px !important;
    }
    .chart-card [style*="height: 290px"] {
        height: 230px !important;
    }
    .chart-card [style*="height: 300px"] {
        height: 240px !important;
    }
    .chart-card [style*="height: 330px"] {
        height: 260px !important;
    }
    .chart-card [style*="height: 340px"] {
        height: 270px !important;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .chart-card [style*="height: 380px"] {
        height: 320px !important;
    }

    .chart-card [style*="height: 320px"] {
        height: 270px !important;
    }

    .chart-card [style*="height: 480px"],
    .chart-card [style*="height: 500px"],
    .chart-card [style*="height: 520px"],
    .chart-card [style*="height: 530px"] {
        height: 400px !important;
    }

    .chart-card [style*="height: 370px"],
    .chart-card [style*="height: 400px"] {
        height: 340px !important;
    }

    .chart-card [style*="height: 250px"] {
        height: 210px !important;
    }
    .chart-card [style*="height: 290px"] {
        height: 250px !important;
    }
    .chart-card [style*="height: 300px"] {
        height: 260px !important;
    }
    .chart-card [style*="height: 330px"] {
        height: 290px !important;
    }
    .chart-card [style*="height: 340px"] {
        height: 300px !important;
    }
}

/* --- Plotly SVG safety (prevents overflow on mobile) --- */
.chart-card .main-svg {
    overflow: visible !important;
}

.chart-card svg {
    max-width: 100% !important;
}

@media (max-width: 767px) {
    /* Cap Plotly legend width so it doesn't push chart area off-screen */
    .chart-card .legend {
        max-width: 85px !important;
    }

    /* Ensure hover tooltips stay within card bounds */
    .chart-card .hoverlayer {
        max-width: calc(100vw - 2rem) !important;
    }

    .chart-card .hovertext {
        font-size: 0.7rem !important;
        max-width: 200px !important;
        word-wrap: break-word !important;
    }

    /* Ensure map badges don't overflow on small screens */
    .unspecified-locations-badge {
        top: 8px !important;
        left: 8px !important;
        padding: 6px 10px !important;
        gap: 0.3rem !important;
    }
    .unspecified-locations-badge span {
        font-size: 0.7rem !important;
    }
}

/* --- 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;
}

