/* ============================================================
   KPIcons Shared Design System
   Single source of truth for tokens + reusable components.
   Loaded by every page after page-specific styles, so it can
   be selectively overridden during the migration.
   ============================================================ */

:root {
    /* Brand */
    --kpi-accent: #009CDE;
    --kpi-accent-hover: #0085B8;
    --kpi-accent-orange: #FF9933;
    --kpi-accent-glow: rgba(0, 156, 222, 0.18);

    /* Status */
    --kpi-status-green: #22C55E;
    --kpi-status-yellow: #FF9933;
    --kpi-status-red: #EF4444;

    /* Card outline (light blue, used on ALL tiles) */
    --kpi-tile-border: rgba(0, 156, 222, 0.38);
    --kpi-tile-border-hover: rgba(0, 156, 222, 0.6);
    --kpi-tile-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 156, 222, 0.08);
    --kpi-tile-shadow-hover: 0 12px 48px rgba(0, 156, 222, 0.22), 0 0 0 1px rgba(0, 156, 222, 0.18);

    /* Typography scale */
    --kpi-font-display: 4rem;
    --kpi-font-h1: 1.6rem;
    --kpi-font-h2: 1.25rem;
    --kpi-font-body: 0.875rem;
    --kpi-font-meta: 0.75rem;
    --kpi-font-micro: 0.65rem;

    /* Radius */
    --kpi-radius-sm: 8px;
    --kpi-radius-md: 12px;
    --kpi-radius-lg: 16px;
    --kpi-radius-pill: 999px;
}

