/* ============================================================
   PBL Roundtable Styles
   Extracted from style.css without selector renames.
   ============================================================ */

/* --- NEW: PBL Roundtable Visualization Styles (from pbl_table_sample.html) --- */
@keyframes dot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}


/* --- PBL Avatar Colors --- */
/* Color palette with high contrast and accessibility */
/* Added more variables from sample for roundtable */

/* Base style for SVG icons in avatars, moved from index.html */
.avatar svg {
    width: 20px;
    height: 20px;
    color: #333; /* Default dark color, good for patient avatar */
}

/* White icon for user avatar, moved from index.html */
.user-row .avatar svg {
    color: white;
}

/* White icon for all PBL participants */
.avatar.facilitator svg,
.avatar.patient svg,
.avatar[class*="student_"] svg {
    color: white;
}

.avatar.facilitator {
    background-color: var(--avatar-facilitator);
    color: white;
}

.avatar.patient {
    background-color: var(--avatar-patient);
    color: white;
}

.avatar.student_a { background-color: var(--avatar-student-1); color: white; }
.avatar.student_b { background-color: var(--avatar-student-2); color: white; }
.avatar.student_c { background-color: var(--avatar-student-3); color: white; }
.avatar.student_d { background-color: var(--avatar-student-4); color: white; }
.avatar.student_e { background-color: var(--avatar-student-5); color: white; }
.avatar.student_f { background-color: var(--avatar-student-6); color: white; }
.avatar.student_g { background-color: var(--avatar-student-7); color: white; }
.avatar.student_h { background-color: var(--avatar-student-8); color: white; }
.avatar.student_i { background-color: var(--avatar-student-9); color: white; }
.avatar.student_j { background-color: var(--avatar-student-10); color: white; }
.avatar.student_k { background-color: var(--avatar-student-11); color: white; }
.avatar.student_l { background-color: var(--avatar-student-12); color: white; }

/* Fallback for any additional students beyond predefined colors */
.avatar[class*="student_"]:not(.student_a):not(.student_b):not(.student_c):not(.student_d):not(.student_e):not(.student_f):not(.student_g):not(.student_h):not(.student_i):not(.student_j):not(.student_k):not(.student_l) {
    background-color: #95a5a6; /* Gray fallback */
    color: white;
}

/* Mention Tag style inside the contenteditable input */
.mention-tag {
    background-color: #e0eaff; /* A light blue */
    color: #0056b3; /* A darker blue for text */
    padding: 2px 6px;
    border-radius: 12px; /* Pill shape */
    font-weight: 500;
    font-size: 0.95em;
    display: inline-block; /* Allows padding and border-radius */
    margin: 0 1px;
}

/* Container for the roundtable visualization */
#pbl-roundtable-container {
    position: relative;
    overflow: hidden;
    padding-top: 5rem;
    background-color: #f8f9f8; /* Match sample bg */
    /* Add container query support for speech bubbles */
    container-type: inline-size;
    container-name: roundtable;
    height: 100%; /* Fill the tab content area */
    width: 100%;
}

