/* Video Call Overlay */
.videocall-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #1a1a2e;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
}

/* Docked Mode */
.videocall-overlay.videocall-docked {
    width: 300px;
    height: 50vh;
    border-radius: 0 12px 0 0;
    resize: both;
    overflow: hidden;
    min-width: 260px;
    min-height: 200px;
    max-width: 50vw;
    max-height: 80vh;
    box-shadow: 4px -4px 20px rgba(0, 0, 0, 0.4);
}

.videocall-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    height: 48px;
    flex-shrink: 0;
}

.videocall-header .call-timer {
    font-size: 14px;
    font-family: 'Roboto Mono', monospace;
    color: rgba(255, 255, 255, 0.8);
}

.videocall-header .call-title {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60vw;
}

.videocall-header .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-toggle-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 14px;
    transition: background 0.2s ease;
}

.mode-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Docked header adjustments */
.videocall-docked .videocall-header {
    padding: 4px 8px;
    height: 36px;
}

.videocall-docked .videocall-header .call-title {
    font-size: 12px;
    max-width: 120px;
}

.videocall-docked .videocall-header .call-timer {
    font-size: 11px;
}

/* Grid Docked */
.video-grid.grid-docked {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.video-grid.grid-docked .video-cell.local-video {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 80px;
    height: 60px;
    z-index: 10;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
}

.video-grid.grid-docked .video-cell:not(.local-video) ~ .video-cell:not(.local-video) {
    display: none;
}

.video-grid.grid-docked .video-cell {
    border-radius: 8px;
}

.video-grid.grid-docked .video-cell .video-label {
    font-size: 10px;
    padding: 2px 6px;
    bottom: 4px;
    left: 4px;
}

.video-grid.grid-docked .video-cell .no-video-placeholder .avatar-circle {
    width: 48px;
    height: 48px;
    font-size: 20px;
}

/* Call Controls Compact */
.call-controls.call-controls-compact {
    padding: 6px;
    gap: 6px;
}

.call-controls.call-controls-compact .control-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
}

.call-controls.call-controls-compact .control-btn.end-call {
    width: 38px;
    height: 38px;
}

.videocall-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.videocall-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 0;
}

/* Video Grid */
.video-grid {
    display: grid;
    gap: 8px;
    width: 100%;
    height: 100%;
    padding: 4px;
}

.video-grid.grid-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.video-grid.grid-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.video-grid.grid-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-grid.grid-3 .video-cell:first-child {
    grid-column: 1 / -1;
}

.video-grid.grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-cell {
    position: relative;
    background: #2d2d44;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.video-cell video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.video-cell .video-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-cell .video-label .muted-icon {
    color: #f44336;
    font-size: 14px;
}

.video-cell.local-video {
    position: relative;
}

.video-cell.local-video video {
    transform: scaleX(-1);
}

.video-cell .no-video-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    gap: 8px;
}

.video-cell .no-video-placeholder .avatar-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #1976d2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    font-weight: 500;
}

/* Call Controls */
.call-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    gap: 12px;
    background: rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.call-controls .control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: white;
    font-size: 20px;
    background: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.call-controls .control-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.call-controls .control-btn.active {
    background: #1976d2;
}

.call-controls .control-btn.muted {
    background: #f44336;
}

.call-controls .control-btn.end-call {
    background: #f44336;
    width: 56px;
    height: 56px;
}

.call-controls .control-btn.end-call:hover {
    background: #d32f2f;
}

.call-controls .control-btn.recording {
    background: #f44336;
    animation: recording-pulse 1.5s infinite;
}

@keyframes recording-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* In-Call Chat Panel - Desktop */
.incall-chat {
    width: 320px;
    background: #1e1e30;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    z-index: 20;
}

.incall-chat .chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 500;
    flex-shrink: 0;
}

.incall-chat .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.incall-chat .chat-message {
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    flex-shrink: 0;
}

.incall-chat .chat-message .msg-sender {
    font-size: 11px;
    color: #1976d2;
    font-weight: 600;
    margin-bottom: 2px;
}

.incall-chat .chat-message .msg-time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
}

.incall-chat .chat-input-area {
    display: flex;
    padding: 8px;
    gap: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.incall-chat .chat-input-area input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    color: white;
    font-size: 13px;
    outline: none;
    min-width: 0;
}

