/**
 * Radim Agent — frontend visual layer
 * Sprint X20.1
 */

/* ─── Floating mode badge (corner of screen) ─── */
.radim-agent-badge {
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 1500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--radim-surface, #fff);
    border: 1.5px solid var(--radim-border, #e8e3d3);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--radim-text, #2a241c);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.92);
}
.radim-agent-badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.radim-agent-badge .rab-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #94a3b8; /* idle gray */
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* Mode-driven colors (match math_engine classify) */
.radim-agent-badge[data-mode="harmony"] .rab-dot {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}
.radim-agent-badge[data-mode="alert"] .rab-dot {
    background: #f59e0b;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.6);
}
.radim-agent-badge[data-mode="crisis"] .rab-dot {
    background: #ef4444;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.7);
}

.radim-agent-badge[data-mode="harmony"] {
    border-color: color-mix(in srgb, #22c55e 35%, var(--radim-border, #e8e3d3));
}
.radim-agent-badge[data-mode="alert"] {
    border-color: color-mix(in srgb, #f59e0b 50%, var(--radim-border, #e8e3d3));
}
.radim-agent-badge[data-mode="crisis"] {
    border-color: #ef4444;
}

/* Pulse when preemptive triggered */
.radim-agent-badge.rab-preemptive .rab-dot {
    animation: rab-pulse 1.2s ease-in-out infinite;
}
@keyframes rab-pulse {
    0%   { transform: scale(1);   opacity: 1; }
    50%  { transform: scale(1.4); opacity: 0.6; }
    100% { transform: scale(1);   opacity: 1; }
}

/* Hide on small screens unless preemptive (don't crowd UI) */
@media (max-width: 640px) {
    .radim-agent-badge:not(.rab-preemptive) {
        opacity: 0.6;
        font-size: 0;
        padding: 8px;
    }
    .radim-agent-badge:not(.rab-preemptive) .rab-label {
        display: none;
    }
}

/* ─── Detail panel (opens on badge click) ─── */
.radim-agent-panel {
    position: fixed;
    bottom: 64px;
    left: 16px;
    z-index: 1500;
    width: min(340px, calc(100vw - 32px));
    background: var(--radim-surface, #fff);
    border: 1px solid var(--radim-border, #e8e3d3);
    border-radius: 14px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.16);
    overflow: hidden;
    font-size: 0.92rem;
    color: var(--radim-text, #2a241c);
    animation: rap-slide-in 0.18s ease-out;
}

@keyframes rap-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.radim-agent-panel .rap-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--radim-surface-sunken, #fbf7ef);
    border-bottom: 1px solid var(--radim-border, #e8e3d3);
}
.radim-agent-panel .rap-close {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--radim-text-muted, #6b6052);
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
}
.radim-agent-panel .rap-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.radim-agent-panel .rap-body {
    padding: 14px 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.radim-agent-panel .rap-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 0.88rem;
}
.radim-agent-panel .rap-row span { color: var(--radim-text-muted, #6b6052); }
.radim-agent-panel .rap-row strong { font-variant-numeric: tabular-nums; }

.radim-agent-panel .rap-row strong[data-mode="harmony"] { color: #22c55e; }
.radim-agent-panel .rap-row strong[data-mode="alert"]   { color: #d97706; }
.radim-agent-panel .rap-row strong[data-mode="crisis"]  { color: #dc2626; }

.radim-agent-panel hr {
    border: none;
    height: 1px;
    background: var(--radim-border, #e8e3d3);
    margin: 10px 0;
}

.radim-agent-panel .rap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.radim-agent-panel .rap-grid > div {
    background: var(--radim-surface-sunken, #fbf7ef);
    padding: 8px 12px;
    border-radius: 8px;
    text-align: center;
}
.radim-agent-panel .rap-grid small {
    display: block;
    color: var(--radim-text-muted, #6b6052);
    font-size: 0.72rem;
    margin-bottom: 2px;
}
.radim-agent-panel .rap-grid strong {
    font-variant-numeric: tabular-nums;
    font-size: 1.05rem;
}

.radim-agent-panel .rap-warn {
    background: color-mix(in srgb, #ef4444 12%, transparent);
    border: 1px solid #ef4444;
    color: #b91c1c;
    padding: 8px 12px;
    border-radius: 8px;
    margin: 8px 0;
    font-weight: 600;
    text-align: center;
}

/* Night mode */
[data-theme="night"] .radim-agent-badge,
.sh-night .radim-agent-badge,
.dark .radim-agent-badge {
    background: rgba(31, 26, 20, 0.92);
    color: #f5f0e3;
}
[data-theme="night"] .radim-agent-panel,
.sh-night .radim-agent-panel,
.dark .radim-agent-panel {
    background: #1f1a14;
    color: #f5f0e3;
    border-color: rgba(255, 255, 255, 0.12);
}
[data-theme="night"] .radim-agent-panel .rap-head,
.sh-night .radim-agent-panel .rap-head,
.dark .radim-agent-panel .rap-head {
    background: rgba(255, 255, 255, 0.04);
}

/* ════════════════════════════════════════════════════════════════
   Sprint X20.1 — Unified voice config UI (Reproduktory tab)
   ════════════════════════════════════════════════════════════════ */

.sh-voice-cfg {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    width: 100%;
}

.sh-voice-cfg-label {
    flex: 0 0 auto;
    min-width: 88px;
    font-weight: 600;
    color: var(--radim-text-muted, #6b6052);
    font-size: 0.86rem;
}

.sh-voice-cfg-select,
.sh-voice-cfg-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--radim-border, #e8e3d3);
    border-radius: 8px;
    background: var(--radim-surface, #fff);
    color: var(--radim-text, #2a241c);
    font-size: 0.92rem;
}

.sh-voice-cfg-input {
    flex: 0 0 70px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.sh-voice-cfg-select:focus,
.sh-voice-cfg-input:focus {
    outline: 2px solid var(--radim-primary-ring, rgba(200, 168, 119, 0.55));
    outline-offset: 1px;
}

.sh-voice-cfg-unit {
    font-size: 0.82rem;
    color: var(--radim-text-subtle, #8a8074);
}

.sh-voice-cfg-mode {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--radim-surface-sunken, #fbf7ef);
    border-radius: 8px;
    font-size: 0.84rem;
    color: var(--radim-text-muted, #6b6052);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.sh-voice-cfg-mode strong {
    color: var(--radim-text, #2a241c);
    font-variant-numeric: tabular-nums;
    text-transform: uppercase;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--radim-surface, #fff);
    border: 1px solid var(--radim-border, #e8e3d3);
}
.sh-voice-cfg-mode small {
    color: var(--radim-text-subtle, #8a8074);
    font-size: 0.78rem;
}

/* Night mode */
.sh-night .sh-voice-cfg-select,
.sh-night .sh-voice-cfg-input,
.sh-night .sh-voice-cfg-mode strong {
    background: rgba(255, 255, 255, 0.06);
    color: var(--radim-cream);
    border-color: color-mix(in srgb, var(--radim-primary) 18%, transparent);
}
.sh-night .sh-voice-cfg-mode {
    background: rgba(255, 255, 255, 0.04);
}

/* ════════════════════════════════════════════════════════════════
   Sprint X20.1 / Fix 2 — Cross-module mode-aware styling
   ════════════════════════════════════════════════════════════════
   RadimAgent sets <html data-agent-mode="harmony|alert|crisis|idle">
   so any module can react via CSS without JS plumbing.

   Subtle visual signals — never block UI, never panic the user.
   Stronger signals only at CRISIS or when preemptive triggered. */

/* ─── ALERT mode: subtle warm border ─── */
html[data-agent-mode="alert"] body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent 0%, #f59e0b 30%, #f59e0b 70%, transparent 100%);
    z-index: 1200;
    pointer-events: none;
    opacity: 0.55;
}

/* ─── CRISIS mode: stronger coral border + animated pulse ─── */
html[data-agent-mode="crisis"] body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, #ef4444, #f87171, #ef4444);
    z-index: 1200;
    pointer-events: none;
    animation: rab-crisis-bar 2.4s ease-in-out infinite;
}
@keyframes rab-crisis-bar {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* ─── PREEMPTIVE flag: dotted gold underline on the crisis bar ─── */
html[data-agent-preemptive="true"] body::after {
    content: '';
    position: fixed;
    top: 4px; left: 0; right: 0;
    height: 2px;
    background:
      repeating-linear-gradient(90deg,
        var(--radim-primary, #c8a877) 0,
        var(--radim-primary, #c8a877) 4px,
        transparent 4px,
        transparent 8px);
    z-index: 1200;
    pointer-events: none;
    opacity: 0.7;
}

/* ─── Komunikace tab: pulse hint when CRISIS — suggests "call family" ─── */
html[data-agent-mode="crisis"] .nav-item--communication,
html[data-agent-mode="crisis"] [data-module="communication"] .module-tab,
html[data-agent-mode="crisis"] .sh-tab[onclick*="communication"] {
    animation: rab-tab-pulse 1.6s ease-in-out infinite;
}
@keyframes rab-tab-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.0); }
    50%      { box-shadow: 0 0 12px 2px rgba(239, 68, 68, 0.45); }
}

/* ─── Smart-home Reproduktory: live mode display already present
   in sh-voice-cfg-mode (in module HTML), the value is updated by JS.
   Just emphasize it visually when not HARMONY. ─── */
html[data-agent-mode="alert"] .sh-voice-cfg-mode strong { color: #b45309; }
html[data-agent-mode="crisis"] .sh-voice-cfg-mode strong { color: #b91c1c; }

/* ─── Mode badge already pulses via .rab-preemptive — nothing extra. ─── */

/* ─── Respect prefers-reduced-motion ─── */
@media (prefers-reduced-motion: reduce) {
    html[data-agent-mode="crisis"] body::before { animation: none; }
    html[data-agent-mode="crisis"] .nav-item--communication,
    html[data-agent-mode="crisis"] [data-module="communication"] .module-tab,
    html[data-agent-mode="crisis"] .sh-tab[onclick*="communication"] { animation: none; }
}
