/**
 * css/synthesis.css — AI Synthesis Modal Styles
 *
 * Chat-style UI for the AI power synthesis copilot.
 * Follows the existing design token system (design-tokens.css).
 * Uses glassmorphism, smooth transitions, and the purple AI accent.
 */

/* ─────────────────────────────────────────────
   Modal Shell — Wider than default for chat UI
   ───────────────────────────────────────────── */

.synthesis-modal-content {
    max-width: 560px;
    width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
}

.synthesis-modal-header {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(59, 130, 246, 0.06));
    border-bottom: 1px solid rgba(124, 58, 237, 0.15);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.synthesis-modal-header h2 {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

/* PRO badge pill next to the title */
.synthesis-badge-pro {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.8px;
    border-radius: 4px;
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
    margin-left: 6px;
    vertical-align: middle;
}

.synthesis-modal-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
}

/* ─────────────────────────────────────────────
   Chat Area — Scrollable message history
   ───────────────────────────────────────────── */

.synthesis-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 50vh;
}

/* Individual chat message bubble */
.synthesis-msg {
    display: flex;
    gap: 10px;
    animation: synthesisFadeIn 0.3s ease-out;
}

@keyframes synthesisFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Avatar circle for assistant messages */
.synthesis-msg-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.synthesis-msg-assistant .synthesis-msg-avatar {
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
}

.synthesis-msg-user .synthesis-msg-avatar {
    background: var(--color-bg-secondary, #1e293b);
    color: var(--color-text-primary, #f1f5f9);
}

/* Message content bubble */
.synthesis-msg-content {
    flex: 1;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
}

.synthesis-msg-assistant .synthesis-msg-content {
    background: var(--color-bg-secondary, #1e293b);
    border: 1px solid var(--color-border, rgba(255,255,255,0.08));
}

.synthesis-msg-user .synthesis-msg-content {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.2);
}

.synthesis-msg-content p {
    margin: 0 0 6px 0;
}
.synthesis-msg-content p:last-child {
    margin-bottom: 0;
}

.synthesis-hint {
    color: var(--color-text-tertiary, #94a3b8);
    font-size: 12px;
}

.synthesis-hint em {
    color: var(--color-text-secondary, #cbd5e1);
    font-style: italic;
}

/* ─────────────────────────────────────────────
   Loading Indicator (3-dot bounce)
   ───────────────────────────────────────────── */

.synthesis-loading-dots {
    display: inline-flex;
    gap: 4px;
    padding: 6px 0;
}

.synthesis-loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #7c3aed;
    animation: synthDotBounce 1.2s infinite ease-in-out;
}

.synthesis-loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.synthesis-loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes synthDotBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.0); opacity: 1; }
}

/* ─────────────────────────────────────────────
   Error State
   ───────────────────────────────────────────── */

.synthesis-error-content {
    color: #ef4444;
    font-size: 12px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.synthesis-error-content .material-symbols-outlined {
    font-size: 16px;
    flex-shrink: 0;
}

/* ─────────────────────────────────────────────
   Generated Design Preview (inside chat)
   ───────────────────────────────────────────── */

.synthesis-preview {
    margin-top: 10px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(124, 58, 237, 0.05);
    border: 1px solid rgba(124, 58, 237, 0.15);
}

.synthesis-preview-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 12px;
    color: #7c3aed;
}

.synthesis-preview-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
}

.synthesis-preview-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--color-bg-secondary, #1e293b);
    border: 1px solid var(--color-border, rgba(255,255,255,0.06));
    min-width: 60px;
}

.synthesis-preview-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text-primary, #f1f5f9);
}

.synthesis-preview-stat-label {
    font-size: 10px;
    color: var(--color-text-tertiary, #94a3b8);
    margin-top: 2px;
}

/* Action buttons for applying/regenerating */
.synthesis-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn-synthesis-apply {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-synthesis-apply:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.35);
}

.btn-synthesis-apply:active {
    transform: translateY(0);
}

.btn-synthesis-apply .material-symbols-outlined {
    font-size: 18px;
}

.btn-synthesis-regen {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border: 1px solid var(--color-border, rgba(255,255,255,0.1));
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-secondary, #cbd5e1);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-synthesis-regen:hover {
    border-color: #7c3aed;
    color: #7c3aed;
}

