/* ============================================================
   Team Dashboard Widget — Slate / supervisory color scheme
   (2026-06-22: replaced indigo with neutral slate per design spec.
   Palette anchored on Tailwind slate-* with a steel-blue accent;
   semantic structure unchanged — only the hue values moved.)
   Scoped to .td-* and .td-dashboard to prevent conflicts.
   Dark mode: body.dark-theme (matches CMS Lead Assistant pattern).
   ============================================================ */

:root {
    --td-primary:          #475569;   /* accent — slate-600 */
    --td-primary-light:    #eef1f5;   /* pill / soft fill */
    --td-primary-mid:      #e6eaef;   /* card border / mid-tone */
    --td-primary-dark:     #334155;   /* hover / pressed accent */
    --td-primary-icon-grad: linear-gradient(135deg, #475569 0%, #334155 100%);
    --td-success:          #16a34a;   /* positive */
    --td-warning:          #d97706;
    --td-danger:           #dc2626;
    --td-header-bg:         linear-gradient(135deg, #f8fafc 0%, #ecf3fd 100%);
    --td-body-bg:          #ffffff;   /* widget surface */
    --td-card-bg:          #ffffff;
    --td-border:           #e6eaef;   /* card border */
    --td-text-primary:     #1e293b;   /* primary text — slate-800 */
    --td-text-secondary:   #475569;   /* matches accent */
    --td-text-muted:       #94a3b8;   /* muted text — slate-400 */
    --td-coach-icon-gray:  linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
    --td-sparkle-color:    #d97706;
    --cards-box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
    --cards-box-shadow-hover: 0 8px 30px rgba(6, 6, 6, 0.15);
}

body.dark-theme {
    --td-primary:          #8ea2c6;   /* accent — steel-blue on dark */
    --td-primary-light:    #2c313b;   /* pill / soft fill */
    --td-primary-mid:      #30343d;   /* card border */
    --td-primary-dark:     #b8c5db;   /* hover (lighter on dark) */
    --td-primary-icon-grad: linear-gradient(135deg, #8ea2c6 0%, #b8c5db 100%);
    --td-success:          #4ade80;   /* positive */
    --td-warning:          #fbbf24;
    --td-danger:           #f87171;
    --td-header-bg:        #1d1f24;   /* widget surface */
    --td-body-bg:          #1d1f24;
    --td-card-bg:          #23262d;   /* card surface */
    --td-border:           #30343d;
    --td-text-primary:     #f1f5f9;   /* primary text */
    --td-text-secondary:   #8ea2c6;   /* matches accent */
    --td-text-muted:       #7b8492;   /* muted text */
    --td-coach-icon-gray:  linear-gradient(135deg, #4b5563 0%, #374151 100%);
    --td-sparkle-color:    #fbbf24;
    --cards-box-shadow: 0 1px 3px rgb(255 255 255 / 60%);
    --cards-box-shadow-hover: 0 8px 30px rgb(255 255 255 / 44%);
}

/* ============================================================
   Root container
   ============================================================ */

.td-dashboard {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    font-size: 14px;
    color: var(--td-text-primary);
    background: var(--td-body-bg);
    border-radius: 8px;
}

/* ============================================================
   Collapsed panel
   ============================================================ */

.td-collapsed-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 4px;
    height: 100%;
    background: var(--td-body-bg);
}

/* ============================================================
   Header overrides for team dashboard
   ============================================================ */

.td-dashboard .widget-header {
    background: var(--td-header-bg);
    border-bottom: 1px solid var(--td-border);
    flex-shrink: 0;
    padding: 10px 14px;
}

/* Stack title + selector vertically */
.td-dashboard .widget-header .widget-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.td-dashboard .widget-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--td-text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.td-dashboard .widget-header h3 i {
    color: var(--td-primary);
    font-size: 13px;
}

/* Team name subtitle (shown below "Team Dashboard" heading) */
.td-dashboard .widget-header .td-team-subtitle {
    font-size: 11px;
    color: var(--td-text-secondary);
    font-weight: 500;
    margin: 0;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Team selector */
.td-team-selector {
    width: 100%;
}

.td-select {
    font-size: 12px;
    padding: 3px 8px 3px 6px;
    border: 1px solid var(--td-border);
    border-radius: 6px;
    background: var(--td-card-bg);
    color: var(--td-text-primary);
    cursor: pointer;
    max-width: 220px;
    font-weight: 500;
}

.td-select:focus {
    outline: none;
    border-color: var(--td-primary);
    box-shadow: 0 0 0 2px var(--td-primary-light);
}

/* ============================================================
   Period tabs
   ============================================================ */

.td-period-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 14px;
    border-bottom: 1px solid var(--td-border);
    background: var(--td-header-bg);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.td-period-tabs::-webkit-scrollbar { display: none; }

.td-period-tab {
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--td-text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.td-period-tab:hover {
    color: var(--td-primary);
}

.td-period-tab.active {
    color: var(--td-primary);
    border-bottom-color: var(--td-primary);
    font-weight: 600;
}

/* ============================================================
   Context banner (individual agent view)
   ============================================================ */

.td-context-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background: var(--td-primary-light);
    border-bottom: 1px solid var(--td-border);
    font-size: 13px;
    flex-shrink: 0;
    color: var(--td-text-primary);
}

.td-context-banner i { color: var(--td-primary); font-size: 12px; }
.td-context-banner strong { font-weight: 600; }

.td-back-btn {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    color: var(--td-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.td-back-btn:hover { background: var(--td-primary-mid); }

/* ============================================================
   Dashboard body — always column layout
   ============================================================ */
.workflow-team_dashboard.state-half .td-dashboard-body {
    flex-direction: column;
}
.workflow-team_dashboard.state-full .td-dashboard-body {   
    flex-direction: row;
}

.td-dashboard-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Main scrollable content area */
.td-main-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* Coaching panel — bottom, full-width, fixed height */
.td-coach-panel {
    flex-shrink: 0;
    border-top: 1px solid var(--td-border);
    background: var(--td-card-bg);
    display: flex;
    flex-direction: column;
    /* max-height: 300px; */
    overflow: hidden;
}

.workflow-team_dashboard.state-full .td-coach-panel {
    height: auto !important;
}

/* Draggable divider between the main area and AI Coaching (stacked layout) */
.td-dashboard .widget-panel-resizer {
    flex: 0 0 10px;
    background: var(--td-primary-light);
    border-top: 1px solid var(--td-border);
    border-bottom: 1px solid var(--td-border);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
    touch-action: none;
    position: relative;
    z-index: 5;
}

.td-dashboard .widget-panel-resizer:hover { background: var(--td-primary-mid); }

.td-dashboard .widget-panel-resizer-grip {
    width: 44px;
    height: 4px;
    border-radius: 3px;
    background: var(--td-primary);
    opacity: 0.55;
    transition: opacity 0.15s;
}

.td-dashboard .widget-panel-resizer:hover .widget-panel-resizer-grip { opacity: 1; }

/* Side-by-side (full) layout: the horizontal resizer doesn't apply */
.workflow-team_dashboard.state-full .td-resizer { display: none !important; }

.td-coach-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px 6px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--td-border);
}

.td-coach-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--td-text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.td-coach-label i {
    color: var(--td-sparkle-color);
    font-size: 11px;
}

.td-coach-scope-hint {
    font-size: 10px;
    color: var(--td-text-muted);
    font-style: italic;
}

/* Topic cards grid — 2 columns, scrollable */
.td-topic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.workflow-team_dashboard.state-full .td-topic-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

/* ============================================================
   Topic cards (CMS-style horizontal layout)
   ============================================================ */

.td-topic-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--td-body-bg);
    border: 1px solid var(--td-border);
    border-radius: 8px;
    padding: 9px 10px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    min-width: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    box-shadow: var(--cards-box-shadow);
}

.td-topic-card:hover {
    background: var(--td-primary-light);
    border-color: var(--td-primary);
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(13, 148, 136, 0.12);
}

.td-topic-icon-wrap {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--td-primary-icon-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    color: #fff;
    box-shadow: 0 2px 5px rgba(13, 148, 136, 0.3);
}

.td-topic-content {
    flex: 1;
    min-width: 0;
}

.td-topic-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--td-text-primary);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-topic-desc {
    font-size: 10px;
    color: var(--td-text-muted);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-topic-action {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--td-sparkle-color);
    opacity: 0.7;
    transition: opacity 0.15s;
}

.td-topic-card:hover .td-topic-action { opacity: 1; }

/* Brief click feedback when a topic is sent */
.td-topic-card.td-topic-selected {
    border-color: var(--td-primary-dark, var(--td-primary));
    background: var(--td-primary-light);
}

/* Covered this session — dimmed, with the lightning bolt swapped for a check */
.td-topic-card.td-topic-used {
    opacity: 0.55;
}
.td-topic-card.td-topic-used .td-topic-action {
    color: var(--td-success-color, #16a34a);
    opacity: 1;
}
/* Keep the covered state legible on hover without fully re-brightening */
.td-topic-card.td-topic-used:hover {
    opacity: 0.8;
}

/* Disabled (out-of-scope) topics */
.td-topic-card.td-topic-disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.td-topic-card.td-topic-disabled .td-topic-icon-wrap {
    background: var(--td-coach-icon-gray);
    box-shadow: none;
}

/* ============================================================
   Section headings
   ============================================================ */

.td-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--td-text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    padding-left: 5px;
}

.td-section-label i { font-size: 10px; opacity: 0.7; }

/* ============================================================
   KPI grid — 2 columns
   ============================================================ */

.td-kpi-grid {
    display: grid;
    /* minmax(0, 1fr) so long content (e.g. team-name in the footer row)
     * doesn't force one column wider than the other — matches .td-topic-grid. */
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 2px;
    min-width: 0;
}

.td-kpi-cell { min-width: 0; }

.td-kpi-cell {
    background: var(--td-card-bg);
    border: 1px solid var(--td-border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--cards-box-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.td-kpi-cell:hover {
    transform: translateY(-2px);
    box-shadow: var(--cards-box-shadow-hover, 0 8px 30px rgba(6, 6, 6, 0.15));
}

.td-kpi-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--td-text-muted);
    padding-left: 5px;
}

.td-kpi-label i { margin-right: 3px; color: var(--td-primary); }

/* Source-Look deep-link icon next to a KPI card label */
.td-kpi-cell .td-kpi-looklink {
    color: var(--td-text-muted);
    opacity: 0.55;
    text-decoration: none;
    font-size: 9px;
    margin-left: 2px;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.td-kpi-cell .td-kpi-looklink i { margin-right: 0; color: inherit; }
.td-kpi-cell .td-kpi-looklink:hover { opacity: 1; color: var(--td-primary); }

.td-kpi-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--td-text-primary);
    line-height: 1;
    padding-left: 10px;
}

