/* Base reset and globals */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #fafafa;
    color: #1a1a1a;
    line-height: 1.5;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* Chat Container */
.chat-container {
    position: fixed;
    left: 20px;
    top: 20px;
    width: min(400px, calc(100vw - 40px));
    height: min(700px, calc(100vh - 40px));
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.chat-input-container {
    padding: 20px;
    border-top: 1px solid rgba(0,0,0,0.08);
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    border-radius: 0 0 16px 16px;
    display: flex;
    gap: 12px;
}

.chat-input-container input {
    flex-grow: 1;
    padding: 12px 16px;
    border: 2px solid #eee;
    border-radius: 12px;
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
}

.chat-input-container input:focus {
    border-color: #2196f3;
    box-shadow: 0 0 0 4px rgba(33,150,243,0.1);
}

.chat-input-container button {
    padding: 12px 24px;
    background: #2196f3;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-input-container button:hover {
    background: #1976d2;
    transform: translateY(-2px);
}

/* Messages */
.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 85%;
    animation: messageAppear 0.3s ease-out;
}

.user-message {
    background: #e3f2fd;
    margin-left: auto;
    color: #1565c0;
}

.assistant-message {
    background: #f5f5f5;
    color: #333;
}

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

/* Reasoning Tree */
.reasoning-tree {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
}

.reasoning-tree svg {
    width: 100%;
    height: 100%;
}

.node {
    transition: transform 0.2s ease;
}

.node:hover {
    opacity: 0.9;
}

.node foreignObject div {
    padding: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: box-shadow 0.2s, opacity 0.2s;  /* Only transition safe properties */
}

.node:hover foreignObject div {
    box-shadow: 0 6px 24px rgba(0,0,0,0.12);
    opacity: 0.95;
}

/* Node Types */
.node-main foreignObject div { 
    background: #e3f2fd;
    border-left: 4px solid #1565c0;
}

.node-process foreignObject div {
    background: #f3e5f5;
    border-left: 4px solid #7b1fa2;
}

.node-evidence foreignObject div {
    background: #f5f5f5;
    border-left: 4px solid #616161;
}

.node-conclusion foreignObject div {
    background: #e8f5e9;
    border-left: 4px solid #2e7d32;
}

.node-child foreignObject div {
    background: #fff3e0;
    border-left: 4px solid #ef6c00;
}

.edge {
    stroke: rgba(0,0,0,0.2);
    stroke-width: 2px;
    transition: all 0.3s ease;
    cursor: pointer;
}

#end {
    fill: rgba(0,0,0,0.2);
}

.edge:hover + #end {
    fill: #2196f3;
}

.edge:hover {
    stroke: #2196f3;
    stroke-width: 3px;
    stroke-dasharray: none;
}

/* Detail View */
.detail-view {
    position: fixed;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    padding: 24px;
    width: 90vw;
    height: 85vh;
    max-height: 85vh;
    top: 7.5vh;  /* Changed from 50% to fixed value */
    left: 5vw;   /* Changed from 50% to fixed value */
    overflow-y: auto;
    z-index: 2000;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
}

.detail-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;         /* Prevent header from shrinking */
}

.detail-view-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a1a;
}

.detail-view-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #f5f5f5;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.detail-view-close:hover {
    background: #eeeeee;
}

.detail-view-content {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #333;
    flex-grow: 1;           /* Allow content to grow */
    overflow-y: auto;       /* Scroll content if needed */
    padding-right: 16px;    /* Space for scrollbar */
}

/* Controls */
.controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 16px;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    z-index: 1000;
}

.controls button {
    padding: 12px 20px;
    background: #2196f3;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.controls button:hover {
    background: #1976d2;
    transform: translateY(-2px);
}

/* Confidence Labels */
.confidence-label {
    fill: #666;
    font-size: 12px;
    font-weight: 500;
    pointer-events: none;
}

/* Loading States */
.loading-indicator {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(33,150,243,0.3);
    border-radius: 50%;
    border-top-color: #2196f3;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error States */
.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 12px 16px;
    border-radius: 12px;
    margin: 8px 0;
    border-left: 4px solid #c62828;
}

/* Alternative */

/* Floating Panel for Alternatives */
.floating-panel {
    position: fixed;
    right: 20px;
    top: 20px;
    width: 400px;
    max-height: 80vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.12);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    animation: panelSlideIn 0.3s ease-out;
}

@keyframes panelSlideIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-button {
    cursor: pointer;
    font-size: 24px;
    color: #666;
    transition: color 0.2s;
}

.close-button:hover {
    color: #333;
}

.panel-content {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 70px);
}

.alternative-item {
    padding: 16px;
    background: #f8f9fa;
    border-radius: 12px;
    margin-bottom: 16px;
    border-left: 4px solid #2196f3;
}

.alternative-item:last-child {
    margin-bottom: 0;
}

.alternative-item h4 {
    margin: 0 0 12px 0;
    color: #1976d2;
}

.alternative-item p {
    margin: 8px 0;
    color: #333;
    line-height: 1.5;
}

.probability-bar {
    height: 6px;
    background: #e3f2fd;
    border-radius: 3px;
    margin: 8px 0;
    position: relative;
    overflow: hidden;
}

.probability-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: #2196f3;
    border-radius: 3px;
    transition: width 0.3s ease-out;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 3000;
    pointer-events: none;
}

/* Loading state */
.loading-alternatives {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #666;
}

.loading-alternatives .spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2196f3;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty state */
.no-alternatives {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.no-alternatives svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    color: #999;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        position: fixed;
    left: 20px;
    top: 20px;
    width: min(400px, calc(100vw - 40px));
    height: min(700px, calc(100vh - 40px));
    }

    .controls {
        position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
        border-radius: 16px 16px 0 0;
        justify-content: center;
    }

    .detail-view {
        width: 95vw;
        height: 90vh;
        max-height: 90vh;
        top: 5vh;
        left: 2.5vw;
        border-radius: 12px;
    }

    .detail-view-content::-webkit-scrollbar {
        width: 6px;
    }
    
    .detail-view-content::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .detail-view-content::-webkit-scrollbar-thumb {
        background-color: rgba(0,0,0,0.2);
        border-radius: 3px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* Print styles */
@media print {
    .chat-container,
    .controls,
    .detail-view {
        position: static;
        box-shadow: none;
        break-inside: avoid;
    }

    .chat-input-container,
    .controls {
        display: none;
    }
}