/* ============================================================
   Agent Performance Widget — Amber/orange color scheme
   Scoped to .ap-* and .ap-dashboard to prevent conflicts.
   Dark mode: body.dark-theme
   ============================================================ */

:root {
    --ap-primary:        #d97706;
    --ap-primary-light:  #fffbeb;
    --ap-primary-mid:    #daedf3;
    --ap-primary-dark:   #b45309;
    --ap-primary-grad:   linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
    --ap-success:        #16a34a;
    --ap-sparkle:        #d97706;
    --ap-header-bg:      linear-gradient(135deg, #ebfcff 0%, #fee0c7 100%);
    --ap-body-bg:        #fafaf5;
    --ap-card-bg:        #ffffff;
    --ap-border:         #fde68a;
    --ap-border-light:   #fef3c7;
    --ap-text-primary:   #1c1101;
    --ap-text-secondary: #78350f;
    --ap-text-muted:     #a16207;
    --ap-icon-gray:      linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
}

body.dark-theme {
    --ap-primary:        #fbbf24;
    --ap-primary-light:  #1c1101;
    --ap-primary-mid:    #292100;
    --ap-primary-dark:   #fcd34d;
    --ap-primary-grad:   linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
    --ap-success:        #4ade80;
    --ap-sparkle:        #fbbf24;
    --ap-header-bg:      #1c1500;
    --ap-body-bg:        #191200;
    --ap-card-bg:        #211900;
    --ap-border:         #3d2d00;
    --ap-border-light:   #2a1e00;
    --ap-text-primary:   #fef9ec;
    --ap-text-secondary: #fcd34d;
    --ap-text-muted:     #a16207;
    --ap-icon-gray:      linear-gradient(135deg, #4b5563 0%, #374151 100%);
}

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

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

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

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

.ap-collapsed-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--ap-text-muted);
    cursor: pointer;
    padding: 8px 4px;
    border-radius: 8px;
    transition: color 0.15s;
}

.ap-collapsed-btn:hover { color: var(--ap-primary); }

.ap-collapsed-btn span {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    transform: rotate(180deg);
}

/* ============================================================
   Header — tint the shared widget-header with amber colours
   ============================================================ */

.ap-dashboard .widget-header,
.ap-widget-header {
    background: var(--ap-header-bg);
    border-bottom: 1px solid var(--ap-border);
    flex-shrink: 0;
}

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

.ap-title-icon {
    color: var(--ap-primary);
    font-size: 14px;
}

.ap-header-subtitle {
    font-size: 11px;
    color: var(--ap-text-muted);
    margin-top: 1px;
}

/* ============================================================
   Period tabs row (below header, like Team Dashboard)
   ============================================================ */

.ap-period-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--ap-border-light);
    flex-shrink: 0;
    overflow-x: auto;
}

.ap-period-tab {
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ap-text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ap-period-tab:hover {
    color: var(--ap-primary);
    background: var(--ap-primary-mid);
}

.ap-period-tab.active {
    background: var(--ap-primary);
    color: #fff;
    font-weight: 600;
}

/* ============================================================
   Body layout — single column (half / default)
   Two-column when the container has state-full
   ============================================================ */

.ap-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Full-view: side-by-side */
.state-full .ap-body {
    flex-direction: row;
}

/* Left column: My Stats + Leaderboard stacked */
.ap-main-col {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Divider only in row layout */
.state-full .ap-main-col {
    border-right: 1px solid var(--ap-border-light);
    border-bottom: none;
}

/* Half-view: add border below main col */
.state-half .ap-main-col {
    border-right: none;
    border-bottom: 1px solid var(--ap-border-light);
}

/* Right / bottom column: Coach panel */
.ap-coach-col {
    flex-shrink: 0;
    overflow-y: auto;
    padding: 10px;
    background: var(--ap-body-bg);
}

/* Fixed width only in full (row) layout */
.state-full .ap-coach-col {
    width: 220px;
}

/* ============================================================
   Section wrapper
   ============================================================ */

.ap-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ap-section-heading {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--ap-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--ap-border-light);
}

.ap-section-heading i { color: var(--ap-primary); font-size: 11px; }

.ap-placeholder-note {
    font-size: 10px;
    color: var(--ap-text-muted);
    text-align: center;
    margin: 2px 0 0;
    line-height: 1.4;
    font-style: italic;
}

/* ============================================================
   State views (loading / error / empty)
   ============================================================ */

.ap-state-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--ap-text-muted);
    text-align: center;
    flex: 1;
}

