/* ===== MODERN CSS RESET AND BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color System - Modern Professional Palette */
    --gray-1: hsl(0 0% 99%);
    --gray-2: hsl(0 0% 97.3%);
    --gray-3: hsl(0 0% 95.1%);
    --gray-4: hsl(0 0% 93%);
    --gray-5: hsl(0 0% 90.9%);
    --gray-6: hsl(0 0% 88.7%);
    --gray-7: hsl(0 0% 85.8%);
    --gray-8: hsl(0 0% 78%);
    --gray-9: hsl(0 0% 56.1%);
    --gray-10: hsl(0 0% 52.3%);
    --gray-11: hsl(0 0% 43.5%);
    --gray-12: hsl(0 0% 9%);

    /* Primary Brand Colors */
    --blue-1: hsl(206 100% 99.2%);
    --blue-2: hsl(210 100% 98%);
    --blue-3: hsl(209 100% 96.5%);
    --blue-4: hsl(210 98.8% 94%);
    --blue-5: hsl(209 95% 90.1%);
    --blue-6: hsl(209 81.2% 84.5%);
    --blue-7: hsl(208 77.5% 76.9%);
    --blue-8: hsl(206 81.9% 65.3%);
    --blue-9: hsl(206 100% 50%);
    --blue-10: hsl(208 100% 47.3%);
    --blue-11: hsl(211 100% 43.2%);
    --blue-12: hsl(211 100% 15%);

    /* Success Colors */
    --green-1: hsl(136 50% 98.9%);
    --green-2: hsl(138 62.5% 96.9%);
    --green-3: hsl(139 55.2% 94.5%);
    --green-4: hsl(140 48.7% 91%);
    --green-5: hsl(141 43.7% 86%);
    --green-6: hsl(143 40.3% 79%);
    --green-7: hsl(146 38.5% 69%);
    --green-8: hsl(151 40.2% 54.1%);
    --green-9: hsl(151 55% 41.5%);
    --green-10: hsl(152 57.5% 37.6%);
    --green-11: hsl(153 67% 28.5%);
    --green-12: hsl(155 40% 14%);

    /* Warning Colors */
    --amber-1: hsl(39 70% 99%);
    --amber-2: hsl(40 100% 96.5%);
    --amber-3: hsl(44 100% 91.7%);
    --amber-4: hsl(43 100% 86.8%);
    --amber-5: hsl(42 100% 81.8%);
    --amber-6: hsl(38 99.7% 76.3%);
    --amber-7: hsl(36 86.1% 67.1%);
    --amber-8: hsl(35 85.2% 55.1%);
    --amber-9: hsl(39 100% 57%);
    --amber-10: hsl(35 100% 55.5%);
    --amber-11: hsl(30 100% 34%);
    --amber-12: hsl(20 80% 17%);

    /* Error Colors */
    --red-1: hsl(359 100% 99.4%);
    --red-2: hsl(359 100% 98.6%);
    --red-3: hsl(360 100% 96.8%);
    --red-4: hsl(360 91.5% 94.8%);
    --red-5: hsl(360 85.1% 92.2%);
    --red-6: hsl(360 77.2% 88.7%);
    --red-7: hsl(359 75% 84%);
    --red-8: hsl(359 69.5% 78.2%);
    --red-9: hsl(358 75% 59%);
    --red-10: hsl(358 69.4% 55.2%);
    --red-11: hsl(358 65% 48.7%);
    --red-12: hsl(354 50% 14.6%);

    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-7: 1.75rem;
    --space-8: 2rem;
    --space-9: 2.25rem;
    --space-10: 2.5rem;
    --space-11: 2.75rem;
    --space-12: 3rem;

    /* Typography Scale */
    --font-size-1: 0.75rem;
    --font-size-2: 0.875rem;
    --font-size-3: 1rem;
    --font-size-4: 1.125rem;
    --font-size-5: 1.25rem;
    --font-size-6: 1.5rem;

    /* Radius Scale */
    --radius-1: 0.125rem;
    --radius-2: 0.25rem;
    --radius-3: 0.5rem;
    --radius-4: 0.75rem;
    --radius-5: 1rem;
    --radius-6: 1.5rem;

    /* Shadow Scale */
    --shadow-1: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-2: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-3: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-4: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-5: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-6: 0 25px 50px -12px rgb(0 0 0 / 0.25);

    /* Animation Easing */
    --ease-1: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-2: cubic-bezier(0.215, 0.61, 0.355, 1);
    --ease-3: cubic-bezier(0.645, 0.045, 0.355, 1);
    --ease-4: cubic-bezier(0.77, 0, 0.175, 1);

    /* Z-Index Scale */
    --z-index-1: 100;
    --z-index-2: 200;
    --z-index-3: 300;
    --z-index-4: 400;
    --z-index-5: 500;
}

