/* ============================================
   COORDY UI PRIMITIVES (GEN-UI-SHARED-01)
   Default styling for the canonical js/components/coordy-ui-primitives.js
   components when rendered with their default `cui-*` class family.
   Surfaces that pass a legacy classPrefix (Broker Office / Admin Operations)
   keep their existing themed styles and are unaffected by this file.
   Built only on the shared design tokens (base.css), so every theme applies.
   ============================================ */

/* ── Panel states ─────────────────────────── */
.cui-panel-state {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border: 1px dashed var(--border-soft, rgba(255, 255, 255, 0.12));
    border-radius: var(--radius-md, 10px);
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
    font-size: 13px;
}

.cui-panel-state-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    opacity: 0.7;
}

.cui-panel-state.loading .cui-panel-state-icon {
    opacity: 0.9;
    color: var(--accent-primary, #8b5cf6);
}

.cui-panel-state.loading .cui-panel-state-icon svg {
    /* GEN-OPS-01B: the loading glyph is a partial ring -- it must spin to
       read as "in progress" rather than a broken icon. Same timing as the
       rest of Coordy's spinners (coordinator.css / login.css). */
    animation: cui-panel-state-spin 0.7s linear infinite;
    transform-origin: center;
}

@keyframes cui-panel-state-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.cui-panel-state.error {
    border-color: var(--danger-border, rgba(239, 68, 68, 0.4));
}

.cui-panel-state.error .cui-panel-state-icon {
    opacity: 1;
    color: var(--danger-solid, #ef4444);
}

.cui-panel-state-message {
    flex: 1 1 180px;
    min-width: 0;
}

.cui-panel-state-action {
    margin-left: auto;
}

/* ── KPI / stat card ──────────────────────── */
.cui-kpi-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-lg, 14px);
    background: var(--card-bg, rgba(255, 255, 255, 0.03));
    color: inherit;
    text-align: left;
    font: inherit;
}

button.cui-kpi-card {
    cursor: pointer;
}