.td-kpi-value.td-placeholder { color: var(--td-text-muted); }

.td-kpi-grid--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* --- Locked card layout v2 (2026-06-22) ----------------------------------
 * Row 1 — label.
 * Row 2 — value (left) + optional inline-right tag for intrinsic sub-info.
 * Row 3 — optional footer row with bg color carrying comparison data.
 *         Comparison data NEVER sits next to the value; it always lives in
 *         the footer (or is absent entirely).
 */

.td-kpi-valuerow {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-height: 24px;
}

.td-kpi-valueright {
    font-size: 11px;
    font-weight: 600;
    color: var(--td-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.td-kpi-footer {
    padding: 5px 8px;
    background: var(--td-primary-light);
    border: 1px solid var(--td-primary-mid);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    min-width: 0;
    flex-wrap: nowrap;
}

.td-kpi-footer-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--td-text-muted);
    flex-shrink: 0;
}

.td-kpi-footer-value {
    font-weight: 700;
    color: var(--td-text-primary);
    flex-shrink: 0;
}

.td-kpi-footer-team {
    color: var(--td-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
}

.td-kpi-footer-win {
    color: var(--td-primary);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.td-kpi-footer-na {
    color: var(--td-text-muted);
    font-style: italic;
}

/* Profit-pill footer keeps the same bg row, just multiple inline pills. */
.td-kpi-footer .td-kpi-pill {
    border: none;
    background: transparent;
    padding: 0;
}

/* Agent drill-down inline back button (replaces the old context banner). */
.td-back-btn--inline {
    margin-left: auto;
    align-self: center;
}

/* Icon-only back button placed on the LEFT of the agent card
 * (2026-06-22 — matches left-to-right back-navigation convention). */
.td-back-btn--icon {
    margin-left: 0;
    margin-right: 4px;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--td-primary);
    background: var(--td-primary-light);
    border: 1px solid var(--td-primary-mid);
    flex-shrink: 0;
}

.td-back-btn--icon:hover {
    background: var(--td-primary-mid);
    color: var(--td-primary-dark);
}

/* Agent card with back-btn: button | avatar | info — flex left-to-right.
 * Uses gap (not margin) so spacing scales with the existing card style. */
.td-agent-card--with-back {
    display: flex;
    align-items: center;
    gap: 10px;
}


.td-kpi-of {
    font-size: 12px;
    font-weight: 500;
    color: var(--td-text-muted);
}

.td-kpi-sub {
    font-size: 11px;
    color: var(--td-text-secondary, var(--td-text-primary));
    margin-top: 2px;
    line-height: 1.3;
}

.td-kpi-sub-muted {
    font-size: 11px;
    color: var(--td-text-muted);
    margin-top: 2px;
    line-height: 1.3;
}

.td-kpi-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.td-kpi-pill {
    font-size: 10px;
    background: var(--td-primary-light);
    color: var(--td-text-primary);
    border: 1px solid var(--td-primary-mid);
    border-radius: 6px;
    padding: 2px 6px;
    font-weight: 600;
    white-space: nowrap;
}

.td-kpi-pill-k {
    color: var(--td-text-muted);
    margin-right: 3px;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 9px;
}

.td-delta-up   { color: var(--td-success); font-weight: 600; }
.td-delta-down { color: var(--td-danger);  font-weight: 600; }

/* Per-agent ranked row — 3-column metric strip (Tier · AGP · Conv) */
.td-agent-metrics {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--td-text-primary);
    margin-top: 2px;
    flex-wrap: wrap;
}