html {
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-feature-settings: 'cv11', 'ss01';
    font-variation-settings: 'opsz' 32;
    background: transparent;
    color: var(--gray-12);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ===== MAIN PANEL CONTAINER ===== */
.panel-container {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr;
    background: var(--gray-1);
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    transition: all 150ms var(--ease-2);
}

.panel-container[data-state="minimized"] {
    transform: scale(0.95);
    opacity: 0.9;
}

/* Remove any default body/html margins that might cause white borders */
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.panel-container[data-state="focused"] {
    box-shadow: var(--shadow-6), 0 0 0 2px var(--blue-8);
}

/* ===== HEADER SECTION ===== */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--gray-2);
    border-bottom: 1px solid var(--gray-6);
    cursor: move;
    user-select: none;
    min-height: 44px;
    gap: var(--space-3);
}

.panel-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 500;
    font-size: var(--font-size-2);
    color: var(--gray-12);
}

.panel-title h1 {
    font-size: var(--font-size-2);
    font-weight: 500;
    margin: 0;
}

.panel-logo {
    font-size: var(--font-size-3);
}

/* Header Media Toggles (Google Meet Style) */
.header-media-toggles {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-1);
    background: var(--gray-3);
    border-radius: var(--radius-2);
    opacity: 0.6;
    transition: all 200ms var(--ease-2);
    transform: scale(0.95);
}

.panel-header:hover .header-media-toggles,
.header-media-toggles:hover,
.header-media-toggles:focus-within {
    opacity: 1;
    transform: scale(1);
}

.header-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: var(--space-1);
    border: none;
    border-radius: var(--radius-1);
    background: transparent;
    color: var(--gray-10);
    cursor: pointer;
    transition: all 150ms var(--ease-2);
}

.header-toggle-btn:hover {
    background: var(--gray-4);
    color: var(--gray-12);
    transform: scale(1.05);
}

.header-toggle-btn.active,
.header-toggle-btn[data-state="active"],
.header-toggle-btn[aria-selected="true"] {
    background: var(--blue-9);
    color: white;
    box-shadow: var(--shadow-1);
}

/* Window controls removed - PiP always fills window */

/* ===== MAIN CONTENT AREA ===== */
.panel-main {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: var(--space-2);
    padding: var(--space-2);
    overflow: hidden;
}

/* ===== MEDIA SECTION ===== */
.media-section {
    display: grid;
    gap: var(--space-2);
}

/* Legacy toggle styles (kept for compatibility) */
.toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-label {
    font-size: var(--font-size-1);
    font-weight: 500;
}

/* Media Panels */
.media-panel {
    border-radius: var(--radius-3);
    overflow: hidden;
}

.media-panel[data-state="hidden"] {
    display: none;
}

.media-panel[data-state="active"] {
    display: block;
}

/* ===== VIDEO PANEL ===== */
.video-panel {
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
}

.video-container {
    padding: var(--space-2);
}

.tavus-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--gray-3);
    border-radius: var(--radius-2);
    margin-bottom: var(--space-3);
    font-size: var(--font-size-1);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-8);
    transition: background-color 150ms var(--ease-2);
}

.status-indicator[data-status="connected"] {
    background: var(--green-9);
}

.status-indicator[data-status="connecting"] {
    background: var(--amber-9);
    animation: pulse 2s infinite;
}

.status-indicator[data-status="disconnected"] {
    background: var(--red-9);
}

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

.video-content {
    position: relative;
    background: var(--gray-12);
    border-radius: var(--radius-3);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    margin-bottom: var(--space-3);
}

/* User camera section below Tavus video */
.user-camera-section {
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
    border-radius: var(--radius-3);
    padding: var(--space-2);
    margin-bottom: var(--space-3);
}

.user-camera-section[data-state="hidden"] {
    display: none;
}

.user-camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
    color: var(--gray-11);
}

.user-camera-container {
    position: relative;
    background: var(--gray-1);
    border: 1px solid var(--gray-6);
    border-radius: var(--radius-2);
    overflow: hidden;
}

.user-camera-video {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: #000;
}

.user-camera-permission,
.user-camera-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: var(--font-size-2);
    padding: var(--space-3);
    text-align: center;
}

/* Ensure overlays truly disappear when hidden attribute is set */
.user-camera-permission[hidden],
.user-camera-error[hidden] {
    display: none !important;
}

.avatar-video-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.avatar-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-overlay {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    z-index: var(--z-index-2);
}

