/* ============================================================
   Recession Probability Indicator — Widget Styles
   ============================================================ */

:root {
    --rpi-bg:        #12121f;
    --rpi-surface:   #1a1a2e;
    --rpi-border:    #2a2a45;
    --rpi-text:      #e2e2f0;
    --rpi-muted:     #888899;
    --rpi-radius:    14px;
    --rpi-radius-sm: 8px;
    --rpi-green:     #22c55e;
    --rpi-yellow:    #eab308;
    --rpi-orange:    #f97316;
    --rpi-red:       #ef4444;
}

/* ── Base widget container ─────────────────────────── */
.rpi-widget {
    background:    var(--rpi-surface);
    border:        1px solid var(--rpi-border);
    border-radius: var(--rpi-radius);
    padding:       24px;
    color:         var(--rpi-text);
    font-family:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size:     14px;
    line-height:   1.5;
    max-width:     640px;
    margin:        0 auto 32px;
    box-shadow:    0 4px 24px rgba(0,0,0,.45);
    position:      relative;
    overflow:      hidden;
}

/* Subtle gradient top accent */
.rpi-widget::before {
    content:  '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899);
    border-radius: var(--rpi-radius) var(--rpi-radius) 0 0;
}

/* ── Header ────────────────────────────────────────── */
.rpi-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    margin-bottom:   18px;
    gap:             12px;
    flex-wrap:       wrap;
}

.rpi-title {
    font-size:   16px;
    font-weight: 700;
    letter-spacing: .3px;
    color: var(--rpi-text);
}

.rpi-badge {
    font-size:     11px;
    font-weight:   700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color:          #fff;
    padding:        4px 10px;
    border-radius:  20px;
    white-space:    nowrap;
}

/* ── Body: gauge + components ─────────────────────── */
.rpi-body {
    display:   flex;
    gap:       24px;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: 20px;
}

/* ── Gauge ─────────────────────────────────────────── */
.rpi-gauge-wrap {
    position:   relative;
    text-align: center;
    flex:       0 0 auto;
}

.rpi-gauge-wrap canvas {
    display: block;
    margin:  0 auto;
}

.rpi-pct {
    font-size:   34px;
    font-weight: 800;
    line-height: 1;
    margin-top: -42px;       /* overlap gauge bottom */
    position: relative;
    z-index: 1;
}

.rpi-pct span {
    font-size:   18px;
    font-weight: 600;
    opacity:     .7;
}

.rpi-pct-label {
    font-size:  11px;
    color:      var(--rpi-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: .6px;
}

/* ── Component bars ────────────────────────────────── */
.rpi-components {
    flex: 1 1 220px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.rpi-comp-row {
    display:     grid;
    grid-template-columns: 1fr 100px 48px;
    align-items: center;
    gap:         8px;
}

.rpi-comp-label {
    font-size:  12px;
    color:      var(--rpi-muted);
    white-space: nowrap;
}

.rpi-comp-label em {
    font-style: normal;
    color: var(--rpi-border);
    font-size: 10px;
    margin-left: 3px;
}

.rpi-comp-bar-wrap {
    background:    var(--rpi-bg);
    border-radius: 4px;
    height:        7px;
    overflow:      hidden;
}

.rpi-comp-bar {
    height:        100%;
    border-radius: 4px;
    transition:    width .6s ease;
}

.rpi-comp-val {
    font-size:  11px;
    color:      var(--rpi-text);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Sparkline section ─────────────────────────────── */
.rpi-sparkline-section {
    margin-top:    4px;
    padding-top:   16px;
    border-top:    1px solid var(--rpi-border);
    margin-bottom: 12px;
}

.rpi-spark-title {
    font-size:   11px;
    color:       var(--rpi-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 8px;
}

/* ── Footer ────────────────────────────────────────── */
.rpi-footer {
    font-size:  11px;
    color:      var(--rpi-muted);
    text-align: right;
    padding-top: 8px;
    border-top:  1px solid var(--rpi-border);
}

/* ── P/E Widget extras ─────────────────────────────── */
.rpi-pe-widget .rpi-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.rpi-pe-kpis {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.rpi-kpi {
    font-size: 13px;
    color: var(--rpi-muted);
}

.rpi-kpi strong {
    font-size:   18px;
    font-weight: 700;
}

.rpi-pe-legend {
    display:       flex;
    gap:           16px;
    margin-bottom: 14px;
    flex-wrap:     wrap;
}

.rpi-zone {
    font-size:   11px;
    font-weight: 600;
    letter-spacing: .3px;
}

.rpi-zone--green  { color: var(--rpi-green);  }
.rpi-zone--yellow { color: var(--rpi-yellow); }
.rpi-zone--red    { color: var(--rpi-red);    }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 520px) {
    .rpi-widget    { padding: 16px; }
    .rpi-body      { flex-direction: column; align-items: center; }
    .rpi-gauge-wrap canvas { width: 180px !important; height: 110px !important; }
    .rpi-pct       { font-size: 28px; margin-top: -34px; }
    .rpi-comp-row  { grid-template-columns: 1fr 80px 40px; }
    .rpi-pe-kpis   { gap: 12px; }
}

/* ── Dark-mode override (if host theme forces light) ── */
@media (prefers-color-scheme: light) {
    .rpi-widget {
        --rpi-bg:      #f3f4f6;
        --rpi-surface: #ffffff;
        --rpi-border:  #e5e7eb;
        --rpi-text:    #111827;
        --rpi-muted:   #6b7280;
        box-shadow: 0 2px 16px rgba(0,0,0,.10);
    }
}