.ap-state-icon { font-size: 26px; color: var(--ap-primary); }

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

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

.ap-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.ap-btn-primary { background: var(--ap-primary); color: #fff; }
.ap-btn-primary:hover { background: var(--ap-primary-dark); }

/* ============================================================
   KPI grid
   ============================================================ */

.ap-kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.ap-kpi-card {
    background: var(--ap-card-bg);
    border: 1px solid var(--ap-border-light);
    border-radius: 8px;
    padding: 8px 10px;
}

.ap-kpi-wide { grid-column: 1 / -1; }

.ap-kpi-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ap-text-muted);
    margin-bottom: 3px;
}

.ap-kpi-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--ap-text-primary);
    line-height: 1.1;
}

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

/* ============================================================
   Leaderboard
   ============================================================ */

.ap-rank-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ap-primary-mid);
    border: 1px solid var(--ap-border);
    border-radius: 10px;
    padding: 9px 12px;
}

body.dark-theme .ap-rank-card { background: var(--ap-primary-light); }

.ap-rank-badge {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--ap-primary-grad);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ap-rank-position { font-size: 12px; font-weight: 700; color: var(--ap-text-primary); }
.ap-rank-detail   { font-size: 10px; color: var(--ap-text-muted); margin-top: 1px; }

.ap-lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.ap-lb-table thead th {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ap-text-muted);
    padding: 4px 4px 5px;
    text-align: left;
    border-bottom: 1px solid var(--ap-border-light);
}

.ap-lb-table thead th:not(:first-child) { text-align: right; }

.ap-lb-row td {
    padding: 5px 4px;
    border-bottom: 1px solid var(--ap-border-light);
    color: var(--ap-text-primary);
}

.ap-lb-row:last-child td { border-bottom: none; }
.ap-lb-row.is-you { background: var(--ap-primary-mid); font-weight: 600; }
body.dark-theme .ap-lb-row.is-you { background: var(--ap-primary-light); }

.ap-lb-rank { font-weight: 600; color: var(--ap-text-muted); width: 20px; }
.ap-lb-stat, .ap-lb-rev { text-align: right; color: var(--ap-text-secondary); }
.ap-lb-rev { font-weight: 600; }

/* GAP TO #1 */

.ap-gap-card {
    background: var(--ap-primary-mid);
    border: 1px solid var(--ap-border);
    border-radius: 8px;
    padding: 9px 12px;
}

body.dark-theme .ap-gap-card { background: var(--ap-primary-light); }

.ap-gap-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ap-text-muted);
    margin-bottom: 7px;
}

.ap-gap-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.ap-gap-label { font-size: 9px; color: var(--ap-text-muted); margin-bottom: 2px; }
.ap-gap-value { font-size: 14px; font-weight: 700; color: var(--ap-primary); }
.ap-gap-highlight { color: var(--ap-primary-dark); }
body.dark-theme .ap-gap-highlight { color: var(--ap-primary); }

/* ============================================================
   Coach column
   ============================================================ */

.ap-coach-heading-row {
    flex-wrap: wrap;
    gap: 4px 6px;
    color: var(--ap-text-muted);
}

.ap-coach-star { color: var(--ap-primary) !important; }

.ap-coach-subtitle-inline {
    font-size: 9px;
    font-weight: 400;
    color: var(--ap-text-muted);
    text-transform: none;
    letter-spacing: 0;
    flex-basis: 100%;
    padding-top: 1px;
    font-style: italic;
}