.user-video-pip {
    width: 80px;
    height: 60px;
    border-radius: var(--radius-2);
    overflow: hidden;
    background: var(--gray-9);
    border: 2px solid white;
    box-shadow: var(--shadow-3);
    transition: all 150ms var(--ease-2);
}

.user-video-pip[data-state="hidden"] {
    display: none;
}

.user-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-controls {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
}

.audio-controls {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-2);
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
    border-radius: var(--radius-3);
    padding: var(--space-2);
}

.audio-controls .row {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: var(--space-2);
    align-items: center;
}

.audio-controls .label {
    font-size: var(--font-size-2);
    color: var(--gray-11);
}

.audio-controls input[type="range"] {
    width: 100%;
}

.btn-compact {
    width: 28px;
    height: 28px;
    padding: 0;
}

.slider-compact {
    height: 4px;
}

.icon-muted {
    color: var(--gray-9);
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-2);
    background: var(--gray-4);
    color: var(--gray-11);
    cursor: pointer;
    transition: all 150ms var(--ease-2);
}

.control-btn:hover {
    background: var(--gray-5);
    color: var(--gray-12);
}

.control-btn[data-state="active"] {
    background: var(--blue-9);
    color: white;
}

/* ===== AUDIO PANEL ===== */
.audio-panel {
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
}

.audio-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
    gap: var(--space-4);
}

.audio-visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.audio-icon {
    color: var(--gray-8);
}

.audio-waves {
    display: flex;
    gap: var(--space-1);
    align-items: end;
    height: 24px;
}

.wave {
    width: 3px;
    background: var(--gray-7);
    border-radius: var(--radius-1);
    animation: wave 1.5s ease-in-out infinite;
    transform-origin: bottom;
}

@keyframes wave {
    0%, 100% { height: 4px; }
    50% { height: 20px; }
}

.audio-status h3 {
    font-size: var(--font-size-3);
    font-weight: 500;
    color: var(--gray-12);
    margin-bottom: var(--space-1);
}

.audio-status p {
    font-size: var(--font-size-2);
    color: var(--gray-9);
}

/* ===== TEXT PANEL ===== */
.text-panel {
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
}

.text-mode-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3);
    color: var(--gray-9);
    font-size: var(--font-size-2);
    font-weight: 500;
}

/* ===== CHAT SECTION ===== */
.chat-section {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: var(--space-3);
    min-height: 0;
}

/* Legacy chat toggle styles removed - now using inline chat toggles */

/* Chat Panels */
.chat-panel {
    border-radius: var(--radius-3);
    overflow: hidden;
    min-height: 0;
}

.chat-panel[data-state="hidden"] {
    display: none;
}

.chat-panel[data-state="active"] {
    display: grid;
}

/* ===== EXPANDED CHAT PANEL ===== */
.chat-expanded-panel {
    display: grid;
    grid-template-rows: 1fr auto;
    gap: var(--space-3);
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
    min-height: 0;
}

.messages-container {
    overflow: hidden;
    min-height: 200px;
    flex: 1;
}

.messages-scroll {
    height: 100%;
    overflow-y: auto;
    padding: var(--space-2);
    scrollbar-width: thin;
    scrollbar-color: var(--gray-7) transparent;
    position: relative;
}

/* Chat toggle is now in header - no overlay needed */

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

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

.messages-scroll::-webkit-scrollbar-thumb {
    background: var(--gray-7);
    border-radius: var(--radius-6);
}

.welcome-message {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-6);
    background: var(--blue-3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-3);
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    min-width: 0;
}

/* Input text (typing) contrast */
.message-textarea {
    color: #111 !important;
    background: #fff;
}
.message-textarea::placeholder {
    color: #666;
}

.message-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.message-sender {
    font-size: var(--font-size-1);
    font-weight: 600;
    color: var(--gray-12);
}

.message-time {
    font-size: var(--font-size-1);
    color: var(--gray-9);
}

.message-text h3 {
    font-size: var(--font-size-3);
    font-weight: 500;
    color: var(--gray-12);
    margin-bottom: var(--space-2);
}

.message-text p {
    font-size: var(--font-size-2);
    line-height: 1.5;
    color: var(--gray-11);
}

/* ===== INPUT AREA ===== */
.input-container {
    padding: var(--space-2);
    border-top: 1px solid var(--gray-6);
    background: var(--gray-1);
}

.input-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--space-2);
}

.chat-toggle-group-inline {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-1);
    background: var(--gray-3);
    border-radius: var(--radius-2);
    opacity: 0.7;
    transition: all 150ms var(--ease-2);
}