button.cui-kpi-card:focus-visible {
    outline: 2px solid var(--focus-ring, var(--accent-primary, #8b5cf6));
    outline-offset: 2px;
}

.cui-kpi-top {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.cui-kpi-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--accent-primary, #8b5cf6);
}

.cui-kpi-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

.cui-kpi-card strong {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.cui-kpi-card small,
.cui-kpi-secondary {
    font-size: 12px;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

.cui-kpi-card.is-empty strong,
.cui-kpi-card.is-no-data strong,
.cui-kpi-card.is-loading strong {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

.cui-kpi-status {
    align-self: flex-start;
    padding: 2px 8px;
    border-radius: var(--radius-full, 999px);
    font-size: 11px;
    font-weight: 600;
    background: var(--neutral-bg, rgba(255, 255, 255, 0.06));
    color: var(--neutral-text, inherit);
}

.cui-kpi-status.good { background: var(--success-bg, rgba(34, 197, 94, 0.14)); color: var(--success-text, #4ade80); }
.cui-kpi-status.bad { background: var(--danger-bg, rgba(239, 68, 68, 0.14)); color: var(--danger-text, #f87171); }

.cui-kpi-spark {
    width: 104px;
    height: 30px;
    fill: none;
    stroke: var(--accent-primary, #8b5cf6);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cui-kpi-empty-line {
    display: block;
    width: 104px;
    height: 1px;
    margin-top: 14px;
    background: var(--border-soft, rgba(255, 255, 255, 0.12));
}

.cui-kpi-ring {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    background:
        radial-gradient(closest-side, var(--card-bg, #1f2127) 78%, transparent 80% 100%),
        conic-gradient(var(--accent-primary, #8b5cf6) var(--cui-kpi-progress, 0%), var(--border-soft, rgba(255, 255, 255, 0.12)) 0);
}

/* ── Trend indicator ──────────────────────── */
.cui-trend,
.cui-kpi-trend {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

.cui-trend.good,
.cui-kpi-trend.good { color: var(--success-text, #4ade80); }
.cui-trend.bad,
.cui-kpi-trend.bad { color: var(--danger-text, #f87171); }

/* ── Drawer shell ─────────────────────────── */
.cui-drawer {
    display: flex;
    flex-direction: column;
    max-height: 100%;
    background: var(--modal-bg, #1f2127);
    border: 1px solid var(--modal-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-xl, 16px);
    box-shadow: var(--shadow-overlay, 0 24px 60px rgba(0, 0, 0, 0.45));
    overflow: hidden;
}

.cui-drawer.hidden {
    display: none;
}

.cui-drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

.cui-drawer-kicker {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-primary, #8b5cf6);
}

.cui-drawer-title {
    margin: 2px 0 0;
    font-size: 17px;
}

.cui-drawer-subtitle {
    margin: 4px 0 0;
    font-size: 12.5px;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

.cui-drawer-close {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: var(--radius-md, 10px);
    border: 1px solid var(--btn-ghost-border, rgba(255, 255, 255, 0.12));
    background: var(--btn-ghost-bg, transparent);
    color: var(--btn-ghost-text, inherit);
    font: inherit;
    cursor: pointer;
}

.cui-drawer-close:focus-visible,
.cui-drawer-tab:focus-visible {
    outline: 2px solid var(--focus-ring, var(--accent-primary, #8b5cf6));
    outline-offset: 2px;
}

.cui-drawer-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 18px 0;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

.cui-drawer-tab {
    padding: 8px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
    font: inherit;
    cursor: pointer;
}

.cui-drawer-tab.active {
    color: inherit;
    border-bottom-color: var(--accent-primary, #8b5cf6);
}

.cui-drawer-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 16px 18px;
}

.cui-drawer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

/* ── Chart no-data state (CoordyCharts.setCanvasEmptyState default) ── */
.cc-empty {
    display: grid;
    place-items: center;
    min-height: 120px;
    font-size: 13px;
    color: var(--text-muted, rgba(255, 255, 255, 0.62));
}

@media (prefers-reduced-motion: reduce) {
    .cui-kpi-card,
    .cui-drawer,
    .cui-panel-state.loading .cui-panel-state-icon svg {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Plan upgrade state (RE-SALE-READY-01D.4) ──────────────────────────
   Shown instead of a blank widget or a disabled raw control when the tenant's plan does
   not include a feature. Rendered by js/core/plan-capabilities.js (CoordyPlan.upgradeCardHtml). */
.coordy-plan-upgrade {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    max-width: 640px;
    margin: 8px 0;
    padding: 22px 24px;
    border: 1px solid var(--border-soft, rgba(143, 164, 255, 0.28));
    border-radius: var(--radius-md, 12px);
    background: linear-gradient(135deg, rgba(124, 140, 255, 0.14), rgba(38, 42, 53, 0.94));
    color: var(--text-primary, #f3f6fb);
}

.coordy-plan-upgrade.is-compact {
    padding: 14px 16px;
    gap: 6px;
}

.coordy-plan-upgrade-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(124, 140, 255, 0.22);
    color: #c9d3ff;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.coordy-plan-upgrade h3 {
    margin: 0;
    font-size: 1.15rem;
    color: #ffffff;
}

.coordy-plan-upgrade p {
    margin: 0;
    color: var(--text-muted, rgba(244, 247, 255, 0.72));
    font-size: 0.92rem;
    line-height: 1.5;
}

.coordy-plan-upgrade-cta {
    min-height: 38px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: rgba(102, 126, 234, 0.92);
    color: #ffffff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.coordy-plan-upgrade-cta:hover,
.coordy-plan-upgrade-cta:focus-visible {
    background: rgba(125, 150, 255, 1);
    outline: none;
}

.coordy-plan-upgrade-note {
    color: var(--text-muted, rgba(244, 247, 255, 0.62));
    font-size: 0.85rem;
}

@media (max-width: 640px) {
    .coordy-plan-upgrade {
        padding: 16px;
    }
}

/* ── Broker Office canonical financial summary (RE-SALE-READY-01D.4) ───── */
.bfs-card {
    padding: 18px 20px;
    margin-bottom: 14px;
    border: 1px solid var(--border-soft, rgba(128, 146, 184, 0.23));
    border-radius: var(--radius-md, 10px);
    background: rgba(38, 42, 53, 0.94);
    color: var(--text-primary, #f3f6fb);
}

.bfs-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.bfs-head h3 { margin: 2px 0 0; font-size: 1.05rem; color: #ffffff; }
.bfs-eyebrow { margin: 0; color: rgba(244, 247, 255, 0.55); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }
.bfs-muted { margin: 0; color: rgba(244, 247, 255, 0.66); font-size: 0.86rem; }

.bfs-link {
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(143, 164, 255, 0.45);
    border-radius: 7px;
    background: transparent;
    color: #c9d3ff;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}

.bfs-link:hover, .bfs-link:focus-visible { background: rgba(124, 140, 255, 0.18); outline: none; }

.bfs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
}

.bfs-tile {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 12px 14px;
    border: 1px solid rgba(132, 150, 188, 0.18);
    border-left-width: 3px;
    border-radius: 8px;
    background: rgba(18, 21, 29, 0.58);
}

.bfs-tile[data-kind="actual"] { border-left-color: #2db883; }
.bfs-tile[data-kind="pipeline"] { border-left-color: #d69a38; }
.bfs-tile[data-kind="planning"] { border-left-color: #b082ff; }
.bfs-tile[data-kind="projected"] { border-left-color: #46a6ff; }

.bfs-label { color: rgba(244, 247, 255, 0.62); font-size: 0.74rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; }
.bfs-tile strong { color: #ffffff; font-size: 1.3rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bfs-tile strong.is-unavailable { color: rgba(244, 247, 255, 0.5); font-size: 1rem; font-weight: 700; }
.bfs-tile small { color: rgba(244, 247, 255, 0.55); font-size: 0.74rem; line-height: 1.35; }

.bfs-chip {
    align-self: flex-start;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(214, 154, 56, 0.16);
    color: #ffd596;
    font-size: 0.66rem;
    font-weight: 800;
    text-transform: uppercase;
}

.bfs-chip-ok { background: rgba(45, 184, 131, 0.16); color: #8fe3bd; }

@media (max-width: 640px) {
    .bfs-card { padding: 14px; }
    .bfs-head { flex-direction: column; }
    .bfs-grid { grid-template-columns: 1fr 1fr; }
}


/* ── Automations plan state (PLAN-ENTITLEMENTS-01D) ─────────────────────── */
.wfw-plan-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin: 0 0 14px;
    padding: 12px 16px;
    border: 1px solid var(--border-soft, rgba(143, 164, 255, 0.28));
    border-radius: var(--radius-md, 10px);
    background: rgba(38, 42, 53, 0.94);
    color: var(--text-primary, #f3f6fb);
}
.wfw-plan-banner-main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; flex: 1 1 320px; }
.wfw-plan-banner-label { color: rgba(244, 247, 255, 0.6); font-size: 0.74rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.wfw-plan-banner-usage { font-size: 0.95rem; color: #ffffff; }
.wfw-plan-meter { position: relative; flex: 0 0 140px; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.wfw-plan-meter-fill { display: block; height: 100%; border-radius: inherit; background: rgba(125, 150, 255, 0.95); }
.wfw-plan-banner--limit { border-color: rgba(245, 183, 66, 0.55); }
.wfw-plan-banner--limit .wfw-plan-meter-fill { background: rgba(245, 183, 66, 0.95); }
.wfw-plan-banner--over { border-color: rgba(240, 106, 106, 0.6); }
.wfw-plan-banner--over .wfw-plan-meter-fill { background: rgba(240, 106, 106, 0.95); }
.wfw-plan-banner-msg, .wfw-plan-banner-note { flex: 1 1 100%; margin: 0; font-size: 0.86rem; line-height: 1.45; color: rgba(244, 247, 255, 0.78); }
.wfw-plan-banner--over .wfw-plan-banner-msg { color: #ffb4b4; }
.wfw-plan-cta { min-height: 32px; padding: 0 14px; }
.wfw-plan-note { color: rgba(244, 247, 255, 0.62); font-size: 0.82rem; }
.wfw-plan-locked { padding: 28px 24px; }
.wf-lib-locked-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 2px 0; border-radius: 8px; opacity: 0.62; cursor: not-allowed; user-select: none; }
.wf-lib-locked-row .wf-lib-sub { font-size: 0.72rem; }


/* ── Custom Fields plan usage (PLAN-ENTITLEMENTS-01E0) ──────────────────── */
.cf-plan-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin: 0 0 14px;
    padding: 12px 16px;
    border: 1px solid var(--border-soft, rgba(143, 164, 255, 0.28));
    border-radius: var(--radius-md, 10px);
    background: rgba(38, 42, 53, 0.94);
    color: var(--text-primary, #f3f6fb);
}
.cf-plan-banner.hidden { display: none; }
.cf-plan-banner-main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; flex: 1 1 320px; }
.cf-plan-banner-label { color: rgba(244, 247, 255, 0.6); font-size: 0.74rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.cf-plan-banner-usage { font-size: 0.95rem; color: #ffffff; }
.cf-plan-meter { position: relative; flex: 0 0 140px; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.cf-plan-meter-fill { display: block; height: 100%; border-radius: inherit; background: rgba(125, 150, 255, 0.95); }
.cf-plan-banner--limit { border-color: rgba(245, 183, 66, 0.55); }
.cf-plan-banner--limit .cf-plan-meter-fill { background: rgba(245, 183, 66, 0.95); }
.cf-plan-banner--over { border-color: rgba(240, 106, 106, 0.6); }
.cf-plan-banner--over .cf-plan-meter-fill { background: rgba(240, 106, 106, 0.95); }
.cf-plan-banner-msg { flex: 1 1 100%; margin: 0; font-size: 0.86rem; line-height: 1.45; color: rgba(244, 247, 255, 0.78); }
.cf-plan-banner--over .cf-plan-banner-msg { color: #ffb4b4; }
.cf-plan-cta { min-height: 32px; padding: 0 14px; }
.cf-plan-note { color: rgba(244, 247, 255, 0.62); font-size: 0.82rem; }
.admin-section-action.is-plan-locked { opacity: 0.7; cursor: not-allowed; }