.btn-synthesis-regen .material-symbols-outlined {
    font-size: 16px;
}

/* ─────────────────────────────────────────────
   Input Area — Fixed at bottom of modal
   ───────────────────────────────────────────── */

.synthesis-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
    background: var(--color-bg-primary, #0f172a);
}

.synthesis-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--color-bg-secondary, #1e293b);
    border: 1px solid var(--color-border, rgba(255,255,255,0.1));
    border-radius: 12px;
    padding: 8px 10px;
    transition: border-color 0.2s ease;
}

.synthesis-input-wrapper:focus-within {
    border-color: rgba(124, 58, 237, 0.5);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.1);
}

.synthesis-textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-text-primary, #f1f5f9);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
}

.synthesis-textarea::placeholder {
    color: var(--color-text-tertiary, #64748b);
}

/* Send / Generate button */
.btn-synthesis-generate {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-synthesis-generate:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.4);
}

.btn-synthesis-generate:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-synthesis-generate .material-symbols-outlined {
    font-size: 20px;
}

.synthesis-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    padding: 0 4px;
}

.synthesis-char-count {
    font-size: 10px;
    color: var(--color-text-tertiary, #64748b);
}

.synthesis-privacy {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--color-text-tertiary, #64748b);
}

/* ─────────────────────────────────────────────
   Generate Button in Toolbar — Distinct styling
   ───────────────────────────────────────────── */

.btn-ai-synthesis {
    position: relative;
}

/* Subtle pulsing glow on the Generate button to draw attention */
.btn-ai-synthesis::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.15), rgba(99, 102, 241, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
    pointer-events: none;
}

.btn-ai-synthesis:hover::after {
    opacity: 1;
}

/* ─────────────────────────────────────────────
   Light Theme Overrides
   ───────────────────────────────────────────── */

[data-theme="light"] .synthesis-msg-user .synthesis-msg-content {
    background: rgba(124, 58, 237, 0.06);
    border-color: rgba(124, 58, 237, 0.12);
}

[data-theme="light"] .synthesis-msg-assistant .synthesis-msg-content {
    background: #f8fafc;
    border-color: #e2e8f0;
}

[data-theme="light"] .synthesis-input-area {
    background: #fff;
    border-top-color: #e2e8f0;
}

[data-theme="light"] .synthesis-input-wrapper {
    background: #f8fafc;
    border-color: #e2e8f0;
}

[data-theme="light"] .synthesis-textarea {
    color: #0f172a;
}

[data-theme="light"] .synthesis-preview {
    background: rgba(124, 58, 237, 0.03);
    border-color: rgba(124, 58, 237, 0.1);
}

[data-theme="light"] .synthesis-preview-stat {
    background: #f8fafc;
    border-color: #e2e8f0;
}

[data-theme="light"] .synthesis-msg-user .synthesis-msg-avatar {
    background: #e2e8f0;
    color: #334155;
}

/* ─────────────────────────────────────────────
   Responsive — Mobile (sub-768px)
   ───────────────────────────────────────────── */

@media (max-width: 768px) {
    .synthesis-modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    .synthesis-chat {
        max-height: none;
        flex: 1;
    }

    .synthesis-preview-stats {
        flex-wrap: wrap;
    }

    /* Rail table scrolls horizontally on narrow screens */
    .synthesis-rail-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* New Chat button: icon-only on mobile */
    .synthesis-new-chat-btn span:last-child {
        display: none;
    }
}

/* ─────────────────────────────────────────────
   Simulation Summary (inside chat preview card)
   ───────────────────────────────────────────── */

.synthesis-sim-summary {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Power Budget Bar ── */

.synthesis-power-bar {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.synthesis-power-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--color-text-secondary, #cbd5e1);
}

.synthesis-power-bar-track {
    height: 6px;
    border-radius: 3px;
    background: var(--color-bg-secondary, #1e293b);
    border: 1px solid var(--color-border, rgba(255,255,255,0.06));
    overflow: hidden;
}

.synthesis-power-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease-out, background 0.3s ease;
}

/* ── Rail Summary Table ── */

.synthesis-rail-table-wrapper {
    max-height: 200px;
    overflow-y: auto;
}

.synthesis-rail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.synthesis-rail-table th {
    text-align: left;
    padding: 4px 8px;
    font-weight: 600;
    font-size: 10px;
    color: var(--color-text-tertiary, #94a3b8);
    border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.08));
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.synthesis-rail-table td {
    padding: 4px 8px;
    color: var(--color-text-primary, #f1f5f9);
    border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.04));
    font-variant-numeric: tabular-nums;
}