.ap-coach-empty { padding: 20px 8px; }

.ap-topics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.ap-topic-card {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 8px;
    border: 1px solid var(--ap-border-light);
    border-radius: 10px;
    background: var(--ap-card-bg);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    width: 100%;
}

.ap-topic-card:hover {
    border-color: var(--ap-primary);
    box-shadow: 0 2px 6px rgba(217, 119, 6, 0.15);
    transform: translateY(-1px);
}

.ap-topic-card.ap-topic-selected {
    border-color: var(--ap-primary-dark);
    background: var(--ap-primary-mid);
}

.ap-topic-icon-wrap {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--ap-primary-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    flex-shrink: 0;
}

.ap-topic-icon-wrap.ap-icon-gray { background: var(--ap-icon-gray); }

.ap-topic-body { flex: 1; min-width: 0; }

.ap-topic-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--ap-text-primary);
    line-height: 1.3;
}

.ap-topic-desc {
    font-size: 9px;
    color: var(--ap-text-secondary);
    margin-top: 2px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ap-topic-sparkle {
    color: var(--ap-sparkle);
    font-size: 9px;
    margin-left: 2px;
}

/* =========================================================================
   Period tabs row wrapper (tabs + CMS toggle on same line)
   ========================================================================= */

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

/* Remove bottom border from .ap-period-tabs when nested inside the row */
.ap-period-tabs-row .ap-period-tabs {
    border-bottom: none;
    flex: 1;
}

/* =========================================================================
   CMS ON/OFF Toggle Switch
   ========================================================================= */

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

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

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

.ap-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;
}

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

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

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

/* Label color when active — driven by JS adding .ap-cms-switch-on to the label */
.ap-cms-switch.ap-cms-switch-on .ap-cms-switch-label {
    color: var(--ap-primary);
}

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

/* Setup prompt */
.ap-cms-setup {
    padding: 10px 0 6px;
}

.ap-cms-setup-label {
    font-size: 11px;
    color: var(--ap-text-secondary);
    margin-bottom: 8px;
}

.ap-cms-setup-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ap-cms-agent-input {
    flex: 1;
    max-width: 110px;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--ap-border);
    background: var(--ap-bg-card);
    color: var(--ap-text-primary);
    font-size: 12px;
}

.ap-cms-agent-input:focus {
    outline: none;
    border-color: var(--ap-primary);
}

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

/* Change row */
.ap-cms-change-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.ap-cms-agent-label {
    font-size: 10px;
    color: var(--ap-text-secondary);
}

.ap-btn-ghost {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    border: 1px solid var(--ap-border);
    background: transparent;
    color: var(--ap-text-secondary);
    cursor: pointer;
}

.ap-btn-ghost:hover {
    border-color: var(--ap-primary);
    color: var(--ap-primary);
}

.ap-cms-note {
    font-size: 10px;
    color: var(--ap-text-secondary);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =========================================================================
   CMS KPI stack — vertically stacked rows (no empty grid gaps)
   ========================================================================= */

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

/* Accent left-border on cards with icon labels */
.ap-kpi-card--icon {
    border-left: 3px solid var(--ap-border);
}

/* Highlighted conversion card */
.ap-kpi-card--accent {
    border-left: 3px solid var(--ap-primary);
    background: var(--ap-primary-light);
}

/* Revenue card — slightly warmer */
.ap-kpi-card--revenue {
    border-left: 3px solid var(--ap-primary-dark);
    background: var(--ap-primary-light);
}

body.dark-theme .ap-kpi-card--accent,
body.dark-theme .ap-kpi-card--revenue {
    background: var(--ap-primary-light);
}

/* Larger value for wide/prominent cards */
.ap-kpi-value--large {
    font-size: 22px;
}

/* Business class inline badge next to Revenue label */
.ap-cms-bus-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 600;
    background: var(--ap-border);
    color: var(--ap-text-secondary);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
    vertical-align: middle;
}
