/* ==========================================================================
   VOICE COMPANION PANEL — Phosphor Theatre Extension
   ==========================================================================

   Location:  /static/css/voice-companion.css
   Activator: Inside .note-rail[data-theme="terminal"]
   Purpose:   Live section preview during voice dictation
   Depends:   note-rail-terminal.css (--term-* design tokens)

   Component Hierarchy:
     .voice-companion-panel
       .vcp-header
         .vcp-recording-status (.active)
         .vcp-live-caption
         .vcp-collapse-toggle
       .vcp-section-grid
         .vcp-section-card (.active, .needs-review, .uncertain)
           .vcp-card-header
             .vcp-card-icon
             .vcp-card-title
             .vcp-confidence-badge (.high, .medium, .low, .uncertain)
           .vcp-card-body
             .vcp-kv-row
           .vcp-card-source
       .vcp-footer
         .vcp-action-btn (.primary, .ghost)
       .vcp-error-banner
   ========================================================================== */


/* ==========================================================================
   §1  PANEL CONTAINER
   ========================================================================== */

.voice-companion-panel {
    display: flex;
    flex-direction: column;
    background: var(--term-bg-surface, #13120F);
    border: 1px solid var(--term-border-default, #2A2720);
    border-radius: var(--term-radius-none, 0);
    margin: var(--term-space-md) 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.voice-companion-panel[hidden] {
    display: none;
}


/* ==========================================================================
   §2  HEADER — Recording Status + Live Caption + Collapse Toggle
   ========================================================================== */

.vcp-header {
    display: flex;
    align-items: center;
    gap: var(--term-space-sm);
    padding: var(--term-space-sm) var(--term-space-md);
    background: var(--term-bg-header, #0E0D0B);
    border-bottom: 1px solid var(--term-border-subtle, #1E1C18);
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
    letter-spacing: var(--term-tracking-wide);
    text-transform: uppercase;
    color: var(--term-fg-muted);
}

/* --- Recording Status --- */

.vcp-recording-status {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.vcp-recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--term-fg-muted);
    flex-shrink: 0;
}

.vcp-recording-status.active .vcp-recording-dot {
    background: #EF4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
    animation: vcp-pulse 1.5s ease-in-out infinite;
}

.vcp-recording-label {
    color: var(--term-fg-secondary);
}

.vcp-recording-status.active .vcp-recording-label {
    color: #EF4444;
}

.vcp-recording-timer {
    color: var(--term-fg-muted);
    font-variant-numeric: tabular-nums;
}

/* --- Live Caption --- */

.vcp-live-caption {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-family: var(--term-font-body);
    font-size: var(--term-text-sm);
    color: var(--term-fg-secondary);
    text-transform: none;
    letter-spacing: normal;
}

.vcp-live-caption .vcp-caption-text {
    font-style: italic;
}

/* --- Pair iPhone Button --- */

.vcp-pair-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid var(--term-border-subtle);
    background: transparent;
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.vcp-pair-btn:hover {
    color: var(--term-fg-primary);
    border-color: var(--term-border-default);
}

.vcp-pair-label {
    white-space: nowrap;
}

/* --- Collapse Toggle --- */

.vcp-collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid var(--term-border-subtle);
    background: transparent;
    color: var(--term-fg-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.vcp-collapse-toggle:hover {
    color: var(--term-fg-primary);
    border-color: var(--term-border-default);
}

.vcp-toggle-icon {
    font-size: 12px;
    line-height: 1;
    transition: transform 0.2s ease;
}

.vcp-collapse-toggle[aria-expanded="false"] .vcp-toggle-icon {
    transform: rotate(-90deg);
}


/* ==========================================================================
   §3  CONFIDENCE BADGES
   ========================================================================== */

.vcp-confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 2px;
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
    font-weight: 500;
    letter-spacing: var(--term-tracking-wide);
    white-space: nowrap;
}

/* Verified — Electric Mint (>= 85%) */
.vcp-confidence-badge.high {
    color: var(--term-accent, #00FFD0);
    background: var(--term-accent-subtle, rgba(0, 255, 208, 0.10));
    border: 1px solid var(--term-accent-dim, rgba(0, 255, 208, 0.40));
    box-shadow: var(--term-glow-accent);
}

/* Review — Art Deco Gold (60–84%) */
.vcp-confidence-badge.medium {
    color: var(--term-gold, #D4A857);
    background: var(--term-gold-subtle, rgba(212, 168, 87, 0.10));
    border: 1px solid var(--term-gold-dim, rgba(212, 168, 87, 0.35));
    box-shadow: var(--term-glow-gold);
}

/* Low — Warning Orange (35–59%) */
.vcp-confidence-badge.low {
    color: #FF8C42;
    background: rgba(255, 140, 66, 0.10);
    border: 1px solid rgba(255, 140, 66, 0.35);
    box-shadow: 0 0 8px rgba(255, 140, 66, 0.20);
}

/* Uncertain — Error Red (< 35%) */
.vcp-confidence-badge.uncertain {
    color: var(--term-status-error, #EF4444);
    background: rgba(239, 68, 68, 0.10);
    border: 1px solid rgba(239, 68, 68, 0.35);
    box-shadow: var(--term-glow-error);
}


/* ==========================================================================
   §4  SECTION GRID + CARDS
   ========================================================================== */

.vcp-section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--term-space-sm);
    padding: var(--term-space-md);
    max-height: 320px;
    overflow-y: auto;
}

/* Scrollbar styling for terminal theme */
.vcp-section-grid::-webkit-scrollbar {
    width: 4px;
}

.vcp-section-grid::-webkit-scrollbar-track {
    background: transparent;
}

.vcp-section-grid::-webkit-scrollbar-thumb {
    background: var(--term-border-default);
}

/* --- Section Card --- */

.vcp-section-card {
    position: relative;
    background: var(--term-bg-elevated, #1B1A16);
    border: 1px solid var(--term-border-subtle, #1E1C18);
    padding: var(--term-space-sm) var(--term-space-md);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;

    /* Stepped corners (Phosphor Theatre ziggurat) */
    clip-path: polygon(
        0 8px, 8px 0, 100% 0, 100% calc(100% - 8px),
        calc(100% - 8px) 100%, 0 100%
    );

    /* Entrance animation */
    animation: vcp-card-appear 0.3s ease backwards;
}

.vcp-section-card:hover {
    border-color: var(--term-border-strong, #3A3630);
}

.vcp-section-card:focus-visible {
    outline: 2px solid var(--term-accent);
    outline-offset: 2px;
}

/* Active section — currently being dictated into */
.vcp-section-card.active {
    border-color: var(--term-accent, #00FFD0);
    box-shadow: var(--term-glow-accent);
}

.vcp-section-card.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--term-accent, #00FFD0);
    animation: vcp-active-scan 2s linear infinite;
}

/* --- Card Header --- */

.vcp-card-header {
    display: flex;
    align-items: center;
    gap: var(--term-space-sm);
    margin-bottom: var(--term-space-xs);
}

.vcp-card-icon {
    color: var(--term-fg-muted);
    font-size: var(--term-text-sm);
}

.vcp-card-title {
    flex: 1;
    font-family: var(--term-font-display, 'Outfit');
    font-size: var(--term-text-sm);
    font-weight: 500;
    color: var(--term-fg-primary, #E8E4DC);
    letter-spacing: var(--term-tracking-wide);
    text-transform: uppercase;
}

/* --- Card Body (key-value pairs) --- */

.vcp-card-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
}

.vcp-section-card[aria-expanded="true"] .vcp-card-body {
    max-height: 300px;
}

.vcp-kv-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
}

.vcp-kv-key {
    color: var(--term-fg-muted);
}

.vcp-kv-value {
    color: var(--term-fg-primary);
    font-weight: 500;
}

/* Editable values (edit mode) */
.vcp-kv-value[contenteditable="true"] {
    border-bottom: 1px solid var(--term-accent-dim);
    outline: none;
    min-width: 40px;
}

.vcp-kv-value[contenteditable="true"]:focus {
    border-bottom-color: var(--term-accent);
}

/* Narrative text (for HPI, Assessment, Plan) */
.vcp-card-narrative {
    font-family: var(--term-font-body);
    font-size: var(--term-text-xs);
    color: var(--term-fg-secondary);
    line-height: 1.5;
    padding: 2px 0;
    white-space: pre-wrap;
}

.vcp-card-narrative[contenteditable="true"] {
    border: 1px solid var(--term-accent-dim);
    padding: 4px;
    outline: none;
}

.vcp-card-narrative[contenteditable="true"]:focus {
    border-color: var(--term-accent);
}

/* --- Source Tier Indicator --- */

.vcp-card-source {
    margin-top: var(--term-space-xs);
}

.vcp-source-tier {
    display: inline-block;
    padding: 1px 4px;
    font-family: var(--term-font-mono);
    font-size: 9px;
    letter-spacing: var(--term-tracking-wider);
    color: var(--term-fg-muted);
    background: var(--term-bg-void);
    border: 1px solid var(--term-border-subtle);
}


/* ==========================================================================
   §5  SHIMMER EFFECTS — Low Confidence Attention
   ========================================================================== */

/* Orange shimmer for needs-review (35-59%) */
.vcp-section-card.needs-review::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        110deg,
        transparent 25%,
        rgba(255, 140, 66, 0.06) 37%,
        transparent 63%
    );
    animation: vcp-shimmer 2.5s ease-in-out infinite;
    pointer-events: none;
}

/* Red shimmer for uncertain (<35%) */
.vcp-section-card.uncertain::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        110deg,
        transparent 25%,
        rgba(239, 68, 68, 0.06) 37%,
        transparent 63%
    );
    animation: vcp-shimmer 2s ease-in-out infinite;
    pointer-events: none;
}


/* ==========================================================================
   §6  FOOTER — Action Buttons
   ========================================================================== */

.vcp-footer {
    display: flex;
    align-items: center;
    gap: var(--term-space-sm);
    padding: var(--term-space-sm) var(--term-space-md);
    border-top: 1px solid var(--term-border-subtle);
    background: var(--term-bg-header);
}

/* Action Buttons */
.vcp-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid var(--term-border-default);
    background: transparent;
    color: var(--term-fg-secondary);
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
    letter-spacing: var(--term-tracking-wide);
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s ease;

    /* Ziggurat clip */
    clip-path: polygon(
        0 4px, 4px 0, 100% 0, 100% calc(100% - 4px),
        calc(100% - 4px) 100%, 0 100%
    );
}

.vcp-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Primary — mint accent for "Use as Input" */
.vcp-action-btn.primary {
    background: var(--term-accent-subtle);
    color: var(--term-accent);
    border-color: var(--term-accent-dim);
}

.vcp-action-btn.primary:hover:not(:disabled) {
    background: var(--term-accent-dim);
    box-shadow: var(--term-glow-accent);
}

/* Ghost — transparent for Edit/Clear */
.vcp-action-btn.ghost:hover:not(:disabled) {
    background: var(--term-bg-elevated);
    color: var(--term-fg-primary);
}


/* ==========================================================================
   §7  ERROR BANNER
   ========================================================================== */

.vcp-error-banner {
    display: flex;
    align-items: center;
    gap: var(--term-space-sm);
    padding: var(--term-space-sm) var(--term-space-md);
    background: rgba(239, 68, 68, 0.08);
    border-top: 1px solid rgba(239, 68, 68, 0.25);
    color: var(--term-status-error, #EF4444);
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
}

.vcp-error-banner[hidden] {
    display: none;
}

.vcp-error-icon {
    flex-shrink: 0;
    font-size: var(--term-text-sm);
}

.vcp-error-message {
    flex: 1;
}

.vcp-error-retry {
    padding: 3px 8px;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: transparent;
    color: var(--term-status-error);
    font-family: var(--term-font-mono);
    font-size: var(--term-text-xs);
    letter-spacing: var(--term-tracking-wide);
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s ease;
}

.vcp-error-retry:hover {
    background: rgba(239, 68, 68, 0.15);
}


/* ==========================================================================
   §8  ANIMATIONS
   ========================================================================== */

/* Recording dot pulse */
@keyframes vcp-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Active section top border pulse */
@keyframes vcp-active-scan {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Low confidence shimmer sweep */
@keyframes vcp-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Card entrance animation */
@keyframes vcp-card-appear {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Stagger entrance for multiple cards appearing at once */
.vcp-section-card:nth-child(1) { animation-delay: 0ms; }
.vcp-section-card:nth-child(2) { animation-delay: 50ms; }
.vcp-section-card:nth-child(3) { animation-delay: 100ms; }
.vcp-section-card:nth-child(4) { animation-delay: 150ms; }
.vcp-section-card:nth-child(5) { animation-delay: 200ms; }
.vcp-section-card:nth-child(6) { animation-delay: 250ms; }


/* ==========================================================================
   §9  COLLAPSED STATE — Header-only compact mode
   ========================================================================== */

.voice-companion-panel.collapsed .vcp-section-grid,
.voice-companion-panel.collapsed .vcp-footer {
    display: none;
}


/* ==========================================================================
   §10  RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* Desktop (1600+): 3-column grid */
@media (min-width: 1600px) {
    .vcp-section-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Laptop (1200–1599): 2-column grid */
@media (max-width: 1599px) {
    .vcp-section-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Narrow rail / small viewport: 1-column, compact */
@media (max-width: 600px) {
    .vcp-section-grid {
        grid-template-columns: 1fr;
        gap: var(--term-space-xs);
    }

    .vcp-section-card {
        padding: var(--term-space-xs) var(--term-space-sm);
    }
}

/* Mobile: hide entirely — dictation uses phone relay pattern */
@media (max-width: 768px) {
    .voice-companion-panel {
        display: none;
    }
}