.chat-toggle-group-inline:hover,
.chat-toggle-group-inline:focus-within {
    opacity: 1;
    transform: scale(1.02);
}

.chat-toggle-btn-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: var(--space-1);
    border: none;
    border-radius: var(--radius-1);
    background: transparent;
    color: var(--gray-8);
    cursor: pointer;
    transition: all 150ms var(--ease-2);
}

.chat-toggle-btn-inline:hover {
    background: var(--gray-4);
    color: var(--gray-12);
    transform: scale(1.05);
}

.chat-toggle-btn-inline.active,
.chat-toggle-btn-inline[data-state="active"],
.chat-toggle-btn-inline[aria-selected="true"] {
    background: var(--blue-9);
    color: white;
    box-shadow: var(--shadow-1);
}

.input-field-container {
    position: relative;
}

.textarea-container {
    position: relative;
    border: 1px solid var(--gray-6);
    border-radius: var(--radius-3);
    background: white;
    transition: border-color 150ms var(--ease-2);
}

.textarea-container:focus-within {
    border-color: var(--blue-8);
    box-shadow: 0 0 0 2px var(--blue-3);
}

.message-textarea {
    width: 100%;
    border: none;
    padding: var(--space-3);
    padding-right: 80px;
    font-family: inherit;
    font-size: var(--font-size-2);
    line-height: 1.4;
    resize: none;
    outline: none;
    background: transparent;
    color: var(--gray-12);
}

.message-textarea::placeholder {
    color: var(--gray-9);
}

.textarea-actions {
    position: absolute;
    right: var(--space-2);
    bottom: var(--space-2);
    display: flex;
    gap: var(--space-1);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-2);
    background: var(--gray-4);
    color: var(--gray-9);
    cursor: pointer;
    transition: all 150ms var(--ease-2);
}

.action-btn:hover {
    background: var(--gray-5);
    color: var(--gray-12);
}

.send-btn:hover {
    background: var(--blue-9);
    color: white;
}

/* ===== MINIMIZED CHAT PANEL ===== */
.chat-minimized-panel {
    background: var(--gray-2);
    border: 1px solid var(--gray-6);
}

.minimized-chat-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
    color: var(--gray-9);
    font-size: var(--font-size-2);
    font-weight: 500;
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 150ms var(--ease-2);
    border-radius: var(--radius-3);
}

.minimized-chat-indicator.clickable:hover {
    background: var(--gray-3);
    color: var(--gray-12);
    transform: translateY(-1px);
    box-shadow: var(--shadow-2);
}

.minimized-chat-indicator.clickable:active {
    transform: translateY(0);
    box-shadow: var(--shadow-1);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 350px) {
    .panel-main {
        padding: var(--space-3);
        gap: var(--space-2);
    }
    
    .media-toggle-btn,
    .chat-toggle-btn {
        padding: var(--space-1) var(--space-2);
        font-size: var(--font-size-1);
    }
    
    .toggle-label {
        display: none;
    }
    
    .video-content {
        aspect-ratio: 4 / 3;
    }
    
    .user-video-pip {
        width: 60px;
        height: 45px;
    }
}

@media (max-height: 400px) {
    .panel-main {
        grid-template-rows: auto 1fr;
        gap: var(--space-2);
    }
    
    .audio-container {
        padding: var(--space-4);
    }
    
    .messages-scroll {
        padding: var(--space-3);
    }
}

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

@media (prefers-color-scheme: dark) {
    :root {
        --gray-1: hsl(0 0% 8.5%);
        --gray-2: hsl(0 0% 11%);
        --gray-3: hsl(0 0% 13.6%);
        --gray-4: hsl(0 0% 15.8%);
        --gray-5: hsl(0 0% 17.9%);
        --gray-6: hsl(0 0% 20.5%);
        --gray-7: hsl(0 0% 24.3%);
        --gray-8: hsl(0 0% 31.2%);
        --gray-9: hsl(0 0% 43.9%);
        --gray-10: hsl(0 0% 49.4%);
        --gray-11: hsl(0 0% 62.8%);
        --gray-12: hsl(0 0% 93%);
    }
}

/* ===== FOCUS MANAGEMENT ===== */
button:focus-visible {
    outline: 2px solid var(--blue-8);
    outline-offset: 2px;
}

textarea:focus-visible {
    outline: none;
}

/* ===== LOADING STATES ===== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--gray-6);
    border-top-color: var(--blue-9);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===== DOCUMENT PICTURE-IN-PICTURE SPECIFIC STYLES ===== */
/* These styles ensure the PiP window floats above all other content */

/* Document PiP Mode Detection and Styling */
/* PiP-specific styles removed (side panel only) */