/* ============================================================================
   ANALYTICS
   The CDR dashboards (pbx/analytics): the dashboard page, its widget cards
   and the widgets' own content.
   ============================================================================ */

/* ----------------------------------------------------------------------------
   Dashboard page frame
   ---------------------------------------------------------------------------- */

/* A dashboard with a max width set caps the page frame (dashboard.html puts
   the value on <html>). */
html[data-dash-width] .page-inner {
    max-width: var(--dash-max-width);
}

.dash-editing-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 0.5rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: rgba(var(--color-blue-rgb), 0.14);
    color: var(--color-blue);
    font-size: 0.7rem;
    font-weight: var(--font-weight-strong);
    letter-spacing: 0.02em;
    vertical-align: middle;
}

.dash-range-form {
    min-width: 15rem;
    padding: 0.25rem 0.75rem 0.5rem;
}

/* ----------------------------------------------------------------------------
   Widget grid and cards (includes/widget_col.html)

   Twelve columns; a card spans its widget's `columns`. Every part of a card
   (header, body, footer) sits on one inset, --dash-pad, so text lines up
   down the card and never touches its edge.
   ---------------------------------------------------------------------------- */

.dash-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1rem;
    padding-bottom: 1.5rem;
}

.dash-cell {
    grid-column: span var(--span, 12);
    min-width: 0;
}

/* Tablet: thirds and quarters double up, so nothing gets narrower than half. */
@media (max-width: 1199.98px) {
    .dash-cell {
        grid-column: span max(var(--span, 12), 6);
    }
}

@media (max-width: 767.98px) {
    .dash-grid {
        gap: 0.75rem;
    }

    .dash-cell {
        grid-column: 1 / -1;
    }
}

.dash-card {
    --dash-pad: 1.125rem;
    container: dash-card / inline-size;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
}

@media (max-width: 575.98px) {
    .dash-card {
        --dash-pad: 0.875rem;
    }
}

/* No surface to pad: the content lines up with the grid edges. */
.dash-card.is-transparent {
    --dash-pad: 0;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.dash-grid.is-editing .dash-card {
    border: 1px dashed var(--border-emphasis);
}

/* --- Header ---------------------------------------------------------------- */

.dash-card-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.5rem;
    padding: var(--dash-pad) var(--dash-pad) 0;
}

.dash-card-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: var(--font-weight-heading);
    letter-spacing: var(--heading-tracking);
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-card-title.is-placeholder {
    color: var(--text-tertiary);
    font-weight: var(--font-weight-body);
}

.dash-card-meta {
    display: flex;
    align-items: center;
    flex: none;
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.dash-card-updated {
    border-radius: 4px;
    cursor: default;
}

.dash-card-updated:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.dash-card-type {
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--border-normal);
    border-radius: 999px;
    color: var(--text-tertiary);
}

/* A narrow card keeps its title and drops the type pill. */
@container dash-card (max-width: 28rem) {
    .dash-card-type {
        display: none;
    }
}

.dash-card-tools {
    display: flex;
    flex: none;
    gap: 0.25rem;
    margin-right: -0.375rem;
}

/* 32px visible, 40px to the pointer: the ::before extends the hit area. */
.dash-card-tool {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.dash-card-tool::before {
    content: "";
    position: absolute;
    inset: -4px;
}

.dash-card-tool:hover {
    background: var(--surface-3);
    color: var(--text-primary);
}

.dash-card-tool.is-danger:hover {
    background: rgba(var(--color-red-rgb), 0.12);
    color: var(--color-red);
}

.dash-card-tool:active {
    transform: scale(0.96);
}

.dash-card-tool:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 1px;
}

/* --- Body and footer -------------------------------------------------------- */

.dash-card-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    padding: var(--dash-pad);
    container-type: inline-size;
}

.dash-card-head + .dash-card-body {
    padding-top: 0.875rem;
}

/* A fixed height (the widget's height_px) is the body's height: the chart
   fills it and stops at a floor rather than being clipped. */
.dash-card.has-fixed-height .dash-card-body {
    min-height: var(--widget-height);
}

.dash-card-body > * {
    flex: 1 1 auto;
}

.dash-card-foot {
    display: flex;
    justify-content: flex-end;
    margin-top: calc(var(--dash-pad) * -0.5);
    padding: 0 var(--dash-pad) var(--dash-pad);
    color: var(--text-muted);
    font-size: 0.75rem;
}