.pbl-environment {
    width: 100%;
    height: 100%; /* Fill the container */
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.virtual-table {
    /* Make the table responsive to the container size */
    width: 40vmin;
    height: 40vmin;
    min-width: 300px;
    min-height: 300px;
    max-width: 550px;
    max-height: 550px;
    background: var(--table-color);
    border-radius: 50%;
    box-shadow: 0 5px 25px rgba(0,0,0,0.05), inset 0 0 10px rgba(0,0,0,0.05);
    position: relative;
}

.character-rig {
    position: absolute;
    /* Give the rig a fixed size so that its children (speech bubble) can overflow
       without affecting the rig's own dimensions and position. */
    width: 120px;
    height: 120px;
    transform: translate(-50%, -50%); /* Center the rig on its coordinates */
    /* top and left will be set by JS */
    pointer-events: none; /* Allow clicks to pass through the rig's empty space */
    /* Ensure speech bubbles don't interfere with other elements */
    z-index: 1;
}

.character {
    width: 100%; /* Ensure the grid container fills the rig for proper centering */
    position: relative;
    display: grid; /* Use grid for simpler vertical stacking and centering */
    justify-items: center; /* Horizontally center all items in the grid */
    gap: 4px; /* Space between icon and name */
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease;    
    opacity: 0.2; /* Make inactive speakers even more subtle */
    pointer-events: auto; /* Re-enable pointer events for the character content */
}

.character.active {
    transform: scale(1.1) translateY(-10px);
    opacity: 1;
    z-index: 100;
}

.icon-wrapper {
    /* Make icons responsive */
    width: 5.5vmin;
    height: 5.5vmin;
    min-width: 40px;
    min-height: 40px;
    max-width: 60px;
    max-height: 60px;
    transition: filter 0.4s ease, width 0.4s ease, height 0.4s ease;
}

.person-icon {
    width: 100%;
    height: 100%;
    fill: var(--icon-color);
    transition: fill 0.4s ease;
    filter: grayscale(0.3) brightness(0.8); /* Subtle muting for inactive icons */
}

.character.active .person-icon { 
    fill: var(--glow-color); 
    filter: none; /* Remove muting filter when active */
}
.character.active .icon-wrapper { filter: drop-shadow(0 0 12px var(--glow-color)); }
.character.active .character-name { 
    font-weight: 600; /* Bold when active */
    font-size: 0.9em; /* Normal size when active */
    opacity: 1; /* Full opacity when active */
}

.character-name {
    color: var(--text-color);
    font-weight: 500; /* Lighter font weight for inactive state */
    font-size: 0.9em; /* Slightly smaller text */
    transition: font-weight 0.4s ease, font-size 0.4s ease;
    opacity: 0.7; /* Additional opacity reduction for names */
    text-align: center; /* Ensure text is centered, especially for multi-line names */
}

/* Special styling for facilitator */
#rig-facilitator .icon-wrapper {
    width: 6.5vmin;
    height: 6.5vmin;
    min-width: 50px;
    min-height: 50px;
    max-width: 70px;
    max-height: 70px;
}

/* Style to distinguish the user's character on the roundtable */
.character.user-character .person-icon {
    fill: var(--primary-color);
}
.character.user-character .character-name {
    color: var(--primary-color);
}

/* Style for patient character on the roundtable */
.character.patient-character .person-icon {
    fill: var(--avatar-patient);
}
.character.patient-character .character-name {
    color: var(--avatar-patient);
}
.character.patient-character .speech-bubble {
    background-color: #fff5f8;
}
.character.patient-character .speech-bubble::after {
    border-top-color: #fff5f8;
}
.character.patient-character .typing-indicator span {
    background-color: var(--avatar-patient);
}
/* Keep patient color when active */
.character.patient-character.active .person-icon {
    fill: var(--avatar-patient);
}
.character.patient-character.active .icon-wrapper {
    filter: drop-shadow(0 0 12px var(--avatar-patient));
}

/* Make user's speech bubble font and typing indicator blue */
.character.user-character .speech-bubble {
    background-color: var(--speech-bubble-bg); /* Revert to default bubble color */
    color: #004085; /* A clearer, less dark navy blue */
    border: none; /* Remove border for consistency with other bubbles */
}

.character.user-character .speech-bubble::after {
    border-top-color: var(--speech-bubble-bg); /* Match the new bubble's background */
}
.character.user-character .typing-indicator span {
    background-color: var(--primary-color);
}

.character-rig.user-typing {
    z-index: 100; /* Bring user to front when typing or using STT */
}

.speech-bubble {
    position: absolute;
    /* Position above the character icon dynamically */
    bottom: 100%;
    margin-bottom: 5px;
    transform-origin: bottom center; /* Make it scale from the center */
    /* Responsive width that adapts to roundtable container size - wider to reduce line wrapping */
    min-width: 80px;
    max-width: min(400px, 35vw, 50vmin);
    background: var(--speech-bubble-bg);
    color: var(--speech-bubble-text);
    border: 1px solid var(--table-color);
    padding: 2px 12px; /* Reduced top/bottom padding */
    border-radius: 12px;
    font-size: 0.95em;
    line-height: 1.5;
    opacity: 0;
    visibility: hidden;
    transform: translateY(5px) scale(1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), 
                box-shadow 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
                opacity 0.4s ease, 
                visibility 0.4s,
                max-width 0.3s ease;
    /* Use max-content to force the bubble to be as wide as its text, up to max-width. */
    width: max-content;
    z-index: 10; /* Ensure bubble is above the icon wrapper */
    text-align: left; /* Ensure text inside is left-aligned */
    /* Ensure content wraps properly and doesn't break layout */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.speech-bubble.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1.05);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    /* Position the tail at the bottom-center */
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: var(--speech-bubble-bg) transparent transparent transparent;
}