.incall-chat .chat-input-area input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.incall-chat .chat-input-area button {
    background: #1976d2;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    min-width: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

/* Incoming Call Dialog */
.incoming-call-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.incoming-call-dialog {
    background: #1e1e30;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    color: white;
    min-width: 300px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: call-slide-in 0.3s ease;
}

@keyframes call-slide-in {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.incoming-call-dialog .caller-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #1976d2;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 500;
    animation: avatar-ring 2s infinite;
}

@keyframes avatar-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(25, 118, 210, 0.4); }
    50% { box-shadow: 0 0 0 20px rgba(25, 118, 210, 0); }
}

.incoming-call-dialog .caller-name {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 4px;
}

.incoming-call-dialog .call-type {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 32px;
}

.incoming-call-dialog .call-actions {
    display: flex;
    justify-content: center;
    gap: 40px;
}

.incoming-call-dialog .call-action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    transition: transform 0.2s;
}

.incoming-call-dialog .call-action-btn:hover {
    transform: scale(1.1);
}

.incoming-call-dialog .call-action-btn.accept {
    background: #4caf50;
}

.incoming-call-dialog .call-action-btn.reject {
    background: #f44336;
}

/* PIP Mode (Picture-in-Picture local video) */
.video-cell.pip-mode {
    position: absolute;
    bottom: 80px;
    right: 16px;
    width: 180px;
    height: 135px;
    z-index: 10;
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: grab;
}

.video-cell.pip-mode:active {
    cursor: grabbing;
}

/* Screen share indicator */
.screen-share-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #1976d2;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Scrollbar styling for chat */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* =============================================
   MOBILE - Smartphones (max-width: 600px)
   ============================================= */
@media (max-width: 600px) {
    .videocall-header {
        padding: 6px 12px;
        height: 40px;
    }

    .videocall-header .call-title {
        font-size: 13px;
        max-width: 50vw;
    }

    .videocall-header .call-timer {
        font-size: 12px;
    }

    .videocall-main {
        padding: 4px;
    }

    .video-grid.grid-2 {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .video-grid.grid-3 {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr 1fr;
    }

    .video-grid.grid-3 .video-cell:first-child {
        grid-column: 1;
    }

    .video-grid.grid-4 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .video-cell {
        border-radius: 8px;
    }

    .video-cell video {
        border-radius: 8px;
    }

    .video-cell .video-label {
        font-size: 10px;
        padding: 2px 6px;
        bottom: 4px;
        left: 4px;
    }

    .video-cell.pip-mode {
        width: 120px;
        height: 90px;
        bottom: 70px;
        right: 8px;
    }

    .call-controls {
        gap: 8px;
        padding: 8px 4px;
        flex-wrap: wrap;
    }

    .call-controls .control-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .call-controls .control-btn.end-call {
        width: 48px;
        height: 48px;
    }

    .incall-chat {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        border-left: none;
        z-index: 30;
        background: #1a1a2e;
    }

    .incall-chat .chat-header {
        padding: 12px 16px;
        background: rgba(0, 0, 0, 0.3);
    }

    .incall-chat .chat-input-area {
        padding: 8px 12px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .incoming-call-dialog {
        padding: 28px 20px;
        min-width: 280px;
        margin: 16px;
    }

    .incoming-call-dialog .caller-avatar {
        width: 64px;
        height: 64px;
        font-size: 26px;
    }

    .incoming-call-dialog .caller-name {
        font-size: 18px;
    }

    .incoming-call-dialog .call-actions {
        gap: 32px;
    }

    .incoming-call-dialog .call-action-btn {
        width: 54px;
        height: 54px;
        font-size: 22px;
    }
}

/* =============================================
   TABLET - (601px a 1024px)
   ============================================= */
@media (min-width: 601px) and (max-width: 1024px) {
    .video-grid.grid-2 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr;
    }

    .video-cell.pip-mode {
        width: 160px;
        height: 120px;
    }

    .incall-chat {
        width: 280px;
    }

    .call-controls .control-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .call-controls .control-btn.end-call {
        width: 52px;
        height: 52px;
    }
}

/* =============================================
   Landscape mobile
   ============================================= */
@media (max-height: 500px) and (orientation: landscape) {
    .videocall-header {
        height: 32px;
        padding: 4px 12px;
    }

    .videocall-header .call-title {
        font-size: 12px;
    }

    .videocall-header .call-timer {
        font-size: 11px;
    }

    .call-controls {
        padding: 4px;
        gap: 6px;
    }

    .call-controls .control-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .call-controls .control-btn.end-call {
        width: 42px;
        height: 42px;
    }

    .video-grid.grid-2 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr;
    }

    .video-cell.pip-mode {
        width: 100px;
        height: 75px;
        bottom: 50px;
        right: 8px;
    }

    .incall-chat {
        position: fixed;
        top: 0;
        right: 0;
        width: 280px;
        height: 100vh;
        border-radius: 0;
    }
}