.synthesis-rail-table tr:last-child td {
    border-bottom: none;
}

/* ── Warning Pills ── */

.synthesis-warnings-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.synthesis-warning-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
}

.synthesis-warning-pill.pill-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.synthesis-warning-pill.pill-error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ── Convergence Badge ── */

.synthesis-convergence-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    width: fit-content;
}

.synthesis-convergence-badge .material-symbols-outlined {
    font-size: 14px;
}

.synthesis-convergence-badge.convergence-pass {
    background: rgba(74, 222, 128, 0.1);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.synthesis-convergence-badge.convergence-fail {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ─────────────────────────────────────────────
   Inline SVG Preview
   ───────────────────────────────────────────── */

.synthesis-svg-preview-slot {
    margin-top: 8px;
}

.synthesis-svg-preview-slot svg {
    max-height: 200px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--color-border, rgba(255,255,255,0.08));
    background: var(--color-bg-primary, #0f172a);
    cursor: pointer;
    transition: box-shadow 0.2s ease;
}

.synthesis-svg-preview-slot svg:hover {
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.2);
}

/* Zoomed overlay within the modal */
.synthesis-svg-preview-expanded {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: pointer;
    border-radius: var(--radius-lg, 12px);
    animation: synthesisFadeIn 0.2s ease-out;
}

.synthesis-svg-preview-expanded svg {
    background: var(--color-bg-primary, #0f172a);
    border-radius: 8px;
    padding: 16px;
    border: 1px solid rgba(124, 58, 237, 0.3);
}

/* ─────────────────────────────────────────────
   LLM Reasoning Text
   ───────────────────────────────────────────── */

.synthesis-reasoning {
    font-size: 12px;
    color: var(--color-text-secondary, #cbd5e1);
    font-style: italic;
    padding: 6px 10px;
    margin: 4px 0 8px 0;
    border-left: 3px solid rgba(124, 58, 237, 0.4);
    background: rgba(124, 58, 237, 0.04);
    border-radius: 0 6px 6px 0;
}

/* ─────────────────────────────────────────────
   "New Chat" Button (Modal Header)
   ───────────────────────────────────────────── */

.synthesis-new-chat-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--color-border, rgba(255,255,255,0.12));
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-secondary, #cbd5e1);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 8px;
}

.synthesis-new-chat-btn:hover {
    border-color: #7c3aed;
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.06);
}

.synthesis-new-chat-btn .material-symbols-outlined {
    font-size: 16px;
}

/* ─────────────────────────────────────────────
   Light Theme Overrides (Phase 2 elements)
   ───────────────────────────────────────────── */

[data-theme="light"] .synthesis-power-bar-track {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

[data-theme="light"] .synthesis-rail-table th {
    color: #64748b;
    border-bottom-color: #e2e8f0;
}

[data-theme="light"] .synthesis-rail-table td {
    color: #1e293b;
    border-bottom-color: #f1f5f9;
}

[data-theme="light"] .synthesis-convergence-badge.convergence-pass {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
    color: #16a34a;
}

[data-theme="light"] .synthesis-convergence-badge.convergence-fail {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
}

[data-theme="light"] .synthesis-warning-pill.pill-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
    color: #d97706;
}

[data-theme="light"] .synthesis-warning-pill.pill-error {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
    color: #dc2626;
}

[data-theme="light"] .synthesis-reasoning {
    color: #475569;
    background: rgba(124, 58, 237, 0.03);
    border-left-color: rgba(124, 58, 237, 0.3);
}

[data-theme="light"] .synthesis-new-chat-btn {
    border-color: #e2e8f0;
    color: #64748b;
}

[data-theme="light"] .synthesis-svg-preview-slot svg {
    background: #fff;
    border-color: #e2e8f0;
}

[data-theme="light"] .synthesis-svg-preview-expanded {
    background: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] .synthesis-svg-preview-expanded svg {
    background: #fff;
    border-color: #e2e8f0;
}