/* Special positioning for facilitator's bubble */
#rig-facilitator .speech-bubble {
    bottom: auto;
    top: 0;
    left: 100%;
    margin-left: 10px; /* Space from icon */
    transform-origin: left center;
    /* Facilitator needs wider bubbles but still constrained to container */
    max-width: min(480px, 40vw, 60vmin);
    /* The transform itself is handled by JS to combine centering and overflow prevention */
}
#rig-facilitator .speech-bubble::after {
    top: 50%;
    left: -10px; /* Position on the left edge of the bubble, pointing left */
    bottom: auto;
    transform: translateY(-50%);
    border-width: 10px 10px 10px 0;
    border-style: solid;
    border-color: transparent var(--speech-bubble-bg) transparent transparent;
}

/* Special positioning for scriber's bubble - wider for longer outputs */
#rig-scriber .speech-bubble {
    /* Scriber needs much wider bubbles for documentation outputs - double the default */
    max-width: min(800px, 70vw, 100vmin);
}

/* Constrain the content inside scriber's bubble with scrollbar for long content */
#rig-scriber .speech-bubble-content {
    max-height: 40vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.typing-indicator {
    position: absolute;
    /* Position above the character icon dynamically */
    bottom: 100%;
    margin-bottom: 5px;
    display: flex;
    gap: 5px;
    align-items: center;
    background: var(--table-color);
    padding: 10px 15px;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, bottom 0.3s, left 0.3s, margin-bottom 0.3s, margin-left 0.3s;
}
.typing-indicator.visible { opacity: 1; visibility: visible; }

/* When speech bubble is visible, move typing indicator to the right of the character */
.character:has(.speech-bubble.visible) .typing-indicator {
    bottom: 50%;
    left: 100%;
    margin-left: 10px;
    margin-bottom: 0;
    transform: translateY(50%);
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--icon-color);
    border-radius: 50%;
}
.typing-indicator span:nth-child(1) { animation: dot-bounce 1.2s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation: dot-bounce 1.2s infinite ease-in-out 0.2s; }
.typing-indicator span:nth-child(3) { animation: dot-bounce 1.2s infinite ease-in-out 0.4s; }


/* --- Pin Board Styles (from sample) --- */

/* --- STYLISH THUMBTACK PIN BUTTON --- */
.pin-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    z-index: 10;
}

/* Always show pin button when in PBL mode */
#chat-panel.pbl-layout-active .message-row .pin-button {
    opacity: 1;
    transform: scale(1);
}

/* Always show pin button on visible speech bubbles */
.speech-bubble.visible .pin-button {
    opacity: 1;
    transform: scale(1);
}

/* Enhanced hover effects for pin buttons */
#chat-panel.pbl-layout-active .message-row:hover .pin-button,
.speech-bubble.visible:hover .pin-button {
    opacity: 1;
    transform: scale(1.1);
}

/* The thumbtack icon created with pseudo-elements */
.pin-button::before { /* The head */
    content: '';
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background-color: #a0a0a0;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.pin-button::after { /* The pin */
    content: '';
    position: absolute;
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 9px;
    background-color: #a0a0a0;
    border-radius: 1px;
    transition: all 0.2s ease;
}

.pin-button:hover::before,
.pin-button:hover::after {
    background-color: var(--primary-color);
}
.pin-button:hover {
    transform: scale(1.1);
}

/* --- Board Styling --- */
.evidence-panel-content {
    flex-grow: 1;
    position: relative;
    padding: 0;
}

.glass-board {
    width: 100%;
    height: 100%;
    min-height: 300px;
    position: relative;
    border-radius: 12px;
    border: 1px solid var(--board-border-color);
    background-color: var(--board-bg-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.07);
}

.board-content {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    overflow: auto;
    background-image: radial-gradient(var(--dot-color) 0.5px, transparent 0.5px);
    background-size: 20px 20px;
}

/* Mounting hardware effect */
.glass-board::before, .glass-board::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: #d1d5db;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.8);
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    z-index: 1;
}
.glass-board::before { top: 15px; left: 15px; }
.glass-board::after { top: 15px; right: 15px; }

.evidence-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    width: 260px;
    position: absolute;
    cursor: grab;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 0 0 1px transparent, 0 5px 15px rgba(0,0,0,0.07);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--card-border);
    font-weight: 600;
    font-size: 13px;
    color: #374151;
    gap: 8px;
}