/* =============================================
   Safe area para notch / barra iOS
   ============================================= */
@supports (padding: max(0px)) {
    .videocall-header {
        padding-top: max(8px, env(safe-area-inset-top));
    }

    .call-controls {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* ============================================
   Patient Video Call Page
   ============================================ */
.patient-videocall-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: 'Roboto', 'Montserrat', sans-serif;
    padding: 20px;
}

.patient-videocall-card {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.patient-videocall-card .clinic-logo {
    margin-bottom: 20px;
}

.patient-videocall-card .clinic-logo img {
    max-width: 180px;
    height: auto;
}

.patient-videocall-card .patient-name {
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 8px;
}

.patient-videocall-card .status-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 24px;
}

.patient-videocall-card .status-text.waiting {
    color: #ffc107;
}

.patient-videocall-card .status-text.connected {
    color: #4caf50;
}

.patient-video-preview {
    width: 100%;
    max-width: 360px;
    aspect-ratio: 4/3;
    background: #2d2d44;
    border-radius: 12px;
    overflow: hidden;
    margin: 0 auto 24px;
    position: relative;
}

.patient-video-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.patient-video-preview .no-video {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
}

.patient-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.patient-controls .control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: white;
    font-size: 20px;
    background: rgba(255, 255, 255, 0.15);
}

.patient-controls .control-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.patient-controls .control-btn.muted {
    background: #f44336;
}

.patient-controls .control-btn.end-call {
    background: #f44336;
    width: 56px;
    height: 56px;
}

.patient-controls .control-btn.end-call:hover {
    background: #d32f2f;
}

.patient-enter-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 40px;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 16px;
}

.patient-enter-btn:hover {
    background: #43a047;
    transform: scale(1.02);
}

.patient-enter-btn:disabled {
    background: rgba(255, 255, 255, 0.2);
    cursor: not-allowed;
    transform: none;
}

.patient-expired {
    color: #f44336;
    font-size: 16px;
}

.waiting-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 193, 7, 0.3);
    border-top-color: #ffc107;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Patient page - in call mode (full screen) */
.patient-incall {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #1a1a2e;
    z-index: 9999;
    display: flex;
    flex-direction: column;
}

.patient-incall .videocall-body {
    flex: 1;
    display: flex;
    position: relative;
    min-height: 0;
}

.patient-incall .remote-video {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.patient-incall .remote-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.patient-incall .local-pip {
    position: absolute;
    bottom: 80px;
    right: 16px;
    width: 150px;
    height: 112px;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 10;
}

.patient-incall .local-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

@media (max-width: 600px) {
    .patient-videocall-card {
        padding: 24px 16px;
    }

    .patient-videocall-card .patient-name {
        font-size: 18px;
    }

    .patient-incall .local-pip {
        width: 100px;
        height: 75px;
        bottom: 70px;
        right: 8px;
    }
}

/* ============================================
   Chat Window - Mobile Fullscreen
   ============================================ */
.chat-window-mobile {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 10001 !important;
    transform: none !important;
}

.chat-window-mobile .k-window-content {
    padding: 4px !important;
    height: calc(100vh - 50px) !important;
    height: calc(100dvh - 50px) !important;
    overflow: hidden !important;
}

.chat-window-mobile .k-window-titlebar {
    padding: 6px 10px !important;
}

@supports (padding: env(safe-area-inset-top)) {
    .chat-window-mobile .k-window-titlebar {
        padding-top: calc(6px + env(safe-area-inset-top)) !important;
    }
    .chat-window-mobile .k-window-content {
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}