.td-agent-metric-sep { color: var(--td-text-muted); opacity: 0.5; }
.td-agent-tier-na    { color: var(--td-text-muted); }

.td-agent-tier {
    font-weight: 700;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    min-width: 30px;
    display: inline-block;
    text-align: center;
}

/* Per-tier color scale — visual severity at a glance.
 * T1 = best (green) → T5 = worst (red). Used on both per-agent rows AND the
 * drill-down AGP Tier card (.td-tier shares the scale). */
.td-tier-t1, .td-tier.td-tier-t1 {
    background: rgba(34,197,94,0.12);  color: #16a34a; border: 1px solid rgba(34,197,94,0.4);
}
.td-tier-t2, .td-tier.td-tier-t2 {
    background: rgba(20,184,166,0.12); color: #0d9488; border: 1px solid rgba(20,184,166,0.4);
}
.td-tier-t3, .td-tier.td-tier-t3 {
    background: rgba(245,158,11,0.14); color: #d97706; border: 1px solid rgba(245,158,11,0.4);
}
.td-tier-t4, .td-tier.td-tier-t4 {
    background: rgba(249,115,22,0.14); color: #ea580c; border: 1px solid rgba(249,115,22,0.5);
}
.td-tier-t5, .td-tier.td-tier-t5 {
    background: rgba(220,38,38,0.12);  color: var(--td-danger); border: 1px solid rgba(220,38,38,0.5);
    font-weight: 800;
}

