/* ==================== PLATFORM STUDIO & CODEBOT DUAL LAYOUT ==================== */

/* Container */
.studio-container,
.codebot-dual-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

/* Override tab-content auto scroll — Studio handles its own scroll internally */
#tab-platform-studio.active,
#tab-codebot.active {
    overflow-y: hidden;
}

/* When Studio is visible, constrain main-content to viewport height (no outer scroll) */
.main-content:has(#tab-platform-studio.active),
.main-content:has(#tab-codebot.active) {
    overflow-y: hidden;
}

.codebot-dual-container > h2 {
    margin: 0;
    padding: 1rem 1.25rem 0.25rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.codebot-dual-container > .text-muted {
    padding: 0 1.25rem 0.75rem;
    font-size: 0.8rem;
    margin: 0;
    border-bottom: 1px solid var(--border-color, #334155);
}

/* Dual pane: main chat + sidebar */
.cb-dual-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Main chat area */
.cb-dual-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cb-dual-main .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: calc(100vh - 180px);  /* fallback: viewport minus header+tabs+input */
}

/* Input area (used by both CodeBot & Platform Studio) */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color, #334155);
    background: var(--bg-primary, #0f172a);
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    resize: none;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid var(--border-color, #334155);
    background: var(--bg-input, #1e293b);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    min-height: 38px;
    max-height: 120px;
    overflow-y: auto;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.chat-input-area textarea::placeholder {
    color: var(--text-secondary, #94a3b8);
}

.chat-input-area .btn-primary {
    padding: 0.6rem 1.25rem;
    white-space: nowrap;
    flex-shrink: 0;
    align-self: flex-end;
}

/* Sidebar */
.cb-dual-sidebar {
    width: 260px;
    border-left: 1px solid var(--border-color, #334155);
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--bg-secondary, #1e293b);
    flex-shrink: 0;
}

.cb-dual-sidebar h4 {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cb-dual-sidebar .session-list {
    min-height: 2rem;
}

.cb-dual-sidebar .btn-secondary {
    width: 100%;
    text-align: center;
}

.cb-dual-sidebar .btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
}

.cb-dual-sidebar hr {
    margin: 0.75rem 0;
    border: none;
    border-top: 1px solid var(--border-color, #334155);
}

.cb-dual-sidebar pre {
    font-size: 0.7rem;
    background: var(--bg-primary, #0f172a);
    padding: 0.5rem;
    border-radius: var(--radius-sm, 6px);
    overflow: auto;
    max-height: 300px;
    margin: 0.5rem 0 0;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-secondary, #94a3b8);
    line-height: 1.4;
}

/* Attachment button */
.ps-attach-btn {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border-color, #334155);
    border-radius: var(--radius-sm, 6px);
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}

.ps-attach-btn:hover {
    color: var(--accent-primary, #3b82f6);
    border-color: var(--accent-primary, #3b82f6);
}

/* Attachment preview bar */
.ps-attachment-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1.25rem;
    background: var(--bg-secondary, #1e293b);
    border-top: 1px solid var(--border-color, #334155);
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
}

.ps-attachment-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ps-attachment-name::before {
    content: "\1F4CE ";
}

.ps-attachment-remove {
    background: none;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.ps-attachment-remove:hover {
    color: var(--danger, #ef4444);
}

/* Tool activity status */
.ps-tool-status {
    margin-top: 0.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
    color: var(--accent-primary, #3b82f6);
    background: rgba(59, 130, 246, 0.08);
    border-left: 2px solid var(--accent-primary, #3b82f6);
    border-radius: 0 var(--radius-sm, 4px) var(--radius-sm, 4px) 0;
    animation: ps-pulse 1.5s ease-in-out infinite;
}

@keyframes ps-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Platform: real-time tool call blocks */
.ps-tool-block {
    margin: 0.5rem 0;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius-sm, 4px);
    background: var(--bg-secondary, #f8fafc);
    font-size: 0.82rem;
}
.ps-tool-header {
    padding: 0.35rem 0.6rem;
    cursor: pointer;
    color: var(--text-secondary, #64748b);
    user-select: none;
}
.ps-tool-header strong {
    color: var(--text-primary, #1e293b);
    margin-right: 0.3rem;
}
.ps-tool-code, .ps-tool-result-code {
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    line-height: 1.4;
    max-height: 300px;
    overflow: auto;
    background: var(--bg-primary, #fff);
    border-top: 1px solid var(--border, #e2e8f0);
    white-space: pre-wrap;
    word-break: break-all;
}
.ps-tool-result-code {
    background: #f0fdf4;
    border-top: 1px dashed #86efac;
    color: #166534;
    max-height: 200px;
}
.ps-tool-call { border-left: 3px solid var(--accent-primary, #3b82f6); }
.ps-tool-truncated {
    color: var(--text-secondary, #94a3b8);
    font-style: italic;
    font-size: 0.7rem;
    margin-top: 0.25rem;
}

/* Project selector */
.ps-project-selector {
    padding: 1rem;
    background: var(--bg-secondary, #f8fafc);
    border-radius: var(--radius-sm, 4px);
    border: 1px solid var(--border, #e2e8f0);
}

.ps-project-selector p { margin: 0 0 0.75rem; }

.ps-project-list { margin-bottom: 0.75rem; }

.ps-project-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border, #e2e8f0);
    cursor: pointer;
    transition: background 0.1s;
}

.ps-project-row:hover {
    background: rgba(59, 130, 246, 0.06);
}

.ps-project-title {
    font-weight: 500;
    font-size: 0.88rem;
}

.ps-project-meta {
    font-size: 0.75rem;
    color: var(--text-secondary, #64748b);
}

/* Sandbox banner & buttons */
.ps-sandbox-banner {
    padding: 0.5rem 1rem;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm, 4px);
    font-size: 0.82rem;
    color: var(--text-primary, #1e293b);
    margin-bottom: 0.5rem;
}

.ps-sandbox-banner span {
    font-weight: 600;
    color: #d97706;
}

.ps-sandbox-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius-sm, 4px);
    background: var(--bg-primary, #fff);
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    margin-left: 0.3rem;
    transition: all 0.15s;
}

.ps-sandbox-btn:hover {
    background: var(--bg-tertiary, #f1f5f9);
}

.ps-sandbox-deploy {
    color: #059669;
    border-color: #059669;
}

.ps-sandbox-deploy:hover {
    background: rgba(5, 150, 105, 0.1);
}

.ps-sandbox-rollback {
    color: #dc2626;
    border-color: #dc2626;
}

.ps-sandbox-rollback:hover {
    background: rgba(220, 38, 38, 0.1);
}

/* File explorer panel */
.ps-file-explorer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-secondary, #1e293b);
    border-left: 1px solid var(--border-color, #334155);
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
}

.ps-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color, #334155);
    font-weight: 600;
    font-size: 0.85rem;
}

.ps-panel-close {
    background: none;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
}

.ps-panel-close:hover {
    color: var(--danger, #ef4444);
}

.ps-file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.ps-file-item {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.1s;
}

.ps-file-item:hover {
    background: rgba(59, 130, 246, 0.08);
}

.ps-file-dir {
    font-weight: 500;
}

.ps-file-file {
    color: var(--text-secondary, #94a3b8);
}

/* Diff panel (bottom) */
.ps-diff-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 250px;
    background: var(--bg-secondary, #1e293b);
    border-top: 2px solid var(--accent-primary, #3b82f6);
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
}

.ps-diff-content {
    flex: 1;
    overflow: auto;
    padding: 0.5rem;
    font-size: 0.78rem;
}

.ps-diff-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.ps-diff-file {
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 500;
}

.ps-diff-modified { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.ps-diff-added { background: rgba(5, 150, 105, 0.15); color: #059669; }
.ps-diff-deleted { background: rgba(220, 38, 38, 0.15); color: #dc2626; }

.ps-diff-code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.72rem;
    line-height: 1.4;
    white-space: pre;
    margin: 0;
    padding: 0.5rem;
    background: var(--bg-primary, #0f172a);
    border-radius: 4px;
    overflow: auto;
}

.ps-diff-add { color: #059669; }
.ps-diff-del { color: #dc2626; }
.ps-diff-hunk { color: #3b82f6; font-weight: 600; }

/* Deploy consent modal */
.ps-consent-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.ps-consent-modal {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 520px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.ps-consent-modal h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
}

.ps-consent-warning {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.ps-consent-warning strong {
    color: #d97706;
    display: block;
    margin-bottom: 0.4rem;
}

.ps-consent-warning p {
    margin: 0;
    line-height: 1.5;
}

.ps-consent-box {
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.ps-consent-box label {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    font-size: 0.82rem;
    line-height: 1.5;
    cursor: pointer;
}

.ps-consent-box input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
}

.ps-consent-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.ps-consent-actions .ps-sandbox-deploy:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 900px) {
    .cb-dual-layout {
        flex-direction: column;
    }
    .cb-dual-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color, #334155);
        max-height: 200px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    .cb-dual-sidebar h4 { width: 100%; }
}

/* ── Verification & Confidence ── */
.ps-confidence-line {
    margin-top: 10px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    background: rgba(46,204,113,0.08);
    border: 1px solid rgba(46,204,113,0.2);
    color: #2ecc71;
}
.ps-verification-warning {
    margin-top: 10px;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    background: rgba(231,76,60,0.08);
    border: 1px solid rgba(231,76,60,0.3);
    color: #e74c3c;
}
.ps-verification-warning ul {
    margin: 4px 0 0 16px;
    padding: 0;
    font-size: 11px;
}
.ps-verification-warning .ps-vw-icon {
    margin-right: 4px;
}
.ps-dual-coder {
    margin-top: 6px;
    padding: 6px 12px;
    font-size: 11px;
    border-radius: 6px;
}
.ps-dc-ok {
    background: rgba(52,152,219,0.08);
    border: 1px solid rgba(52,152,219,0.2);
    color: #3498db;
}
.ps-dc-warn {
    background: rgba(243,156,18,0.08);
    border: 1px solid rgba(243,156,18,0.3);
    color: #f39c12;
}
.ps-dc-icon { margin-right: 4px; }