/* ---------- Glass card (the universal container) ---------- */
.kpi-glass {
    background: var(--card-surface, rgba(13, 31, 60, 0.8));
    border: 1.5px solid var(--kpi-tile-border);
    border-radius: var(--kpi-radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: var(--kpi-tile-shadow);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-width: 0;
}
.kpi-glass:hover {
    border-color: var(--kpi-tile-border-hover);
    box-shadow: var(--kpi-tile-shadow-hover);
    transform: translateY(-4px);
}

/* ---------- Status pill ---------- */
.kpi-pill {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--kpi-radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.kpi-pill.green  { background: rgba(34, 197, 94, 0.15);  color: var(--kpi-status-green); }
.kpi-pill.yellow { background: rgba(255, 153, 51, 0.15); color: var(--kpi-status-yellow); }
.kpi-pill.red    { background: rgba(239, 68, 68, 0.15);  color: var(--kpi-status-red); }
.kpi-pill.info   { background: rgba(0, 156, 222, 0.15);  color: var(--kpi-accent); }

/* ---------- Persona / mood / resource badges ---------- */
.kpi-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--kpi-radius-sm);
    line-height: 1.4;
}
.kpi-badge.mood           { background: rgba(0, 156, 222, 0.12);  color: var(--kpi-accent); border: 1px solid rgba(0, 156, 222, 0.25); }
.kpi-badge.best-practices { background: rgba(139, 92, 246, 0.12); color: #A78BFA; border: 1px solid rgba(139, 92, 246, 0.25); }
.kpi-badge.life-preserver { background: rgba(239, 68, 68, 0.12);  color: #F87171; border: 1px solid rgba(239, 68, 68, 0.25); animation: kpiPulse 2.4s ease-in-out infinite; }

@keyframes kpiPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50%     { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ---------- Score hero (used across Scoreboard + Manager) ---------- */
.kpi-score-hero {
    background: linear-gradient(135deg, rgba(0,156,222,0.18) 0%, rgba(255,153,51,0.08) 50%, rgba(13,31,60,0.9) 100%);
    border: 1.5px solid var(--kpi-tile-border);
    border-radius: 20px;
    padding: 28px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 156, 222, 0.18), 0 0 0 1px rgba(0, 156, 222, 0.12);
}
.kpi-score-hero::before {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 240px; height: 240px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 156, 222, 0.25), transparent 70%);
    pointer-events: none;
}
.kpi-score-number {
    font-size: var(--kpi-font-display);
    font-weight: 800;
    background: linear-gradient(135deg, var(--kpi-accent), var(--kpi-accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

/* ---------- Time-remaining chip ---------- */
.kpi-time-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 153, 51, 0.15);
    border: 1px solid rgba(255, 153, 51, 0.4);
    color: var(--kpi-accent-orange);
    padding: 6px 14px;
    border-radius: var(--kpi-radius-pill);
    font-size: 12px;
    font-weight: 600;
}

/* ============================================================
   Persistent AI Companion Rail
   ------------------------------------------------------------
   Always-present George/companion dock on the right edge.
   - Expanded (default): 300px full chat rail.
   - Collapsed: 48px stripe with avatar + unread dot.
   - Body gets a matching padding-right so the page can use
     the FULL horizontal real estate up to the rail.
   - Loaded after each page's inline <style> block, so these
     rules override the per-page ad-hoc .bot-panel widths.
   ============================================================ */

:root {
    --kpi-bot-width: 300px;
    --kpi-bot-width-collapsed: 48px;
    --kpi-sidebar-width: 250px;
}

.bot-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--kpi-bot-width);
    min-width: var(--kpi-bot-width);
    max-width: var(--kpi-bot-width);
    height: 100vh;
    z-index: 900;
    background-color: var(--bg-bot, var(--bg-sidebar, #0A1628));
    border-left: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    display: flex;
    flex-direction: column;
    color: var(--text-primary, #F8FAFC);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.25);
    transition: width 0.25s ease, min-width 0.25s ease, max-width 0.25s ease;
}

/* ----- Bot panel internals (used by both inline + auto-mounted shells) ----- */
.bot-panel .bot-header {
    padding: 20px;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.bot-panel .bot-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--kpi-accent) 0%, var(--kpi-accent-orange) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    position: relative;
}
/* Unread-message indicator on the avatar.
   Only visible when the bot-panel has data-unread="1" AND the rail is collapsed,
   so the user gets a subtle attention cue without extra chrome in the normal state. */
.bot-panel[data-unread="1"] .bot-avatar::after {
    content: '';
    position: absolute;
    top: -3px;
    right: -3px;
    width: 12px;
    height: 12px;
    background: #EF4444;
    border: 2px solid var(--bg-bot, var(--bg-sidebar, #0A1628));
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55);
    animation: kpiBotUnreadPulse 1.6s ease-out infinite;
    pointer-events: none;
}
@keyframes kpiBotUnreadPulse {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    70%  { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.bot-panel .bot-header-info { flex: 1; min-width: 0; }
.bot-panel .bot-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary, #F8FAFC);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bot-panel .bot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--kpi-accent);
    margin-top: 2px;
}
.bot-panel .bot-status-dot {
    width: 6px;
    height: 6px;
    background-color: var(--kpi-accent);
    border-radius: 50%;
    animation: kpiBotPulse 2s infinite;
}
@keyframes kpiBotPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}
.bot-panel .bot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}
.bot-panel .bot-messages::-webkit-scrollbar { width: 4px; }
.bot-panel .bot-messages::-webkit-scrollbar-track { background: transparent; }
.bot-panel .bot-messages::-webkit-scrollbar-thumb { background: var(--border, rgba(255, 255, 255, 0.08)); border-radius: 2px; }
.bot-panel .bot-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    animation: kpiBotMsgIn 0.3s ease;
}
@keyframes kpiBotMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.bot-panel .bot-msg.bot {
    background-color: var(--bot-msg-bg, rgba(26, 41, 66, 0.8));
    border: 1px solid var(--bot-msg-border, rgba(255, 255, 255, 0.08));
    color: var(--bot-msg-text, #94A3B8);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.bot-panel .bot-msg.user {
    background: linear-gradient(135deg, var(--kpi-accent) 0%, var(--kpi-accent-orange) 100%);
    color: #FFFFFF;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.bot-panel .bot-msg .msg-time { font-size: 10px; color: var(--text-tertiary, #64748B); margin-top: 4px; }
.bot-panel .bot-msg.user .msg-time { color: rgba(255, 255, 255, 0.6); }
.bot-panel .bot-msg strong { color: var(--kpi-accent); }
.bot-panel .bot-msg.user strong { color: #FFFFFF; }
.bot-panel .bot-input-area {
    padding: 16px;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    flex-shrink: 0;
}
.bot-panel .bot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}
.bot-panel .bot-input {
    flex: 1;
    min-width: 0;
    background-color: var(--bg-input, #1a2a4a);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary, #F8FAFC);
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.2s ease;
}
.bot-panel .bot-input:focus {
    outline: none;
    border-color: var(--kpi-accent);
    box-shadow: 0 0 0 3px rgba(0, 156, 222, 0.1);
}
.bot-panel .bot-input::placeholder { color: var(--text-tertiary, #64748B); }
.bot-panel .bot-send-btn {
    width: 36px;
    height: 36px;
    background: var(--kpi-accent);
    border: none;
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.bot-panel .bot-send-btn:hover { background: var(--kpi-accent-hover); box-shadow: 0 4px 12px rgba(0, 156, 222, 0.3); }
.bot-panel .bot-send-btn:active { transform: scale(0.95); }

/* Reserve space at the right edge so every pixel between the sidebar
   and the rail is usable content. Driven by body.has-companion which
   the bot-ui JS sets on pages where a rail is mounted. Works regardless
   of whether the page uses the .container/.main-content pattern or its
   own layout (it-admin, kpi-studio, ai-inbox, etc.). */
body.has-companion {
    padding-right: var(--kpi-bot-width);
    transition: padding-right 0.25s ease;
}

/* ---------- Collapsed state ---------- */
body.bot-collapsed .bot-panel {
    width: var(--kpi-bot-width-collapsed);
    min-width: var(--kpi-bot-width-collapsed);
    max-width: var(--kpi-bot-width-collapsed);
}
body.bot-collapsed.has-companion {
    padding-right: var(--kpi-bot-width-collapsed);
}
body.bot-collapsed .bot-header-info,
body.bot-collapsed .bot-messages,
body.bot-collapsed .bot-input-area {
    display: none;
}
body.bot-collapsed .bot-header {
    justify-content: center;
    padding: 14px 0;
    border-bottom: none;
    cursor: pointer;
}
body.bot-collapsed .bot-header .bot-avatar {
    cursor: pointer;
}

/* ---------- Collapse / expand toggle ---------- */
.bot-collapse-toggle {
    position: absolute;
    top: 50%;
    left: -14px;
    transform: translateY(-50%);
    width: 28px;
    height: 44px;
    background: var(--kpi-accent);
    color: #ffffff;
    border: none;
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 901;
    box-shadow: -4px 0 14px rgba(0, 0, 0, 0.25);
    transition: background 0.2s ease, transform 0.2s ease;
    line-height: 1;
}
.bot-collapse-toggle:hover {
    background: var(--kpi-accent-hover);
    transform: translateY(-50%) scale(1.05);
}
.bot-collapse-toggle::before {
    content: '›';
    font-size: 20px;
    transition: transform 0.25s ease;
    display: inline-block;
}
body.bot-collapsed .bot-collapse-toggle::before {
    transform: rotate(180deg);
}

/* ---------- Responsive: hide rail on mobile/tablet, reclaim space ---------- */
@media (max-width: 1024px) {
    .bot-panel { display: none; }
    body.has-companion { padding-right: 0; }
}

/* ---------- Telemetry debug button (floating) ---------- */
.kpi-debug-fab {
    position: fixed;
    bottom: 16px; left: 16px;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: var(--kpi-accent);
    border: 1px solid var(--kpi-tile-border);
    font-size: 16px;
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    opacity: 0.5;
}
.kpi-debug-fab:hover { opacity: 1; transform: scale(1.1); }