.card-header .avatar {
    width: 24px;
    height: 24px;
}
.card-header .avatar svg {
    width: 14px;
    height: 14px;
}

.card-content {
    padding: 12px;
    font-size: 14px;
    line-height: 1.6;
    color: #1a1a1a;
    flex-grow: 1;
}

.unpin-button {
    position: absolute;
    top: 6px;
    right: 6px;
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    color: #999;
    cursor: pointer;
    font-size: 20px;
    opacity: 0.5;
    transition: all 0.2s ease;
    z-index: 5;
}

.evidence-card:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 0 0 1px var(--primary-color), 0 8px 25px rgba(0,0,0,0.1);
}

.evidence-card:hover .unpin-button {
    opacity: 1;
    color: var(--primary-color);
}

.evidence-card:active {
    cursor: grabbing;
    z-index: 1000;
}

/* Fallback responsive design for browsers without container query support */
@supports not (container-type: inline-size) {
    @media (max-width: 800px) {
        .speech-bubble {
            max-width: min(320px, 30vw, 45vmin);
            font-size: 0.95em;
            padding: 14px;
        }
        #rig-facilitator .speech-bubble {
            max-width: min(380px, 35vw, 50vmin);
        }
        #rig-scriber .speech-bubble {
            max-width: min(640px, 60vw, 90vmin);
        }
        #rig-scriber .speech-bubble-content {
            max-height: 40vh;
            overflow-y: auto;
            overflow-x: hidden;
        }
    }
    
    @media (max-width: 600px) {
        .speech-bubble {
            max-width: min(280px, 28vw, 40vmin);
            font-size: 0.9em;
            padding: 12px;
            line-height: 1.4;
        }
        #rig-facilitator .speech-bubble {
            max-width: min(320px, 32vw, 45vmin);
        }
        #rig-scriber .speech-bubble {
            max-width: min(560px, 56vw, 80vmin);
        }
        #rig-scriber .speech-bubble-content {
            max-height: 40vh;
            overflow-y: auto;
            overflow-x: hidden;
        }
    }
    
    @media (max-width: 400px) {
        .speech-bubble {
            max-width: min(240px, 25vw, 35vmin);
            font-size: 0.85em;
            padding: 10px;
        }
        #rig-facilitator .speech-bubble {
            max-width: min(280px, 30vw, 40vmin);
        }
        #rig-scriber .speech-bubble {
            max-width: min(480px, 50vw, 70vmin);
        }
        #rig-scriber .speech-bubble-content {
            max-height: 40vh;
            overflow-y: auto;
            overflow-x: hidden;
        }
    }
}

/* Container queries for better responsive speech bubble sizing */
@container roundtable (max-width: 800px) {
    .speech-bubble {
        max-width: min(320px, 30vw, 45vmin);
        font-size: 0.95em;
        padding: 14px;
    }
    
    #rig-facilitator .speech-bubble {
        max-width: min(380px, 35vw, 50vmin);
    }
    
    #rig-scriber .speech-bubble {
        max-width: min(640px, 60vw, 90vmin);
    }
    
    #rig-scriber .speech-bubble-content {
        max-height: 40vh;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

@container roundtable (max-width: 600px) {
    .speech-bubble {
        max-width: min(280px, 28vw, 40vmin);
        font-size: 0.9em;
        padding: 12px;
        line-height: 1.4;
    }
    
    #rig-facilitator .speech-bubble {
        max-width: min(320px, 32vw, 45vmin);
    }
    
    #rig-scriber .speech-bubble {
        max-width: min(560px, 56vw, 80vmin);
    }
    
    #rig-scriber .speech-bubble-content {
        max-height: 40vh;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

@container roundtable (max-width: 400px) {
    .speech-bubble {
        max-width: min(240px, 25vw, 35vmin);
        font-size: 0.85em;
        padding: 10px;
    }
    
    #rig-facilitator .speech-bubble {
        max-width: min(280px, 30vw, 40vmin);
    }
    
    #rig-scriber .speech-bubble {
        max-width: min(480px, 50vw, 70vmin);
    }
    
    #rig-scriber .speech-bubble-content {
        max-height: 40vh;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
}

.speech-bubble .pin-button {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 15;
    /* Add thumbtack icon styles here if needed */
}

.speech-bubble-content {
    padding-right: 30px; /* Increased right padding to accommodate pin and voice icons */
}