.dash-card.is-transparent .dash-card-foot {
    margin-top: 0.375rem;
}

/* --- Loading, empty and error states ---------------------------------------- */

.dash-skeleton {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dash-skeleton-line,
.dash-skeleton-block {
    display: block;
    border-radius: 6px;
    background-color: var(--surface-2);
    background-image: linear-gradient(
        90deg,
        rgba(var(--ink-rgb), 0) 30%,
        rgba(var(--ink-rgb), 0.05) 50%,
        rgba(var(--ink-rgb), 0) 70%
    );
    background-size: 300% 100%;
    background-repeat: no-repeat;
    animation: dash-shimmer 1.6s ease-in-out infinite;
}

.dash-skeleton-line {
    width: 40%;
    height: 0.75rem;
}

.dash-skeleton-block {
    height: 13rem;
    border-radius: 8px;
}

.dash-card.has-fixed-height .dash-skeleton-block {
    flex: 1 1 auto;
    height: auto;
    min-height: 4rem;
}

.dash-skeleton.is-compact {
    flex-direction: row;
    align-items: center;
}

.dash-skeleton.is-compact .dash-skeleton-line {
    order: 2;
    width: 50%;
}

.dash-skeleton.is-compact .dash-skeleton-block {
    width: 2.5rem;
    height: 2.5rem;
}

@keyframes dash-shimmer {
    from { background-position: 100% 0; }
    to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    .dash-skeleton-line,
    .dash-skeleton-block {
        animation: none;
    }
}

.dash-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-height: 12rem;
    padding: 1.5rem 1rem;
    border: 1px dashed var(--border-normal);
    border-radius: 10px;
    text-align: center;
}

.dash-empty > i {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 1.5rem;
    opacity: 0.7;
}

.dash-empty-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: var(--font-weight-strong);
}

.dash-empty-subtitle {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-wrap: pretty;
}

.dash-card-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.875rem;
    border-radius: 8px;
    background: rgba(var(--color-red-rgb), 0.08);
    color: var(--color-red);
    font-size: 0.85rem;
}

/* ----------------------------------------------------------------------------
   Chart widgets (dashboard_widgets/chart.html, chart_widget.js)
   ---------------------------------------------------------------------------- */

.chart-widget {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    min-width: 0;
}

/* Auto height is proportional to the card's width (a canvas has no height
   of its own): 2:1, never below a floor or taller than the viewport allows. */
.chart-plot {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 1;
    min-height: 16rem;
    max-height: min(70vh, 40rem);
}

/* The canvas is out of flow, so the plot's size comes from the layout alone
   and Chart.js never feeds its own height back into it. */
.chart-plot > canvas {
    position: absolute;
    inset: 0;
}

/* A fixed-height widget: the plot takes what the legend leaves. */
.dash-card.has-fixed-height .chart-plot {
    flex: 1 1 auto;
    aspect-ratio: auto;
    height: auto;
    min-height: 10rem;
    max-height: none;
}

/* --- Legend: a line key, the name, the total -------------------------------- */

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem 1.25rem;
    margin: 0;
    font-size: 0.8rem;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-tertiary);
    font: inherit;
    text-align: left;
}

button.chart-legend-item {
    cursor: pointer;
    border-radius: 6px;
}

button.chart-legend-item:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.chart-legend-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-legend-value {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.chart-legend-share {
    color: var(--text-muted);
}

/* The identity key: a short stroke of the series color. */
.chart-key {
    flex: none;
    width: 0.875rem;
    height: 3px;
    border-radius: 2px;
}

/* --- Doughnut and pie: ring beside a legend of values ---------------------- */

.chart-widget-doughnut,
.chart-widget-pie {
    display: grid;
    grid-template-areas: "plot" "legend";
    gap: 1rem;
}

.chart-widget-doughnut .chart-plot,
.chart-widget-pie .chart-plot {
    grid-area: plot;
    aspect-ratio: auto;
    height: 13.5rem;
    min-height: 0;
    max-height: none;
}

.chart-widget-doughnut .chart-legend,
.chart-widget-pie .chart-legend {
    grid-area: legend;
    flex-direction: column;
    gap: 0;
    align-self: center;
}

.chart-widget-doughnut .chart-legend-item,
.chart-widget-pie .chart-legend-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto 3rem;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 0.5rem;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}