.td-agent-agp  { font-weight: 600; }
.td-agent-conv { font-weight: 600; color: var(--td-text-muted); }

/* Flat agent row (v3 — 2026-06-22): identity LEFT, metrics RIGHT, tier LAST.
 * Layout: rank | avatar | name(1fr) | AGP | conv | TIER | chevron.
 * The `1fr` on name pushes the right-side metrics flush to the right while
 * keeping the avatar+name pair anchored on the left. */
.td-dashboard .td-agent-row--flat {
    display: grid;
    grid-template-columns: 24px 32px minmax(0, 1fr) 80px 56px 38px 12px;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--td-border);
    transition: background 0.15s ease;
}

.td-dashboard .td-agent-row--flat:hover { 
    background: var(--td-primary-light); 
    transform: translateY(-1x);
}

.td-dashboard .td-agent-row--flat:last-child { border-bottom: none; }

.td-dashboard .td-agent-name--flat {
    font-weight: 600;
    color: var(--td-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.td-dashboard .td-agent-row--flat .td-agent-agp,
.td-dashboard .td-agent-row--flat .td-agent-conv {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}

/* Tier column — keep the colour-coded badge compact and centered in its slot. */
.td-dashboard .td-agent-row--flat .td-agent-tier {
    justify-self: center;
}

/* Drill-down tier card */
.td-dashboard .td-tier {
    font-size: 22px;
    font-weight: 800;
}

.td-dashboard .td-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
    margin-top: 4px;
}

.td-badge-frozen { background: rgba(59,130,246,0.12); color: #2563eb; border: 1px solid rgba(59,130,246,0.35); }
.td-badge-immune { background: rgba(34,197,94,0.12);  color: #16a34a; border: 1px solid rgba(34,197,94,0.35); }

.td-muted-note {
    font-size: 11px;
    color: var(--td-text-muted);
    font-style: italic;
    margin: 4px 0 0;
    text-align: center;
}

/* ============================================================
   Agents card
   ============================================================ */

.td-agents-card {
    background: var(--td-card-bg);
    border: 1px solid var(--td-border);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--cards-box-shadow);
}

.td-agents-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px 7px;
    border-bottom: 1px solid var(--td-border);
}

.td-agents-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--td-text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.td-agents-title .td-agents-info-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
    outline: none;
}