.chart-widget-doughnut .chart-legend-item + .chart-legend-item,
.chart-widget-pie .chart-legend-item + .chart-legend-item {
    box-shadow: inset 0 1px 0 var(--border-subtle);
}

.chart-widget-doughnut button.chart-legend-item:hover,
.chart-widget-pie button.chart-legend-item:hover {
    background: var(--surface-2);
}

.chart-widget-doughnut .chart-legend-share,
.chart-widget-pie .chart-legend-share {
    text-align: right;
}

.chart-widget-doughnut .chart-key,
.chart-widget-pie .chart-key {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 3px;
}

@container (min-width: 30rem) {
    .chart-widget-doughnut,
    .chart-widget-pie {
        grid-template-areas: "plot legend";
        grid-template-columns: minmax(0, 1fr) minmax(13rem, 1fr);
        gap: 1.5rem;
        align-items: center;
    }

    .chart-widget-doughnut .chart-plot,
    .chart-widget-pie .chart-plot {
        height: 15rem;
    }
}

/* A fixed-height widget: the ring's row takes what the legend leaves. */
.dash-card.has-fixed-height .chart-widget-doughnut,
.dash-card.has-fixed-height .chart-widget-pie {
    grid-template-rows: minmax(10rem, 1fr) auto;
}

.dash-card.has-fixed-height .chart-widget-doughnut .chart-plot,
.dash-card.has-fixed-height .chart-widget-pie .chart-plot {
    align-self: stretch;
    height: auto;
    min-height: 10rem;
}

@container (min-width: 30rem) {
    .dash-card.has-fixed-height .chart-widget-doughnut,
    .dash-card.has-fixed-height .chart-widget-pie {
        grid-template-rows: minmax(10rem, 1fr);
    }
}

.chart-total {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translate(-50%, -50%);
    pointer-events: none;
    text-align: center;
}

.chart-total[hidden] {
    display: none;
}

.chart-total-value {
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: var(--font-weight-heading);
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.chart-total-label {
    margin-top: 0.15rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* --- Tooltip: values lead, names follow ------------------------------------- */

.chart-tooltip,
.org-volume-tooltip {
    position: absolute;
    z-index: 2;
    min-width: 11rem;
    max-width: 18rem;
    padding: 0.6rem 0.75rem;
    background: var(--menu-bg);
    border: 1px solid var(--menu-border);
    border-radius: 8px;
    box-shadow: var(--menu-shadow);
    pointer-events: none;
    font-size: 0.8rem;
}

.chart-tooltip {
    top: 0;
    left: 0;
    contain: layout style;
}

.chart-tooltip-title,
.org-volume-tooltip-title {
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
    font-weight: var(--font-weight-strong);
}

.chart-tooltip-row,
.chart-tooltip-foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1.6;
}

.chart-tooltip-value {
    min-width: 2.5rem;
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.chart-tooltip-name {
    overflow: hidden;
    color: var(--text-tertiary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-tooltip-extra {
    margin-left: auto;
    padding-left: 0.75rem;
    color: var(--text-muted);
}

.chart-tooltip-foot {
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border-normal);
}

/* Rows with no key start flush at the keys' left edge. */
.chart-tooltip-foot .chart-tooltip-value {
    min-width: 0;
    color: var(--text-secondary);
    text-align: left;
}

/* --- Click-through list (shown in a SweetAlert) ---------------------------- */

.chart-drill {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    text-align: left;
}

.chart-drill-hint {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chart-drill-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

a.chart-drill-row:hover {
    background: var(--surface-2);
    border-color: var(--border-normal);
    color: var(--text-primary);
    text-decoration: none;
}

.chart-drill-value {
    margin-left: auto;
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.chart-drill-open {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ----------------------------------------------------------------------------
   Summary stat tiles (dashboard_widgets/text_summary.html)
   ---------------------------------------------------------------------------- */

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    align-content: start;
    gap: 0.75rem;
}

.stat-tiles.is-vertical {
    grid-template-columns: minmax(0, 1fr);
}

.stat-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.375rem;
    min-width: 0;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--bg-raise);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.stat-tile:hover {
    border-color: var(--border-emphasis);
    background: var(--surface-3);
}

.stat-tile:active {
    transform: scale(0.98);
}

.stat-tile:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.stat-tile-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    font-weight: var(--font-weight-strong);
}

.stat-tile-key {
    flex: none;
    width: 0.875rem;
    height: 3px;
    border-radius: 2px;
    background: var(--key-color);
}

.stat-tile-value {
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: var(--font-weight-heading);
    letter-spacing: -0.015em;
    line-height: 1.1;
}

.stat-tile-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: color 0.15s ease;
}

.stat-tile-link .fas {
    font-size: 0.65rem;
    transition: transform 0.15s ease;
}

.stat-tile:hover .stat-tile-link {
    color: var(--color-blue);
}

.stat-tile:hover .stat-tile-link .fas {
    transform: translateX(2px);
}

/* A narrow card lists the totals as rows: label left, number right. */
@container (max-width: 24rem) {
    .stat-tiles {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.5rem;
    }

    .stat-tile {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "label value" "link value";
        align-items: center;
        gap: 0.125rem 1rem;
        padding: 0.75rem 0.875rem;
    }

    .stat-tile-label { grid-area: label; }
    .stat-tile-link { grid-area: link; }

    .stat-tile-value {
        grid-area: value;
        font-size: 1.375rem;
    }
}

/* ----------------------------------------------------------------------------
   Link widget (dashboard_widgets/link_widget.html): the whole card is the link
   ---------------------------------------------------------------------------- */

.dash-card.is-link .dash-card-body {
    padding: 0;
}

.dash-card.is-link .dash-card-head + .dash-card-body {
    padding-top: 0;
}

.dash-link {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-height: 4.5rem;
    padding: var(--dash-pad);
    border-radius: 11px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background-color 0.15s ease;
}

a.dash-link:hover,
a.dash-link:focus-visible {
    background: var(--bg-raise);
    color: var(--text-primary);
    text-decoration: none;
}

a.dash-link:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: -2px;
}

.dash-link-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    background: rgba(var(--link-tint), 0.14);
    color: rgb(var(--link-tint));
    font-size: 1rem;
}

.dash-link-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 0.95rem;
    font-weight: var(--font-weight-strong);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-link-note {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: var(--font-weight-body);
    white-space: normal;
}

.dash-link-arrow {
    flex: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: color 0.15s ease, transform 0.15s ease;
}

a.dash-link:hover .dash-link-arrow {
    color: var(--text-secondary);
    transform: translateX(2px);
}

.dash-link.is-broken .dash-link-icon {
    opacity: 0.6;
}

/* ----------------------------------------------------------------------------
   Dashboard list (dashboard_list.html)
   ---------------------------------------------------------------------------- */

/* Outranks tables.css `td a.cell-link { display: inline-block }`. */
td a.cell-link.dash-list-name {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.dash-list-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    background: rgba(var(--color-blue-rgb), 0.12);
    color: var(--color-blue);
    font-size: 0.8rem;
}

.dash-list-title {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.dash-list-count {
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.dash-list-count.is-zero {
    color: var(--text-muted);
}

/* ----------------------------------------------------------------------------
   Widget modals (includes/add_widget_modal.html, the widget forms)
   ---------------------------------------------------------------------------- */

.widget-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    border: 0;
}

.widget-picker-option {
    position: relative;
    margin: 0;
}

.widget-picker-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.widget-picker-tile {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.125rem 0.75rem;
    height: 100%;
    margin: 0;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border-normal);
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.widget-picker-tile:hover {
    border-color: var(--border-emphasis);
    background: var(--surface-2);
}

.widget-picker-option input:focus-visible + .widget-picker-tile {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.widget-picker-option input:checked + .widget-picker-tile {
    border-color: var(--color-blue);
    background: rgba(var(--color-blue-rgb), 0.08);
    box-shadow: inset 0 0 0 1px var(--color-blue);
}

.widget-picker-icon {
    display: inline-flex;
    grid-row: span 2;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 8px;
    background: var(--surface-3);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.widget-picker-option input:checked + .widget-picker-tile .widget-picker-icon {
    background: rgba(var(--color-blue-rgb), 0.16);
    color: var(--color-blue);
}

.widget-picker-name {
    align-self: end;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: var(--font-weight-strong);
}

.widget-picker-desc {
    color: var(--text-muted);
    font-size: 0.775rem;
    line-height: 1.4;
    text-wrap: pretty;
}

.widget-form-section {
    margin: 1.25rem 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
    font-size: 0.7rem;
    font-weight: var(--font-weight-strong);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.widget-form-section:first-child {
    margin-top: 0;
}

/* A chart dataset's settings (widgets/bar_chart_dataset_widget.html). */
.dataset-fields {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 0.5rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--bg-raise);
}

/* Top-aligned with its control's first line, so a long help text below the
   control never pulls the label down with it. */
.dataset-fields-label {
    align-self: start;
    margin: 0;
    padding-top: 0.5rem;
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

.dataset-fields-help {
    margin-top: 0.2rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.dataset-fields [hidden] {
    display: none;
}

/* ----------------------------------------------------------------------------
   Org call volume (OrgCallVolumeChart, org_call_volume_chart.js)
   ---------------------------------------------------------------------------- */

.org-volume {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.org-volume-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
}

.org-volume-title {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
    font-size: 0.95rem;
}

.org-volume-subtitle {
    color: var(--text-tertiary);
    font-size: 0.8rem;
    margin-top: 0.15rem;
}

.org-volume-dot {
    margin: 0 0.3rem;
    color: var(--text-muted);
}

/* Both segmented controls keep one size whether or not the other is shown
   (the metric control hides in table view): every segment is a fixed
   height, and neither group stretches to its neighbor. */
.org-volume-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.org-volume-controls .nav-tabs {
    flex: none;
}

.org-volume-controls .nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.5rem;
}

/* Auto height: 2:1 with the card's width, between a floor and the
   viewport's reach, like the other chart plots. */
.org-volume-plot {
    position: relative;
    contain: layout;
    width: 100%;
    aspect-ratio: 2 / 1;
    min-height: 16rem;
    max-height: min(70vh, 40rem);
}

.org-volume-plot > canvas {
    position: absolute;
    inset: 0;
}

/* A fixed-height widget: the plot takes what the header and legend leave. */
.dash-card.has-fixed-height .org-volume-plot {
    flex: 1 1 auto;
    aspect-ratio: auto;
    height: auto;
    min-height: 14rem;
    max-height: none;
}

/* A fixed-height widget: the table fills what is left of the card and
   scrolls inside it, under its pinned header rows. */
.dash-card.has-fixed-height .org-volume-table {
    flex: 1 1 0;
    min-height: 14rem;
    overflow: auto;
}

/* The view toggle is icons only: fixed segments, the icon centered. */
.org-volume-view .nav-link {
    width: 2rem;
    padding-right: 0 !important; /* beats theme.css `.nav-sm .nav-link` padding !important */
    padding-left: 0 !important;
}

.org-volume-view .nav-link .fas {
    margin-right: 0;
}

/* --- Tooltip (box shared with .chart-tooltip above) ------------------------

   One grid for every row: key, value (right-aligned), label. Rows are
   subgrids, so the columns line up across the picked orgs, the pointer
   slot and the average. Two text styles only: values in primary ink and
   strong weight, labels and hints in tertiary ink. One width at every hour;
   renderTooltip moves it with a transform. */

.org-volume-tooltip {
    top: 0;
    left: 0;
    display: grid;
    grid-template-columns: 0.75rem minmax(3.5ch, max-content) minmax(0, 1fr);
    align-items: center;
    column-gap: 0.5rem;
    width: 17.5rem;
    min-width: 0;
    max-width: none;
    contain: layout style;
}

.org-volume-tooltip[hidden] {
    display: none;
}

.org-volume-tooltip-title {
    grid-column: 1 / -1;
    margin: 0 0 0.2rem;
    color: var(--text-secondary);
    font-weight: var(--font-weight-strong);
}

.org-volume-tooltip-row,
.org-volume-tooltip-section {
    position: relative;
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
}

.org-volume-tooltip-row {
    min-height: 1.375rem;
}

.org-volume-tooltip-section {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid var(--border-normal);
}

.org-volume-tooltip-value {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.org-volume-tooltip-label {
    overflow: hidden;
    color: var(--text-tertiary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The org under the pointer: a wash behind its row, its name in the value
   style, and the other rows step back. */
.org-volume-tooltip-row.is-active::before {
    content: "";
    position: absolute;
    inset: 0 -0.375rem;
    z-index: -1;
    border-radius: 4px;
    background: var(--surface-3);
}

.org-volume-tooltip-row.is-active .org-volume-tooltip-label {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.org-volume-tooltip.has-active > .org-volume-tooltip-row:not(.is-active) {
    opacity: 0.55;
}

/* A short stroke of the series color: the identity key in the tooltip, the
   chips and the table. Hollow until the org is picked. */
.org-volume-key {
    flex: none;
    width: 0.75rem;
    height: 3px;
    border-radius: 2px;
    background: var(--border-emphasis);
}

/* --- Legend chips --------------------------------------------------------- */

.org-volume-legend {
    border-top: 1px solid var(--border-subtle);
    padding-top: 0.85rem;
}

.org-volume-legend-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 0.65rem;
}

.org-volume-legend-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: var(--font-weight-strong);
}

.org-volume-legend-hint {
    color: var(--text-muted);
    font-weight: var(--font-weight-body);
    margin-left: 0.35rem;
}

.org-volume-legend-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
}

.org-volume-legend-actions .btn {
    min-height: 2rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
}

.org-volume-legend-sep {
    width: 1px;
    height: 1rem;
    margin: 0 0.4rem;
    background: var(--border-normal);
}

.org-volume-context-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    margin-left: 0.25rem;
}

.org-volume-context-toggle .custom-control-label {
    color: var(--text-tertiary);
    font-size: 0.8rem !important; /* beats forms.css `label { font-size: 14px !important }` */
    line-height: 1.5rem;
    cursor: pointer;
}

.org-volume-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.org-volume-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2rem;
    padding: 0.25rem 0.65rem;
    border: 1px solid var(--border-normal);
    border-radius: 999px;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.org-volume-chip:hover {
    background: var(--surface-2);
    color: var(--text-secondary);
}

.org-volume-chip:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.org-volume-chip.is-picked {
    background: var(--bg-raise);
    border-color: var(--border-emphasis);
    color: var(--text-primary);
}

.org-volume-chip[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
}

.org-volume-chip.is-hover {
    border-color: var(--text-tertiary);
    color: var(--text-primary);
}

.org-volume-chip[aria-disabled="true"]:hover {
    background: transparent;
    color: var(--text-tertiary);
}

.org-volume-chip-value {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.org-volume-chip.is-picked .org-volume-chip-value {
    color: var(--text-tertiary);
}

/* The metric toggle and the org chips only drive the chart. */
.org-volume.is-table-view .org-volume-metric,
.org-volume.is-table-view .org-volume-legend {
    display: none;
}

.org-volume-plot[hidden],
.org-volume-table[hidden] {
    display: none;
}

/* --- Table view: hours shaded by volume, then the per-day group ----------- */

/* Auto height: every row at full height and the card grows; only the hour
   columns scroll sideways, past the pinned org column. */
.org-volume-table {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
}

.org-volume-grid {
    margin: 0;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.org-volume-grid th,
.org-volume-grid td {
    padding: 0.4rem 0.6rem;
    border-color: var(--border-subtle);
    text-align: right;
    white-space: nowrap;
}

/* Two header rows stay pinned: the column groups, then the columns. */
.org-volume-grid thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 2rem;
    background: var(--bg-surface);
    color: var(--text-tertiary);
    font-weight: var(--font-weight-strong);
    vertical-align: middle;
}

.org-volume-grid thead tr + tr th {
    top: 2rem;
}

.org-volume-grid thead th {
    letter-spacing: normal;
    text-transform: none;
}

.org-volume-grid .org-volume-grid-group {
    color: var(--text-muted);
    font-weight: var(--font-weight-body);
    text-align: left;
}

/* The per-day group starts at a stronger rule than the hairlines between
   the hours. */
.org-volume-grid .org-volume-grid-day {
    border-left: 2px solid var(--border-emphasis);
}

.org-volume-sort {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s ease;
}

.org-volume-sort:hover,
.org-volume-sort.is-sorted {
    color: var(--text-primary);
}

.org-volume-sort:focus-visible {
    border-radius: 3px;
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

.org-volume-sort .fas {
    font-size: 0.65rem;
}

.org-volume-grid td {
    color: var(--text-secondary);
}

/* The strongest cells carry their number in full ink and weight. The shade
   stops short of solid, so primary text keeps its contrast in both themes. */
.org-volume-grid td.is-strong {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.org-volume-grid .org-volume-grid-org {
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    text-align: left;
    color: var(--text-primary);
    font-weight: var(--font-weight-body);
}

.org-volume-grid thead .org-volume-grid-org {
    z-index: 2;
    color: var(--text-tertiary);
    font-weight: var(--font-weight-strong);
}

.org-volume-grid tbody .org-volume-grid-org {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.org-volume-grid td.org-volume-grid-total {
    color: var(--text-primary);
    font-weight: var(--font-weight-strong);
}

.org-volume-empty a {
    color: var(--color-blue);
}