.td-agents-title .td-agents-info {
    font-size: 0.72rem;
    color: var(--td-text-muted);
    opacity: 0.65;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.td-agents-title .td-agents-info-wrap:hover .td-agents-info,
.td-agents-title .td-agents-info-wrap:focus .td-agents-info {
    opacity: 1;
    color: var(--td-primary);
}

/* Custom tooltip — appears instantly (no native title= delay) */
.td-agents-title .td-agents-tooltip {
    position: absolute;
    top: calc(100% + 7px);
    left: 0;
    z-index: 50;
    width: 280px;
    max-width: 78vw;
    padding: 9px 11px;
    background: #1f2937;
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.45;
    letter-spacing: 0;
    text-transform: none;
    text-align: left;
    border-radius: 8px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.08s ease;
}

.td-agents-title .td-agents-info-wrap:hover .td-agents-tooltip,
.td-agents-title .td-agents-info-wrap:focus .td-agents-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Little arrow pointing up to the icon */
.td-agents-title .td-agents-tooltip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 10px;
    border: 5px solid transparent;
    border-bottom-color: #1f2937;
}

.td-agents-badge {
    background: var(--td-primary-light);
    color: var(--td-primary);
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 7px;
    border: 1px solid var(--td-primary-mid);
}

.td-agents-list { display: flex; flex-direction: column; }

.td-agent-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid var(--td-border);
}

.td-agent-row:last-child { border-bottom: none; }
.td-agent-row:hover { background: var(--td-primary-light); }

.td-agent-rank {
    font-size: 11px;
    font-weight: 700;
    color: var(--td-text-muted);
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.td-agent-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--td-primary-mid);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    color: var(--td-primary-dark);
    font-weight: 700;
    border: 1px solid var(--td-border);
}

.td-agent-info { flex: 1; min-width: 0; }

.td-agent-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--td-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-agent-meta { font-size: 11px; color: var(--td-text-muted); }

.td-dashboard .td-agent-cms-rev  { color: var(--td-success); font-weight: 600; }
.td-dashboard .td-agent-cms-sep  { color: var(--td-text-muted); margin: 0 4px; }
.td-dashboard .td-agent-cms-conv { color: var(--td-primary); font-weight: 500; }
.td-dashboard .td-agent-cms-nodata { color: var(--td-text-muted); font-style: italic; }

.td-agent-chevron {
    color: var(--td-text-muted);
    font-size: 10px;
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity 0.12s, transform 0.12s;
}

.td-agent-row:hover .td-agent-chevron {
    opacity: 1;
    transform: translateX(2px);
    color: var(--td-primary);
}

/* ============================================================
   Agent individual view card
   ============================================================ */

.td-agent-card {
    background: var(--td-card-bg);
    border: 1px solid var(--td-border);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.td-agent-card-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--td-primary-icon-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.td-agent-card-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--td-text-primary);
}

.td-agent-card-sub {
    font-size: 12px;
    color: var(--td-text-muted);
    margin-top: 2px;
}

/* ============================================================
   Loading / error / no-team states
   ============================================================ */

.td-loading-view,
.td-no-team-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex: 1;
    height: 100%;
    padding: 32px 24px;
    text-align: center;
    background: var(--td-body-bg);
}

.td-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--td-border);
    border-top-color: var(--td-primary);
    border-radius: 50%;
    animation: td-spin 0.8s linear infinite;
}

.td-spinner-sm { width: 20px; height: 20px; margin: 10px auto; }

@keyframes td-spin { to { transform: rotate(360deg); } }

.td-loading-text { font-size: 13px; color: var(--td-text-muted); margin: 0; }

.td-no-team-icon { font-size: 34px; color: var(--td-text-muted); }

.td-no-team-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    color: var(--td-text-primary);
}

.td-no-team-msg {
    font-size: 13px;
    color: var(--td-text-muted);
    max-width: 260px;
    line-height: 1.5;
    margin: 0;
}

.td-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: var(--td-primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.td-retry-btn:hover { background: var(--td-primary-dark); }

.td-empty-state {
    padding: 16px 14px;
    text-align: center;
    color: var(--td-text-muted);
    font-size: 12px;
}

/* ============================================================
   Period tabs row — tabs + CMS toggle on the same line
   ============================================================ */

.td-period-tabs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--td-border);
    background: var(--td-header-bg);
    flex-shrink: 0;
}

.td-period-tabs-row .td-period-tabs {
    border-bottom: none;
    background: transparent;
    flex: 1;
}

/* ============================================================
   CMS ON/OFF Toggle Switch (teal colour scheme)
   ============================================================ */

.td-cms-switch {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 0 12px 0 8px;
    flex-shrink: 0;
    user-select: none;
}

.td-cms-switch-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.td-cms-switch-track {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
    border-radius: 8px;
    background: var(--td-border);
    transition: background 0.2s;
    flex-shrink: 0;
}

.td-cms-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    transition: left 0.2s;
}

.td-cms-switch-input:checked ~ .td-cms-switch-track {
    background: var(--td-primary);
}

.td-cms-switch-input:checked ~ .td-cms-switch-track .td-cms-switch-thumb {
    left: 14px;
}

.td-cms-switch-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--td-text-muted);
    transition: color 0.2s;
}

.td-cms-switch.td-cms-switch-on .td-cms-switch-label {
    color: var(--td-primary);
}

.td-cms-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 700;
    background: var(--td-primary);
    color: #fff;
    margin-left: 6px;
    vertical-align: middle;
}

/* ============================================================
   CMS KPI stack (same card system as AP widget, teal variant)
   ============================================================ */

.td-cms-kpi-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.td-kpi-cell--icon {
    border-left: 3px solid var(--td-border);
}

/* Spans both grid columns */
.td-kpi-cell--full {
    grid-column: 1 / -1;
}

.td-kpi-cell--wide {
    border-radius: 8px;
    background: var(--td-card-bg);
    border: 1px solid var(--td-border);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.td-kpi-cell--accent {
    border-left: 3px solid var(--td-primary);
    background: var(--td-primary-light) !important;
}

.td-kpi-cell--revenue {
    border-left: 3px solid var(--td-primary-dark);
    background: var(--td-primary-light) !important;
}

body.dark-theme .td-kpi-cell--accent,
body.dark-theme .td-kpi-cell--revenue {
    background: var(--td-primary-light) !important;
}

.td-kpi-sub {
    font-size: 10px;
    color: var(--td-text-muted);
    margin-top: 1px;
}

.td-kpi-value--large {
    font-size: 22px;
}

.td-cms-bus-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 600;
    background: var(--td-primary-mid);
    color: var(--td-text-secondary);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
    vertical-align: middle;
}

.td-cms-state {
    display: flex;
    justify-content: center;
    padding: 16px 0;
}

.td-cms-error {
    font-size: 11px;
    color: #ef4444;
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
